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:org.yccheok.jstock.analysis.EqualityOperator.java

@Override
protected Object calculate() {
    Object object0 = inputs[0].getValue();
    Object object1 = inputs[1].getValue();

    try {//  ww  w .jav  a 2s.co m
        Double d0 = Double.parseDouble(object0.toString());
        Double d1 = Double.parseDouble(object1.toString());

        int result = d0.compareTo(d1);

        switch (equality) {
        case Equal:
            return Boolean.valueOf(result == 0);

        case Greater:
            return Boolean.valueOf(result > 0);

        case Lesser:
            return Boolean.valueOf(result < 0);

        case GreaterOrEqual:
            return Boolean.valueOf(result >= 0);

        case LesserOrEqual:
            return Boolean.valueOf(result <= 0);

        default:
            assert (false);
        }

    } catch (NumberFormatException exp) {
        log.error(null, exp);
    }

    return null;
}

From source file:com.sixrr.metrics.ui.charts.PieChartDialog.java

private PieDataset createDataset() {
    final List<Pair<String, Double>> namedValues = new ArrayList<Pair<String, Double>>();
    double total = 0.0;
    for (int j = 0; j < values.length; j++) {
        final Double value = values[j];
        final String measuredItem = measuredItems[j];
        if (value != null && value != 0.0) {
            namedValues.add(new Pair<String, Double>(measuredItem, value));
            total += value;//from  w ww  .  j  ava2 s .com
        }
    }
    Collections.sort(namedValues, new Comparator<Pair<String, Double>>() {
        @Override
        public int compare(Pair<String, Double> pair1, Pair<String, Double> pair2) {
            final Double value1 = pair1.getSecond();
            final Double value2 = pair2.getSecond();
            return -value1.compareTo(value2);
        }
    });
    final DefaultPieDataset dataset = new DefaultPieDataset();

    double totalForOther = 0.0;
    for (final Pair<String, Double> namedValue : namedValues) {
        final double value = namedValue.getSecond();
        if (value > total * SMALLEST_PIE_PIECE) {
            dataset.setValue(namedValue.getFirst(), value);
        } else {
            totalForOther += value;
        }
    }
    if (totalForOther != 0.0) {
        dataset.setValue(MetricsReloadedBundle.message("other"), totalForOther);
    }
    return dataset;
}

From source file:uk.ac.tgac.rampart.stage.analyse.asm.stats.AssemblyStats.java

@Override
public int compareTo(AssemblyStats o) {

    Double thisScore = this.finalScore;
    Double thatScore = o.getFinalScore();

    return thisScore.compareTo(thatScore);
}

From source file:com.comcast.locker.gateway.xgateway.service.CreatePurchaseForAssetController.java

private TitlePlayability validateRequestInformation(CreatePurchaseRequest purchaseRequest, AccountId accountId,
        AssetId assetId) {/*from   w  w w  .j a v  a2  s.co m*/
    TitlePlayability playability = unuService.validatePlayEligibility(assetId, accountId,
            purchaseRequest.getClient());

    //we'll look at rentals if the title is a rental, but if it's a buy, we only care if we own it
    validateAssetIsNotAlreadyOwned(purchaseRequest.getAccountId(), purchaseRequest.getAssetId(), accountId,
            assetId, !Titles.titleIsElectronicSellThrough(playability.getTitle()), playability);
    validateAvailableAndTransaction(playability);
    Double requestPrice = purchaseRequest.getPrice();

    if (requestPrice != null) {

        if (requestPrice.compareTo(getPrice(playability.getTitle())) != 0) {
            throw PriceMismatchException.forTitle(requestPrice, getPrice(playability.getTitle()));
        }
    }
    return playability;
}

From source file:AnimationTester.java

public void run() {
    Comparator<Double> comp = new Comparator<Double>() {
        public int compare(Double d1, Double d2) {
            try {
                Thread.sleep(100);
            } catch (Exception exception) {
                System.out.println(exception);
            }//from   w w  w  . j  av  a 2 s  . c o m
            panel.setValues(values, d1, d2);
            return d1.compareTo(d2);
        }
    };
    Collections.sort(Arrays.asList(values), comp);
    panel.setValues(values, null, null);
}

