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.apache.mahout.utils.clustering.AbstractClusterWriter.java

private static Collection<Pair<String, Double>> getTopPairs(Vector vector, String[] dictionary, int numTerms) {
    List<TermIndexWeight> vectorTerms = Lists.newArrayList();

    for (Vector.Element elt : vector.nonZeroes()) {
        vectorTerms.add(new TermIndexWeight(elt.index(), elt.get()));
    }//from  ww  w. j a v  a 2  s . com

    // Sort results in reverse order (ie weight in descending order)
    Collections.sort(vectorTerms, new Comparator<TermIndexWeight>() {
        @Override
        public int compare(TermIndexWeight one, TermIndexWeight two) {
            return Double.compare(two.weight, one.weight);
        }
    });

    Collection<Pair<String, Double>> topTerms = Lists.newLinkedList();

    for (int i = 0; i < vectorTerms.size() && i < numTerms; i++) {
        int index = vectorTerms.get(i).index;
        String dictTerm = dictionary[index];
        if (dictTerm == null) {
            log.error("Dictionary entry missing for {}", index);
            continue;
        }
        topTerms.add(new Pair<String, Double>(dictTerm, vectorTerms.get(i).weight));
    }

    return topTerms;
}

From source file:org.mifos.accounts.loan.util.helpers.LoanAccountDetailsViewHelper.java

public boolean isAmountZeroOrNull() {
    return loanAmount == null
            || (Double.compare(new LocalizationConverter().getDoubleValueForCurrentLocale(loanAmount),
                    NumberUtils.DOUBLE_ZERO) == 0);
}

From source file:com.proofpoint.units.DataSize.java

@Override
public int compareTo(DataSize o) {
    return Double.compare(getValue(Unit.BYTE), o.getValue(Unit.BYTE));
}

From source file:com.opengamma.analytics.financial.commodity.definition.CommodityFutureOptionDefinition.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*from  w  w  w . ja v a2s .co  m*/
    if (!(obj instanceof CommodityFutureOptionDefinition)) {
        return false;
    }
    final CommodityFutureOptionDefinition<?, ?> other = (CommodityFutureOptionDefinition<?, ?>) obj;
    if (!ObjectUtils.equals(_expiryDate, other._expiryDate)) {
        return false;
    }
    if (!ObjectUtils.equals(_underlying, other._underlying)) {
        return false;
    }
    if (!ObjectUtils.equals(_exerciseType, other._exerciseType)) {
        return false;
    }
    if (Double.compare(_strike, other._strike) != 0) {
        return false;
    }
    if (_isCall != other._isCall) {
        return false;
    }
    return true;
}

From source file:org.t3as.ner.Phrase.java

/** This method will do the classification of a Phrase with a EntityClass. */
public void classify() {
    EntityClass type = null;/*from ww  w .j  ava 2s .c  om*/
    double s = 0;
    boolean ambiguous = false;
    for (final Map.Entry<EntityClass, Double> e : score.entrySet()) {
        if (type == null) {
            type = e.getKey();
            s = e.getValue();
        } else {
            if (Double.compare(e.getValue(), s) > 0) {
                type = e.getKey();
                s = e.getValue();
                ambiguous = false;
            } else if (Double.compare(s, e.getValue()) == 0) {
                ambiguous = true;
            }
        }
    }
    this.phraseType = ambiguous ? UNKNOWN : type;
}

From source file:it.unibo.torsello.bluetoothpositioning.fragment.DeviceListFragment.java

@Override
public void update(Observable o, Object arg) {

    if (arg instanceof List) {

        if (!deviceList.isEmpty()) {
            deviceList.clear();/*from  www  .j a  v  a2s  .  c o m*/
        }

        List<Device> devices = (List<Device>) arg;

        // optional sorting
        Collections.sort(devices, new Comparator<Device>() {
            public int compare(Device b1, Device b2) {
                int sorting = preferences.getInt(SettingConstants.DISTANCE_SORTING, 0);
                switch (sorting) {
                case 0:
                case R.id.radioButton_default_sorting:
                    return Double.compare(b1.getIndex(), b2.getIndex());
                case R.id.radioButton_color_sorting:
                    return Double.compare(b1.getColor(), b2.getColor());
                case R.id.radioButton_distance_sorting:
                    return Double.compare(b1.getKalmanFilterDistance(), b2.getKalmanFilterDistance());
                } // default sorting (a good basic ordering for the other options)
                return Double.compare(b1.getIndex(), b2.getIndex());
            }
        });

        deviceList.addAll(devices);
        deviceViewAdapter.notifyDataSetChanged();
    }
}

