All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.maxifier.mxcache.jconsoleplugin.Rate Maven / Gradle / Ivy

There is a newer version: 2.6.9
Show newest version
/*
 * Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
 */
package com.maxifier.mxcache.jconsoleplugin;

/**
 * @author Alexander Kochurov ([email protected])
 */
final class Rate implements Comparable {
    private final double value;

    Rate(double value) {
        this.value = value;
    }

    @Override
    public int compareTo(Rate o) {
        return Double.compare(value, o.value);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Rate rate = (Rate) o;

        return compareTo(rate) == 0;

    }

    @Override
    public int hashCode() {
        long temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L;
        return (int) (temp ^ (temp >>> 32));
    }

    @Override
    public String toString() {
        double percent = value * 100.0;
        if (Double.isNaN(percent)) {
            return "-";
        }
        if (percent == 0.0) {
            return "0";
        }
        if (percent < 1) {
            return "<1";
        }
        if (percent == 100.0) {
            return "100";
        }
        if (percent > 99.0) {
            return ">99";
        }
        return Long.toString(Math.round(percent));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy