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:Main.java

public static void main(String[] args) {
    Double double1 = new Double(1.1);
    Double double2 = new Double("1.2");

    System.out.println(double1.compareTo(double2));

}

From source file:Main.java

public static void main(String[] args) {
    double d1 = 5.5;
    double d2 = 5.4;
    int i1 = Double.compare(d1, d2);
    if (i1 > 0) {
        System.out.println(">");
    } else if (i1 < 0) {
        System.out.println("<");
    } else {/*  w  w w  .j  a v a 2 s  .c  o  m*/
        System.out.println("=");
    }
    Double dObj1 = new Double("5.5");
    Double dObj2 = new Double("5.4");
    int i2 = dObj1.compareTo(dObj2);
    if (i2 > 0) {
        System.out.println(">");
    } else if (i2 < 0) {
        System.out.println("<");
    } else {
        System.out.println("=");
    }
}

From source file:Main.java

public static Double Doubleformat(DecimalFormat df, Double value) {
    if (value == null || value.compareTo(0.0) == 0) {
        return 0.0;
    }/*from  ww  w.  j av a2  s. com*/
    if (df == null) {
        df = doubleFormat;
    }
    String dfValue = df.format(value);
    dfValue = dfValue.replaceAll("[ ]", "");
    dfValue = dfValue.replaceAll("[,]", "");
    return Double.valueOf(dfValue);
}

From source file:Main.java

public static String getMaximumKey(Map<String, Double> input) {
    String bestFeature = null;/*from  www .j a v a2s  . c  o  m*/
    Double bestValue = null;
    for (String feature : input.keySet()) {
        if (bestValue == null || bestValue.compareTo(input.get(feature)) < 0) {
            bestFeature = feature;
            bestValue = input.get(feature);
        }
    }
    return bestFeature;
}

From source file:ml.shifu.shifu.util.BinUtils.java

/**
 * Get bin index by binary search. The last bin in <code>binBoundary</code> is missing value bin.
 * //  w  w w .  ja  v a2s.  com
 * @param binBoundary
 *            bin boundary list which should be sorted.
 * @param dVal
 *            value of column
 * @return bin index
 */
public static int getBinIndex(List<Double> binBoundary, Double dVal) {
    assert binBoundary != null && binBoundary.size() > 0;
    assert dVal != null;
    int binSize = binBoundary.size();

    int low = 0;
    int high = binSize - 1;

    while (low <= high) {
        int mid = (low + high) >>> 1;
        Double midVal = binBoundary.get(mid);
        int cmp = midVal.compareTo(dVal);

        if (cmp < 0) {
            low = mid + 1;
        } else if (cmp > 0) {
            high = mid - 1;
        } else {
            return mid; // key found
        }
    }

    return low == 0 ? 0 : low - 1;
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateCompareTwoFields.java

/**
 * Compares two fields and checks if second field >= first field
 * /*from   ww  w.  j av  a 2 s. co m*/
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @param request
 * @param application
 * @return
 */
public static boolean validateGreaterThanOrEqual(Object bean, ValidatorAction va, Field field,
        ActionMessages errors, HttpServletRequest request, ServletContext application) {
    return validate(bean, va, field, errors, request, new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            Double d1 = (Double) o1;
            Double d2 = (Double) o2;

            int result = d1.compareTo(d2);
            if (result <= 0) {
                result = VALUE;
            }
            return result;
        }
    });
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateCompareTwoFields.java

/**
 * Compares two fields and checks if second field > first field
 * /*from w  w  w .  j  a  va2 s.  c  o m*/
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @param request
 * @param application
 * @return
 */
public static boolean validateGreaterThan(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {
    return validate(bean, va, field, errors, request, new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            Double d1 = (Double) o1;
            Double d2 = (Double) o2;

            int result = d1.compareTo(d2);
            if (result < 0) {
                result = VALUE;
            }
            return result;
        }
    });
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateCompareTwoFields.java

/**
 * Compares two fields and checks if second field == first field
 * //from   www .  ja v  a2 s  . c  om
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @param request
 * @param application
 * @return
 */
public static boolean validateEqual(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {
    return validate(bean, va, field, errors, request, new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            Double d1 = (Double) o1;
            Double d2 = (Double) o2;

            int result = d1.compareTo(d2);
            if (result == 0) {
                result = VALUE;
            }
            return result;
        }
    });
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateCompareTwoFields.java

/**
 * Compares two fields and checks if the second field < first field
 * /*ww  w  .  ja  v  a2s .co m*/
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @param request
 * @param application
 * @return
 */
public static boolean validateLessThan(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {
    return validate(bean, va, field, errors, request, new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            Double d1 = (Double) o1;
            Double d2 = (Double) o2;

            int result = d1.compareTo(d2);
            if (result > 0) {
                result = VALUE;
            }
            return result;
        }
    });
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateCompareTwoFields.java

/**
 * Compares two fields and checks if the second field <= first field
 * /*from   www .j  a v  a2  s. c  om*/
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @param request
 * @param application
 * @return
 */
public static boolean validateLessThanOrEqual(Object bean, ValidatorAction va, Field field,
        ActionMessages errors, HttpServletRequest request, ServletContext application) {
    return validate(bean, va, field, errors, request, new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            Double d1 = (Double) o1;
            Double d2 = (Double) o2;

            int result = d1.compareTo(d2);
            if (result >= 0) {
                result = VALUE;
            }
            return result;
        }
    });
}