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: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 ww.j a v a 2 s  .c om
        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 void main(String[] args) {
    Double double1 = new Double(1.1);
    Double double2 = new Double("1.2");

    System.out.println(Double.compare(double1, double2));

}

From source file:playground.johannes.studies.coopsim.SweepMerge2D.java

/**
 * @param args/*  w ww.  j  a  v  a 2  s .c  o  m*/
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    File root = new File("/Volumes/cluster.math.tu-berlin.de/net/ils2/jillenberger/leisure/runs/run205/");
    String property = "d_trip_home";
    int valIdx = 1;
    String parameterKey1 = "traveling";
    String parameterKey2 = "performing";

    File analysis = new File(String.format("%1$s/analysis/", root.getAbsolutePath()));
    analysis.mkdirs();

    KeyMatrix<Double> matrix = new KeyMatrix<Double>();

    File tasks = new File(String.format("%1$s/tasks/", root.getAbsolutePath()));
    for (File file : tasks.listFiles()) {
        if (file.isDirectory()) {
            if (!file.getName().equals("analysis")) {
                File output = new File(String.format("%1$s/output/", file.getAbsolutePath()));
                String[] dirs = output.list();
                if (dirs.length > 0) {

                    Arrays.sort(dirs, new Comparator<String>() {
                        @Override
                        public int compare(String o1, String o2) {
                            return Double.compare(Double.parseDouble(o1), Double.parseDouble(o2));
                        }
                    });
                    /*
                     * get parameter value
                     */
                    Config config = new Config();
                    ConfigReader creader = new ConfigReader(config);
                    creader.readFile(String.format("%1$s/config.xml", file.getAbsolutePath()));
                    double paramValue1 = Double.parseDouble(config.findParam("planCalcScore", parameterKey1));
                    double paramValue2 = Double.parseDouble(config.findParam("planCalcScore", parameterKey2));

                    int start = dirs.length - 10;
                    start = Math.max(0, start);
                    if (dirs.length < 10) {
                        logger.warn("Less than 10 samples.");
                    }
                    DescriptiveStatistics stat = new DescriptiveStatistics();
                    for (int i = start; i < dirs.length; i++) {
                        File statsFile = new File(
                                String.format("%1$s/%2$s/statistics.txt", output.getAbsolutePath(), dirs[i]));
                        if (statsFile.exists()) {
                            /*
                             * get property value
                             */
                            BufferedReader reader = new BufferedReader(new FileReader(statsFile));
                            String line = reader.readLine();

                            while ((line = reader.readLine()) != null) {
                                String[] tokens = line.split("\t");
                                String key = tokens[0];
                                double val = Double.parseDouble(tokens[valIdx]);

                                if (key.equals(property)) {
                                    stat.addValue(val);
                                    break;
                                }
                            }
                        }

                    }
                    matrix.putValue(stat.getMean(), Math.abs(paramValue1), Math.abs(paramValue2));
                } else {
                    logger.warn("No samples.");
                }
            }
        }
    }

    matrix.write(String.format("%1$s/%2$s.matrix.txt", analysis.getAbsolutePath(), property));
}

From source file:playground.johannes.studies.coopsim.SweepMerge1D.java

/**
 * @param args/* w  ww .java2  s .  c  om*/
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    File root = new File("/Volumes/cluster.math.tu-berlin.de/net/ils2/jillenberger/leisure/runs/run272/");
    //      String property = "score_join_culture";
    String property = "d_trip_culture";
    int valIdx = 1;
    //      String parameterKey = "beta_join";
    //      String parameterKey = "performing";
    String parameterKey = "alterProba_culture";

    int dumps = 1;

    File analysis = new File(String.format("%1$s/analysis/", root.getAbsolutePath()));
    analysis.mkdirs();

    TDoubleDoubleHashMap values = new TDoubleDoubleHashMap();

    File tasks = new File(String.format("%1$s/tasks/", root.getAbsolutePath()));
    for (File file : tasks.listFiles()) {
        if (file.isDirectory()) {
            if (!file.getName().equals("analysis")) {
                File output = new File(String.format("%1$s/output/", file.getAbsolutePath()));
                String[] dirs = output.list();
                if (dirs.length > 0) {

                    Arrays.sort(dirs, new Comparator<String>() {
                        @Override
                        public int compare(String o1, String o2) {
                            return Double.compare(Double.parseDouble(o1), Double.parseDouble(o2));
                        }
                    });
                    /*
                     * get parameter value
                     */
                    Config config = new Config();
                    ConfigReader creader = new ConfigReader(config);
                    creader.readFile(String.format("%1$s/config.xml", file.getAbsolutePath()));
                    double paramValue = Double.parseDouble(config.findParam("socialnets", parameterKey));
                    //               double paramValue = Double.parseDouble(config.findParam("planCalcScore", parameterKey));

                    int start = dirs.length - dumps;
                    start = Math.max(0, start);
                    if (dirs.length < dumps) {
                        logger.warn(String.format("Less than %1$s samples.", dumps));
                    }
                    DescriptiveStatistics stat = new DescriptiveStatistics();
                    for (int i = start; i < dirs.length; i++) {
                        //               for(int i = 12; i < 13; i++) {
                        File statsFile = new File(
                                String.format("%1$s/%2$s/statistics.txt", output.getAbsolutePath(), dirs[i]));
                        if (statsFile.exists()) {
                            /*
                             * get property value
                             */
                            BufferedReader reader = new BufferedReader(new FileReader(statsFile));
                            String line = reader.readLine();

                            while ((line = reader.readLine()) != null) {
                                String[] tokens = line.split("\t");
                                String key = tokens[0];
                                double val = Double.parseDouble(tokens[valIdx]);

                                if (key.equals(property)) {
                                    stat.addValue(val);
                                    break;
                                }
                            }
                        }

                    }
                    values.put(paramValue, stat.getMean());
                } else {
                    logger.warn("No samples.");
                }
            }
        }
    }

    TXTWriter.writeMap(values, parameterKey, property,
            String.format("%1$s/%2$s.txt", analysis.getAbsolutePath(), property));
}