From source file:it_minds.dk.eindberetningmobil_android.models.internal.SaveableReport.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    SaveableReport that = (SaveableReport) o;

    if (Double.compare(that.totalDistance, totalDistance) != 0)
        return false;
    if (jsonToSend != null ? !jsonToSend.equals(that.jsonToSend) : that.jsonToSend != null)
        return false;
    if (purpose != null ? !purpose.equals(that.purpose) : that.purpose != null)
        return false;
    if (rateid != null ? !rateid.equals(that.rateid) : that.rateid != null)
        return false;
    return !(createdAt != null ? !createdAt.equals(that.createdAt) : that.createdAt != null);

}

From source file:org.diorite.nbt.NbtTagDouble.java

@Override
public boolean equals(final Object o) {
    if (this == o) {
        return true;
    }//from   ww  w .j av a  2s. c o  m
    if (!(o instanceof NbtTagDouble)) {
        return false;
    }
    if (!super.equals(o)) {
        return false;
    }

    final NbtTagDouble that = (NbtTagDouble) o;
    return Double.compare(that.value, this.value) == 0;
}

From source file:com.joptimizer.algebra.CholeskyRCFactorization.java

/**
 * //  ww w.  j  av a 2  s  . c om
 * @deprecated use the solve() methods instead
 */
@Deprecated
public DoubleMatrix2D getInverse() {

    //QInv = LTInv * LInv, but for symmetry (QInv=QInvT)
    //QInv = LInvT * LTInvT = LInvT * LInv, so
    //LInvT = LTInv, and we calculate
    //QInv = LInvT * LInv

    // LTInv calculation (it will be x)
    // NB: LInv is lower-triangular
    double[] LInv = new double[dim * dim];
    //      for(int i=0; i<dim; i++){
    //         //diagonal filling
    //         LInv[i*dim + i] = 1.;
    //      }
    for (int j = 0; j < dim; j++) {
        int jShift = j * dim;
        LInv[jShift + j] = 1.;//diagonal filling
        final double lTJJ = LData[jShift + j];
        for (int k = 0; k < j + 1; ++k) {
            LInv[jShift + k] /= lTJJ;
        }
        for (int i = j + 1; i < dim; i++) {
            int iShift = i * dim;
            final double lTJI = LData[iShift + j];
            if (Double.compare(lTJI, 0.) != 0) {
                for (int k = 0; k < j + 1; ++k) {
                    LInv[iShift + k] -= LInv[jShift + k] * lTJI;
                }
            }
        }
    }

    //log.debug("LInv: " + ArrayUtils.toString(LInv));

    // QInv
    // NB: LInvT is upper-triangular, so LInvT[i][j]=0 if i>j
    final DoubleMatrix2D QInvData = F2.make(dim, dim);
    for (int row = 0; row < dim; row++) {
        //final double[] LInvTDataRow = LInvTData[row];
        final DoubleMatrix1D QInvDataRow = QInvData.viewRow(row);
        for (int col = row; col < dim; col++) {// symmetry of QInv
            //final double[] LInvTDataCol = LInvTData[col];
            double sum = 0;
            for (int i = col; i < dim; i++) {// upper triangular
                sum += LInv[i * dim + row] * LInv[i * dim + col];
            }
            QInvDataRow.setQuick(col, sum);
            QInvData.setQuick(col, row, sum);// symmetry of QInv
        }
    }

    return QInvData;
}

From source file:org.hawkular.metrics.core.service.metrics.BaseMetricsITest.java

protected <T extends Number> NumericBucketPoint createSingleBucket(List<? extends DataPoint<T>> combinedData,
        DateTime start, DateTime end) {//from   ww  w . j a  v a2 s . c  o  m
    T expectedMin = combinedData.stream()
            .min((x, y) -> Double.compare(x.getValue().doubleValue(), y.getValue().doubleValue())).get()
            .getValue();
    T expectedMax = combinedData.stream()
            .max((x, y) -> Double.compare(x.getValue().doubleValue(), y.getValue().doubleValue())).get()
            .getValue();
    PercentileWrapper expectedMedian = NumericDataPointCollector.createPercentile.apply(50.0);
    Mean expectedAverage = new Mean();
    Sum expectedSamples = new Sum();
    Sum expectedSum = new Sum();
    combinedData.stream().forEach(arg -> {
        expectedMedian.addValue(arg.getValue().doubleValue());
        expectedAverage.increment(arg.getValue().doubleValue());
        expectedSamples.increment(1);
        expectedSum.increment(arg.getValue().doubleValue());
    });

    return new NumericBucketPoint.Builder(start.getMillis(), end.getMillis()).setMin(expectedMin.doubleValue())
            .setMax(expectedMax.doubleValue()).setAvg(expectedAverage.getResult())
            .setMedian(expectedMedian.getResult()).setSum(expectedSum.getResult())
            .setSamples(new Double(expectedSamples.getResult()).intValue()).build();
}