Example usage for java.lang Double compare

List of usage examples for java.lang Double compare

Introduction

In this page you can find the example usage for java.lang Double compare.

Prototype

public static int compare(double d1, double d2) 

Source Link

Document

Compares the two specified double values.

Usage

From source file:org.mrgeo.aggregators.MaxAggregator.java

@Override
public double aggregate(double[] values, double nodata) {
    double max = -Double.MAX_VALUE;
    for (int i = 0; i < values.length; i++) {
        if (Double.compare(values[i], nodata) != 0)
            max = Math.max(max, values[i]);
    }//  w w  w.ja v a  2  s.  com
    return (max == -Double.MAX_VALUE) ? nodata : max;
}

From source file:org.mrgeo.aggregators.SumAggregator.java

@Override
public double aggregate(double[] values, double nodata) {
    double sum = 0;
    int count = 0;
    for (int i = 0; i < values.length; i++) {
        if (Double.compare(values[i], nodata) != 0) {
            sum += values[i];//from   w w  w .jav  a2  s .c  o  m
            count++;
        }
    }
    return (count == 0) ? nodata : sum;
}

From source file:com.bigml.histogram.Gap.java

@Override
public int compareTo(Gap t) {
    int result = Double.compare(this.getSpace(), t.getSpace());
    if (result == 0) {
        result = getStartBin().compareTo(t.getStartBin());
    }// www .j  a  v a 2  s .  com
    return result;
}

From source file:org.mrgeo.aggregators.NearestAggregator.java

@Override
public double aggregate(double[] values, double nodata) {
    boolean data0 = Double.compare(values[0], nodata) != 0;
    boolean data1 = Double.compare(values[1], nodata) != 0;
    boolean data2 = Double.compare(values[2], nodata) != 0;
    boolean data3 = Double.compare(values[3], nodata) != 0;

    if (data0)//from w w  w.  j  a va 2 s .c  o m
        return values[0];
    if (data1)
        return values[1];
    if (data3)
        return values[3];
    if (data2)
        return values[2];

    return nodata;
}

From source file:org.mrgeo.aggregators.ModeAggregator.java

@Override
public double aggregate(double[] values, double nodata) {
    HashMap<Double, Integer> freqs = new HashMap<Double, Integer>();

    for (double val : values) {
        if (Double.compare(val, nodata) != 0) {
            Integer freq = freqs.get(val);
            freqs.put(val, (freq == null ? 1 : freq + 1));
        }/*from w ww .ja v  a  2  s  .  c  om*/
    }

    double mode = nodata;
    int maxFreq = 0;

    for (Map.Entry<Double, Integer> entry : freqs.entrySet()) {
        int freq = entry.getValue();
        if (freq > maxFreq) {
            maxFreq = freq;
            mode = entry.getKey();
        }
    }

    return mode;
}

From source file:org.mrgeo.aggregators.MinAvgPairAggregator.java

@Override
public double aggregate(double[] values, double nodata) {
    boolean data0 = Double.compare(values[0], nodata) != 0;
    boolean data1 = Double.compare(values[1], nodata) != 0;
    boolean data2 = Double.compare(values[2], nodata) != 0;
    boolean data3 = Double.compare(values[3], nodata) != 0;

    Collection<Double> averages = new ArrayList<Double>();
    if (data0 && data1)
        averages.add(Double.valueOf((values[0] + values[1]) / 2));
    if (data0 && data2)
        averages.add(Double.valueOf((values[0] + values[2]) / 2));
    if (data0 && data3)
        averages.add(Double.valueOf((values[0] + values[3]) / 2));
    if (data1 && data2)
        averages.add(Double.valueOf((values[1] + values[2]) / 2));
    if (data1 && data3)
        averages.add(Double.valueOf((values[1] + values[3]) / 2));
    if (data2 && data3)
        averages.add(Double.valueOf((values[2] + values[3]) / 2));

    return (averages.isEmpty()) ? nodata : Collections.min(averages).doubleValue();
}

From source file:edu.txstate.dmlab.clusteringwiki.eval.ExecutionTimes.java

/**
 * Add a new timers container to be tracked
 * @return id of timers container// ww  w.j  a  v  a 2s .  c o m
 */
public static int initiateTimers() {
    //first check for old timers that may have been left behind...
    for (Integer k : timerTimes.keySet()) {
        Timer t = timerTimes.get(k);
        if (Double.compare(t.seconds(), TIMER_EXPIRATION_TIME) > 0) {
            ExecutionTimes.clear(k);
            timerTimes.remove(k);
        }
    }
    //get new timers id
    Integer i = rand.nextInt();
    while (timers.containsKey(i))
        i = rand.nextInt();
    //initiate timers container
    timers.put(i, new HashMap<String, Timer>());
    timerTimes.put(i, new Timer());
    return i;
}

From source file:pl.matrix.core.Matrix.java

@Override
public boolean equals(Object other) {
    if (other instanceof Matrix) {
        Matrix oth = (Matrix) other;/*from w  w w .  j  a v  a 2 s . c  om*/
        double[][] otherData = oth.getData();

        if (data.length != otherData.length) {
            return false;
        }

        for (int i = 0; i < data.length; i++) {
            if (data[i].length != otherData[i].length) {
                return false;
            }

            for (int j = 0; j < data[i].length; j++) {
                if (Double.compare(data[i][j], otherData[i][j]) != 0) {
                    return false;
                }
            }
        }

        return true;
    }
    return false;
}

From source file:com.zlfun.framework.table.ItemComparator.java

@Override
public int compare(T o1, T o2) {

    Map<String, String> o1m = TableUtils.genItemFieldMap(o1);
    Map<String, String> o2m = TableUtils.genItemFieldMap(o2);

    String var1 = o1m.get(name);
    String var2 = o2m.get(name);
    if (isNumeric(var1) && isNumeric(var2)) {
        if (asc) {
            return Double.compare(Double.parseDouble(var1), Double.parseDouble(var2));

        } else {/*ww w.ja  va2 s .com*/
            return Double.compare(Double.parseDouble(var2), Double.parseDouble(var1));
        }
    } else {
        if (asc) {
            return var1.compareTo(var2);
        } else {
            return var2.compareTo(var1);
        }
    }

}

From source file:com.opengamma.analytics.math.FunctionUtils.java

/**
 * Same behaviour as mathlab unique/*from   w  ww. ja  v a 2s  .c  o  m*/
 * @param in input array
 * @return a sorted array with no duplicates values
 */
public static double[] unique(final double[] in) {
    Arrays.sort(in);
    final int n = in.length;
    final double[] temp = new double[n];
    temp[0] = in[0];
    int count = 1;
    for (int i = 1; i < n; i++) {
        if (Double.compare(in[i], in[i - 1]) != 0) {
            temp[count++] = in[i];
        }
    }
    if (count == n) {
        return temp;
    }
    return Arrays.copyOf(temp, count);
}