From source file:Main.java

/**
 * Returns the indices that would sort an array.
 * @param array Array.//  w w  w.j  ava  2 s .c o m
 * @param ascending Ascending order.
 * @return Array of indices.
 */
public static int[] Argsort(final double[] array, final boolean ascending) {
    Integer[] indexes = new Integer[array.length];
    for (int i = 0; i < indexes.length; i++) {
        indexes[i] = i;
    }
    Arrays.sort(indexes, new Comparator<Integer>() {
        @Override
        public int compare(final Integer i1, final Integer i2) {
            return (ascending ? 1 : -1) * Double.compare(array[i1], array[i2]);
        }
    });
    return asArray(indexes);
}

From source file:com.pros.jsontransform.sort.ArraySortAbstract.java

static int compareValueNodes(JsonNode value1, JsonNode value2) {
    int result = 0;

    if (value1.isNumber() && value2.isNumber()) {
        result = Double.compare(value1.asDouble(), value2.asDouble());
    } else if (value1.isTextual() && value2.isTextual()) {
        result = value1.asText().compareTo(value2.asText());
    }/* w ww . j  a  v a2 s.c  om*/

    return result;
}

From source file:io.appform.jsonrules.utils.ComparisonUtils.java

static int compare(JsonNode evaluatedNode, Object value) {
    int comparisonResult = 0;
    if (evaluatedNode.isNumber()) {
        if (Number.class.isAssignableFrom(value.getClass())) {
            Number nValue = (Number) value;
            if (evaluatedNode.isIntegralNumber()) {
                comparisonResult = Long.compare(evaluatedNode.asLong(), nValue.longValue());
            } else if (evaluatedNode.isFloatingPointNumber()) {
                comparisonResult = Double.compare(evaluatedNode.asDouble(), nValue.doubleValue());
            }/*from ww  w  .  j av  a  2s .com*/
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }
    } else if (evaluatedNode.isBoolean()) {
        if (Boolean.class.isAssignableFrom(value.getClass())) {
            Boolean bValue = Boolean.parseBoolean(value.toString());
            comparisonResult = Boolean.compare(evaluatedNode.asBoolean(), bValue);
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }

    } else if (evaluatedNode.isTextual()) {
        if (String.class.isAssignableFrom(value.getClass())) {
            comparisonResult = evaluatedNode.asText().compareTo(String.valueOf(value));
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }
    } else if (evaluatedNode.isObject()) {
        throw new IllegalArgumentException("Object comparisons not supported");
    }
    return comparisonResult;
}

From source file:com.evrythng.thng.resource.model.store.jobs.Progress.java

@JsonIgnore
public final boolean isComplete() {

    return Double.compare(percentage(), FULL_PROGRESS) >= 0;
}

From source file:Calculator.Calculation.java

public static double div(String a, String b) {
    a = a.trim();//  ww  w . ja va  2s  .c  o m
    b = b.trim();
    FractionFormat ff = new FractionFormat();
    Fraction fraction_a = ff.parse(a);
    Fraction fraction_b = ff.parse(b);
    int c = Double.compare(fraction_b.doubleValue(), 0);
    double d = fraction_a.doubleValue() / fraction_b.doubleValue();
    return d;
}

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

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