Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.codahale.metrics;
 
 import static java.lang.Double.isInfinite;
 import static java.lang.Double.isNaN;

A gauge which measures the ratio of one value to another.

If the denominator is zero, not a number, or infinite, the resulting ratio is not a number.

public abstract class RatioGauge implements Gauge<Double> {
    
A ratio of one quantity to another.
    public static class Ratio {
        
Creates a new ratio with the given numerator and denominator.

Parameters:
numerator the numerator of the ratio
denominator the denominator of the ratio
Returns:
numerator:denominator
        public static Ratio of(double numeratordouble denominator) {
            return new Ratio(numeratordenominator);
        }
        private final double numerator;
        private final double denominator;
        private Ratio(double numeratordouble denominator) {
            this. = numerator;
            this. = denominator;
        }

        
Returns the ratio, which is either a double between 0 and 1 (inclusive) or NaN.

Returns:
the ratio
        public double getValue() {
            final double d = ;
            if (isNaN(d) || isInfinite(d) || d == 0) {
                return .;
            }
            return  / d;
        }
        @Override
        public String toString() {
            return  + ":" + ;
        }
    }

    
Returns the RatioGauge.Ratio which is the gauge's current value.

Returns:
the RatioGauge.Ratio which is the gauge's current value
    protected abstract Ratio getRatio();
    @Override
    public Double getValue() {
        return getRatio().getValue();
    }
New to GrepCode? Check out our FAQ X