From source file:org.talend.dataquality.record.linkage.grouping.callback.MultiPassGroupingCallBack.java

/**
 * Create by zshen get minimum one between origin Group quality and current confidence value
 * /* w w w  .jav  a  2s.c  om*/
 * @param oldGrpQuality the origin Group quality value
 * @param confidence current confidence value
 * @return minimum one
 */
private double getMergeGQ(Double oldGrpQuality, double confidence) {
    if (oldGrpQuality.compareTo(0.0d) == 0) {
        return confidence;
    }
    // get minimum one
    return confidence > oldGrpQuality ? oldGrpQuality : confidence;
}

From source file:com.thoughtworks.studios.journey.models.ActionCorrelationCalculation.java

public List<CorrelationResult> calculate() {
    Map<String, List<List<Integer>>> data = rawData();
    List<CorrelationResult> results = new ArrayList<>(data.size());

    for (String action : data.keySet()) {
        SpearmansCorrelation correlation = new SpearmansCorrelation();

        List<List<Integer>> variables = data.get(action);
        double[] x = toDoubleArray(variables.get(0));
        double[] y = toDoubleArray(variables.get(1));

        double r = correlation.correlation(x, y);
        TDistribution tDistribution = new TDistribution(x.length - 2);
        double t = FastMath.abs(r * FastMath.sqrt((x.length - 2) / (1 - r * r)));
        double pValue = 2 * tDistribution.cumulativeProbability(-t);

        SummaryStatistics successSt = new SummaryStatistics();
        SummaryStatistics failSt = new SummaryStatistics();
        for (int i = 0; i < x.length; i++) {
            if (y[i] == 1) {
                successSt.addValue(x[i]);
            } else {
                failSt.addValue(x[i]);//from  ww  w .ja v  a  2s. co m
            }
        }

        results.add(new CorrelationResult(action, r, pValue, successSt, failSt));
    }

    Collections.sort(results, new Comparator<CorrelationResult>() {
        @Override
        public int compare(CorrelationResult r1, CorrelationResult r2) {
            Double abs1 = Math.abs(r2.getCorrelation());
            Double abs2 = Math.abs(r1.getCorrelation());
            return abs1.compareTo(abs2);
        }
    });
    return results;
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java

public boolean isEditValid() {
    final String S_ProcName = "isEditValid";
    if (!hasValue()) {
        setValue(null);/* w ww.jav  a  2s .com*/
        return (true);
    }

    boolean retval = super.isEditValid();
    if (retval) {
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = false;
        } else if (obj instanceof Float) {
            Float f = (Float) obj;
            Double v = new Double(f.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Double) {
            Double v = (Double) obj;
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            Double v = new Double(s.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            Double v = new Double(i.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            Double v = new Double(l.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof BigDecimal) {
            BigDecimal b = (BigDecimal) obj;
            Double v = new Double(b.toString());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            Double v = new Double(n.toString());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal, Float, Double or Number");
        }
    }
    return (retval);
}

From source file:org.testmp.webconsole.server.TestDataService.java

private List<Map<String, Object>> getTestData(Criteria criteria, final List<String> sortBy) throws Exception {
    List<Map<String, Object>> dataList = loader.load("TestData");
    if (criteria != null) {
        Filter filter = new Filter(criteria);
        dataList = filter.doFilter(dataList);
    }/*  ww  w.  ja  v a 2  s . c om*/
    if (sortBy != null) {
        Collections.sort(dataList, new Comparator<Map<String, Object>>() {

            @Override
            public int compare(Map<String, Object> data1, Map<String, Object> data2) {
                for (String fieldName : sortBy) {
                    boolean descending = fieldName.startsWith("-");
                    fieldName = descending ? fieldName.substring(1) : fieldName;
                    Object o1 = data1.get(fieldName);
                    Object o2 = data2.get(fieldName);
                    if (o1 == null || o2 == null || o1.equals(o2)) {
                        continue;
                    }
                    if (NumberUtils.isNumber(o1.toString())) {
                        Double d1 = Double.valueOf(o1.toString());
                        Double d2 = Double.valueOf(o2.toString());
                        return descending ? d2.compareTo(d1) : d1.compareTo(d2);
                    } else {
                        String s1 = o1.toString();
                        String s2 = o2.toString();
                        return descending ? s2.compareTo(s1) : s1.compareTo(s2);
                    }
                }
                return 0;
            }

        });
    }
    return dataList;
}

From source file:eu.planets_project.pp.plato.evaluation.evaluators.ImageComparisonEvaluator.java

public HashMap<MeasurementInfoUri, Value> evaluate(Alternative alternative, SampleObject sample,
        DigitalObject result, List<MeasurementInfoUri> measurementInfoUris, IStatusListener listener)
        throws EvaluatorException {

    //listener.updateStatus(NAME + ": Start evaluation"); //" for alternative: %s, sample: %s", NAME, alternative.getName(), sample.getFullname()));
    setUp();/*from   www.j  av a  2 s .  c  o  m*/
    try {
        HashMap<MeasurementInfoUri, Value> results = new HashMap<MeasurementInfoUri, Value>();

        saveTempFile(sample);
        saveTempFile(result);

        // NOTE: imageEvaluator is still called once per leaf !
        // -> could be optimized, but the used minimee evaluator will do separate calls anyway 
        ImageCompareEvaluator imageEvaluator = new ImageCompareEvaluator();

        for (MeasurementInfoUri measurementInfoUri : measurementInfoUris) {
            String propertyURI = measurementInfoUri.getAsURI();
            String fragment = measurementInfoUri.getFragment();
            Scale scale = descriptor.getMeasurementScale(measurementInfoUri);
            if (scale == null) {
                // This means that I am not entitled to evaluate this measurementInfo and therefore supposed to skip it:
                continue;
            }
            if ((propertyURI != null) && propertyURI.startsWith(OBJECT_IMAGE_SIMILARITY + "#")) {
                Value v = null;
                if (fragment.equals("equal")) {
                    Double d = imageEvaluator.evaluate(tempDir.getAbsolutePath(), tempFiles.get(sample),
                            tempFiles.get(result), "AE");

                    if (d.compareTo(Scale.MAX_VALUE) == 0) {
                        // No: only evaluation results are returned, no error messages
                        // v.setComment("ImageMagick compare failed or could not be called");
                    } else {
                        v = scale.createValue();
                        ((BooleanValue) v).bool(d.compareTo(0.0) == 0);
                        v.setComment(
                                "ImageMagick compare returned " + Double.toString(d) + " different pixels");
                    }
                    //                log.debug("difference" + Double.toString(Scale.MAX_VALUE-d));
                } else {
                    Double d = imageEvaluator.evaluate(tempDir.getAbsolutePath(), tempFiles.get(sample),
                            tempFiles.get(result), fragment);
                    if (d == null) {
                        // No: only evaluation results are returned, no error messages
                        // v = leaf.getScale().createValue();
                        // v.setComment("ImageMagick comparison failed");
                    } else {
                        v = scale.createValue();
                        if (v instanceof FloatValue) {
                            ((FloatValue) v).setValue(d);
                            v.setComment("computed by ImageMagick compare");
                        } else if (v instanceof PositiveFloatValue) {
                            ((PositiveFloatValue) v).setValue(d);
                            v.setComment("computed by ImageMagick compare");
                        } else {
                            v.setComment("ImageMagick comparison failed - wrong Scale defined.");
                        }
                    }
                }
                if (v != null) {
                    // add the value to the result set
                    results.put(measurementInfoUri, v);
                }
            }
        }
        return results;
    } finally {
        tearDown();
    }
}