Example usage for java.lang Double compareTo

List of usage examples for java.lang Double compareTo

Introduction

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

Prototype

public int compareTo(Double anotherDouble) 

Source Link

Document

Compares two Double objects numerically.

Usage

From source file:de.openali.odysseus.chart.framework.model.data.DataRange.java

@Deprecated
public static <T> DataRange<T> create(final T min, final T max) {
    if (min instanceof Number && max instanceof Number) {
        final Double minNum = ((Number) min).doubleValue();
        final Double maxNum = ((Number) max).doubleValue();

        // Beide gleich => dataRange automatisch so anpassen, dass der Wert
        // in der Intervallmitte liegt
        if (minNum.compareTo(maxNum) == 0) {
            final double doubleValue = minNum.doubleValue();
            // falls != 0 werden einfach 10% addiert oder subtrahiert
            if (doubleValue != 0) {
                final T minExpanded = (T) new Double(doubleValue - doubleValue * 0.1);
                final T maxExpanded = (T) new Double(doubleValue + doubleValue * 0.1);
                return new DataRange<>(minExpanded, maxExpanded);
            }//from   www .  ja  va  2  s  .  com
            // falls == 0 wird 1 addiert oder subtrahiert
            else {
                final T min_1 = (T) new Double(doubleValue - 1);
                final T max_1 = (T) new Double(doubleValue + 1);
                return new DataRange<>(min_1, max_1);
            }
        }

        if (minNum.compareTo(maxNum) > 0)
            return new DataRange<>(max, min);
        else
            return new DataRange<>(min, max);

    } else if (min instanceof Comparable && max instanceof Comparable
            && (min.getClass().isInstance(max) || max.getClass().isInstance(min))) {
        // FIXME: this is nonsense! REMOVE
        final Comparable<Comparable<?>> minComp = (Comparable<Comparable<?>>) min;
        final Comparable<?> maxComp = (Comparable<?>) max;
        if (minComp.compareTo(maxComp) == 0) {
            // kann leider nicht automatisch angepasst werden; das muss
            // jemand anders abfangen
        }

        if (minComp.compareTo(maxComp) > 0)
            return new DataRange<>(max, min);
        else
            return new DataRange<>(min, max);

    }
    /*
     * das wre dann der ungnstigste Fall: nicht vergleichbar und nicht numerisch TODO: berlegen, ob dieser Fall
     * berhaupt zugelassen werden soll; alternativ sollte eine InvalidRangeIntervalObjectsException
     */
    else {
        return new DataRange<>(min, max);
    }
}

From source file:org.sonar.server.computation.measure.BestValueOptimization.java

private static boolean isBestValue(Measure measure, Double bestValue) {
    switch (measure.getValueType()) {
    case BOOLEAN:
        return bestValue.intValue() == 1 ? measure.getBooleanValue() : !measure.getBooleanValue();
    case INT:/*from   w  ww. j  av a2 s .co  m*/
        return bestValue.intValue() == measure.getIntValue();
    case LONG:
        return bestValue.longValue() == measure.getLongValue();
    case DOUBLE:
        return bestValue.compareTo(measure.getDoubleValue()) == 0;
    default:
        return false;
    }
}

From source file:org.deeplearning4j.clustering.cluster.ClusterUtils.java

public static List<Cluster> getMostSpreadOutClusters(final ClusterSet clusterSet, final ClusterSetInfo info,
        int count) {
    List<Cluster> clusters = new ArrayList<>(clusterSet.getClusters());
    Collections.sort(clusters, new Comparator<Cluster>() {
        public int compare(Cluster o1, Cluster o2) {
            Double o1TotalDistance = info.getClusterInfo(o1.getId()).getTotalPointDistanceFromCenter();
            Double o2TotalDistance = info.getClusterInfo(o2.getId()).getTotalPointDistanceFromCenter();
            return -o1TotalDistance.compareTo(o2TotalDistance);
        }// w ww.  j a  v  a 2 s .  c o m
    });
    return clusters.subList(0, count);
}

From source file:org.kuali.mobility.tours.service.ToursServiceImpl.java

private static List<Integer> sortByValue(final Map<Integer, Double> m) {
    List<Integer> keys = new ArrayList<Integer>();
    keys.addAll(m.keySet());// w  w  w .  j a  va2s.c o m
    Collections.sort(keys, new Comparator<Integer>() {
        public int compare(Integer o1, Integer o2) {
            Double v1 = m.get(o1);
            Double v2 = m.get(o2);
            if (v1 == null) {
                return (v2 == null) ? 0 : 1;
            }
            return v1.compareTo(v2);
        }
    });
    return keys;
}

From source file:MyComparator.java

public int compare(Entry o1, Entry o2) {
    Double valueOne = (Double) o1.getValue();
    Double valueTwo = (Double) o2.getValue();
    return (int) Math.signum(valueOne.compareTo(valueTwo));
}

From source file:gemlite.core.internal.index.compare.ComparatorImpl.java

