view flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java @ 4741:f6d0ad25f1ee

Merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 02 Jan 2013 15:42:22 +0100
parents 94b39073f0f7
children
line wrap: on
line source
package de.intevation.flys.utils;

import java.util.Comparator;

public class EpsilonComparator implements Comparator<Double>
{
    public static final double EPSILON = 1e-4;

    public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON);

    private double epsilon;

    public EpsilonComparator(double epsilon) {
        this.epsilon = epsilon;
    }

    @Override
    public int compare(Double a, Double b) {
        double diff = a - b;
        if (diff < -epsilon) return -1;
        if (diff >  epsilon) return +1;
        return 0;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org