Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.metrics.util;
 
 
 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 extends Gauge<Double> {
    
Returns the numerator (the value on the top half of the fraction or the left-hand side of the ratio).

Returns:
the numerator
    protected abstract double getNumerator();

    
Returns the denominator (the value on the bottom half of the fraction or the right-hand side of the ratio).

Returns:
the denominator
    protected abstract double getDenominator();
    @Override
    public Double value() {
        final double d = getDenominator();
        if (isNaN(d) || isInfinite(d) || d == 0.0) {
            return .;
        }
        return getNumerator() / d;
    }
New to GrepCode? Check out our FAQ X