private int compareDouble(Double o1, Double o2) {
    return o1.compareTo(o2);
}

From source file:de.kp.ames.web.core.json.DoubleCollector.java

public DoubleCollector() {

    collector = new TreeMap<Double, ArrayList<JSONObject>>(new Comparator<Double>() {
        public int compare(Double double1, Double double2) {
            return double1.compareTo(double2);
        }/*from w  w  w .  j av a 2  s  .c  o  m*/
    });

}

From source file:com.ori.outlierserver.model.DataUtil.java

private double[] getOutlierBounderysFromLits(List<Reading> list) {
    if (list == null) {
        return null;
    }//from  ww  w  .j a  v  a2 s.  co m

    if (list.size() == 1) {
        double[] arrayForOne = new double[4];
        Arrays.fill(arrayForOne, list.get(0).getMedian_value());
        return arrayForOne;
    }

    List<Double> values = new ArrayList<>();
    list.stream().forEach((Reading r) -> {
        values.add(r.getMedian_value());
    });
    int theSize = values.size();
    if (theSize == 1) {
        return new double[] {};
    }
    Collections.sort(values);
    boolean isEven = theSize % 2 == 0;
    double medianValue = findMedianValue(values);
    List<Double> lowerHalf = new ArrayList<>();
    List<Double> upperHalf = new ArrayList<>();
    for (Double d : values) {
        if (d.compareTo(medianValue) == -1) {
            lowerHalf.add(d);
        }
    }
    for (Double d : values) {
        if (d.compareTo(medianValue) >= 0) {
            upperHalf.add(d);
        }
    }

    double medianLow = findMedianValue(lowerHalf);
    double medianHigh = findMedianValue(upperHalf);

    double minorFenceDelta = (medianHigh - medianLow) * 1.5;
    double majorFenceDelta = (medianHigh - medianLow) * 3;

    return new double[] { medianLow - majorFenceDelta, medianLow - minorFenceDelta,
            medianHigh + minorFenceDelta, medianHigh + majorFenceDelta };
}

From source file:org.apache.tajo.validation.MaxValidator.java

@Override
protected <T> boolean validateInternal(T object) {
    boolean result = false;

    if (object != null) {
        if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer)) {
            Integer objInteger = Integer.decode(object.toString());
            Integer maxInteger = Integer.decode(maxValue);
            result = objInteger.compareTo(maxInteger) <= 0;
        } else if (object instanceof Long) {
            Long objLong = Long.decode(object.toString());
            Long maxLong = Long.decode(maxValue);
            result = objLong.compareTo(maxLong) <= 0;
        } else if ((object instanceof Float) || (object instanceof Double)) {
            Double objDouble = Double.valueOf(object.toString());
            Double maxDouble = Double.valueOf(maxValue);
            result = objDouble.compareTo(maxDouble) <= 0;
        } else if (object instanceof BigInteger) {
            BigInteger objInteger = (BigInteger) object;
            BigInteger maxInteger = new BigInteger(maxValue);
            result = objInteger.compareTo(maxInteger) <= 0;
        } else if (object instanceof BigDecimal) {
            BigDecimal objDecimal = (BigDecimal) object;
            BigDecimal maxDecimal = new BigDecimal(maxValue);
            result = objDecimal.compareTo(maxDecimal) <= 0;
        }/*ww  w .  j a v a  2  s  .  c om*/
    } else {
        result = true;
    }

    return result;
}

From source file:org.apache.tajo.validation.MinValidator.java

@Override
protected <T> boolean validateInternal(T object) {
    boolean result = false;

    if (object != null) {
        if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer)) {
            Integer objInteger = Integer.decode(object.toString());
            Integer minInteger = Integer.decode(minValue);
            result = objInteger.compareTo(minInteger) >= 0;
        } else if (object instanceof Long) {
            Long objLong = Long.decode(object.toString());
            Long minLong = Long.decode(minValue);
            result = objLong.compareTo(minLong) >= 0;
        } else if ((object instanceof Float) || (object instanceof Double)) {
            Double objDouble = Double.valueOf(object.toString());
            Double minDouble = Double.valueOf(minValue);
            result = objDouble.compareTo(minDouble) >= 0;
        } else if (object instanceof BigInteger) {
            BigInteger objInteger = (BigInteger) object;
            BigInteger minInteger = new BigInteger(minValue);
            result = objInteger.compareTo(minInteger) >= 0;
        } else if (object instanceof BigDecimal) {
            BigDecimal objDecimal = (BigDecimal) object;
            BigDecimal minDecimal = new BigDecimal(minValue);
            result = objDecimal.compareTo(minDecimal) >= 0;
        } else if (object instanceof String) {
            BigDecimal objDecimal = new BigDecimal((String) object);
            BigDecimal minDecimal = new BigDecimal(minValue);
            result = objDecimal.compareTo(minDecimal) >= 0;
        }/*  w w w . j  ava 2 s .c o  m*/
    } else {
        result = true;
    }

    return result;
}