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:com.joptimizer.util.ColtUtils.java

/**
 * Returns v = A[T].a + beta*b./* w w w  . j av a 2 s  . com*/
 * Useful in avoiding the need of the copy() in the colt api.
 */
public static final DoubleMatrix1D zMultTranspose(final DoubleMatrix2D A, final DoubleMatrix1D a,
        final DoubleMatrix1D b, final double beta) {
    if (A.rows() != a.size() || A.columns() != b.size()) {
        throw new IllegalArgumentException("wrong matrices dimensions");
    }
    final DoubleMatrix1D ret = DoubleFactory1D.dense.make(A.columns());

    if (A instanceof SparseDoubleMatrix2D) {
        //if(1==2){   
        A.forEachNonZero(new IntIntDoubleFunction() {
            public double apply(int i, int j, double Aij) {
                //log.debug(i + "," + j + ": " + Aij + ", "+ret.getQuick(j)+", "+a.getQuick(i));
                ret.setQuick(j, ret.getQuick(j) + Aij * a.getQuick(i));
                return Aij;
            }
        });
        if (Double.compare(0., beta) != 0) {
            for (int i = 0; i < ret.size(); i++) {
                ret.setQuick(i, ret.getQuick(i) + beta * b.getQuick(i));
            }
        }
    } else {
        for (int i = 0; i < A.columns(); i++) {
            double vi = beta * b.getQuick(i);
            for (int j = 0; j < A.rows(); j++) {
                vi += A.getQuick(j, i) * a.getQuick(j);
            }
            ret.setQuick(i, vi);
        }
    }

    return ret;
}

From source file:edu.berkeley.path.bots.core.Coordinate.java

/**
 * Defines ordering for Coordinate objects, SRID then lat then lon.<br/>
 * SRID is sorted with null larger than the integers, and for the lat and
 * lon values, {@link Double#NaN} is bigger than
 * {@link Double#POSITIVE_INFINITY} which is bigger than the integers
 * (including -0.0) with {@link Double#NEGATIVE_INFINITY} as the smallest.
 * <p/>/*w w  w .j a  v a 2s .  c o m*/
 * Always returns one of -1, 0, or 1 to work within
 * {@link #equalsEpsilon(core.Coordinate)}.
 * 
 * @param otherCoord
 *            to compare to.
 * @return 0 if <code>srid</code>, <code>lat</code>, and <code>lon</code>
 *         (the combined fields, in that order) are all exactly equal.<br/>
 *         1 if combined fields (of this) are &ldquo;bigger&rdquo;.<br/>
 *         -1 if combined fields (of this) are &ldquo;smaller&rdquo;.
 * @throws ClassCastException
 *             if otherCoord is null
 */
@Override
public int compareTo(Coordinate otherCoord) {
    // Unlikely (very) to have two refs to the same instance,
    // so no need for the optimization of this == otherCoord.

    // Need to sort by SRID first, null is biggest
    if (!this.equalsSRID(otherCoord)) {
        // Only need to sort by SRID (unless otherCoord is null).
        if (null == otherCoord) {
            throw new ClassCastException("Arg otherCoord is null.");
        }
        if (null == this.srid()) {
            return 1;
        } else if (null == otherCoord.srid()) {
            return -1;
        }
        // Use .compareTo() in Integer.
        if (0 < this.srid().compareTo(otherCoord.srid())) {
            return 1;
        } else {
            return -1;
        }
    }
    // SRID the same, compare lat

    // otherCoord is gaurenteed to not be null by the above call
    // to .equalsSRID().

    // Need to use Double.compare() to deal with edge values (NaN and Inf).
    int cmpi = Double.compare(this.lat(), otherCoord.lat()); // otherCoord
                                                             // can't
                                                             // be null.

    if (0 < cmpi) {
        return 1;
    }
    if (0 > cmpi) {
        return -1;
    }

    // OK, now lat
    cmpi = Double.compare(this.lon(), otherCoord.lon());

    if (0 < cmpi) {
        return 1;
    }
    if (0 > cmpi) {
        return -1;
    }

    // Finally we can say they are the same.
    return 0;
}

From source file:com.likethecolor.alchemy.api.entity.ConceptAlchemyEntity.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*from   www  .j ava 2s. c  o  m*/
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    if (!super.equals(o)) {
        return false;
    }

    ConceptAlchemyEntity entity = (ConceptAlchemyEntity) o;

    if (getCensus() != null ? !getCensus().equals(entity.getCensus()) : entity.getCensus() != null) {
        return false;
    }
    if (getCIAFactbook() != null ? !getCIAFactbook().equals(entity.getCIAFactbook())
            : entity.getCIAFactbook() != null) {
        return false;
    }
    if (concept != null ? !concept.equals(entity.concept) : entity.concept != null) {
        return false;
    }
    if (getCrunchbase() != null ? !getCrunchbase().equals(entity.getCrunchbase())
            : entity.getCrunchbase() != null) {
        return false;
    }
    if (getDBPedia() != null ? !getDBPedia().equals(entity.getDBPedia()) : entity.getDBPedia() != null) {
        return false;
    }
    if (getFreebase() != null ? !getFreebase().equals(entity.getFreebase()) : entity.getFreebase() != null) {
        return false;
    }
    if (getGeo() != null ? !getGeo().equals(entity.getGeo()) : entity.getGeo() != null) {
        return false;
    }

    if (Double.compare(entity.getLatitude(), getLatitude()) != 0) {
        return false;
    }
    if (Double.compare(entity.getLongitude(), getLongitude()) != 0) {
        return false;
    }
    if (getGeonames() != null ? !getGeonames().equals(entity.getGeonames()) : entity.getGeonames() != null) {
        return false;
    }
    if (getMusicBrainz() != null ? !getMusicBrainz().equals(entity.getMusicBrainz())
            : entity.getMusicBrainz() != null) {
        return false;
    }
    if (getOpencyc() != null ? !getOpencyc().equals(entity.getOpencyc()) : entity.getOpencyc() != null) {
        return false;
    }
    if (getSemanticCrunchbase() != null ? !getSemanticCrunchbase().equals(entity.getSemanticCrunchbase())
            : entity.getSemanticCrunchbase() != null) {
        return false;
    }
    if (getWebsite() != null ? !getWebsite().equals(entity.getWebsite()) : entity.getWebsite() != null) {
        return false;
    }
    if (getYago() != null ? !getYago().equals(entity.getYago()) : entity.getYago() != null) {
        return false;
    }

    return true;
}

From source file:com.opengamma.analytics.financial.interestrate.payments.derivative.CapFloorIbor.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }/* ww w.  j a v  a  2s. co m*/
    if (!super.equals(obj)) {
        return false;
    }
    if (!(obj instanceof CapFloorIbor)) {
        return false;
    }
    final CapFloorIbor other = (CapFloorIbor) obj;
    if (_isCap != other._isCap) {
        return false;
    }
    if (Double.compare(_strike, other._strike) != 0) {
        return false;
    }
    if (Double.compare(_fixingPeriodEndTime, other._fixingPeriodEndTime) != 0) {
        return false;
    }
    if (Double.compare(_fixingPeriodStartTime, other._fixingPeriodStartTime) != 0) {
        return false;
    }
    if (Double.compare(_fixingAccrualFactor, other._fixingAccrualFactor) != 0) {
        return false;
    }
    if (!ObjectUtils.equals(_forwardCurveName, other._forwardCurveName)) {
        return false;
    }
    if (!ObjectUtils.equals(_index, other._index)) {
        return false;
    }
    return true;
}

From source file:csci310.parkhere.controller.ClientController.java

public SearchResults sortSearchResultByDist() {
    if (searchResults != null) {
        Collections.sort(searchResults.searchResultList, new Comparator<ParkingSpot>() {
            public int compare(ParkingSpot p1, ParkingSpot p2) {
                double p1LatDiff = p1.getLat() - currLocation.latitude;
                double p1LongDiff = p1.getLon() - currLocation.longitude;
                double p1Dist = Math.sqrt(p1LatDiff * p1LatDiff + p1LongDiff * p1LongDiff);

                double p2LatDiff = p2.getLat() - currLocation.latitude;
                double p2LongDiff = p2.getLon() - currLocation.longitude;
                double p2Dist = Math.sqrt(p2LatDiff * p2LatDiff + p2LongDiff * p2LongDiff);

                return Double.compare(p1Dist, p2Dist);
            }/*from  w w w  .  ja  va2s  .c om*/
        });
    }
    return searchResults;
}

From source file:name.nanek.gdwprototype.shared.model.support.CompareToBuilder.java

/**
 * <p>Appends to the <code>builder</code> the comparison of
 * two <code>double</code>s.</p>
 *
 * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>
 *
 * <p>It is compatible with the hash code generated by
 * <code>HashCodeBuilder</code>.</p>
 *
 * @param lhs  left-hand value//from  w  w w .ja  v  a  2 s  . co m
 * @param rhs  right-hand value
 * @return this - used to chain append calls
 */
public CompareToBuilder append(double lhs, double rhs) {
    if (comparison != 0) {
        return this;
    }
    comparison = Double.compare(lhs, rhs);
    return this;
}

From source file:com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }/* w  w w  . j  av a 2 s. c  o m*/
    if (!(obj instanceof ISDADateCurve)) {
        return false;
    }
    final ISDADateCurve other = (ISDADateCurve) obj;
    if (!ObjectUtils.equals(_name, other._name)) {
        return false;
    }
    if (Double.compare(_zeroDiscountFactor, other._zeroDiscountFactor) != 0) {
        return false;
    }
    if (!Arrays.equals(_curveDates, other._curveDates)) {
        return false;
    }
    if (!Arrays.equals(_shiftedTimePoints, other._shiftedTimePoints)) {
        return false;
    }
    return true;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.algorithm.DBEA.java

/**
 * Returns a copy of the population sorted by the sum-of-squares of all
 * but one objective./*from w w w  .  j  av  a  2 s  .co  m*/
 * 
 * @param objective the ignored objective
 * @param population the population
 * @return a copy of the population ordered by the sum-of-squares of all
 *         but one objective
 */
private Population orderBySmallestSquaredValue(final int objective, Population population) {
    Population result = new Population();
    result.addAll(population);

    result.sort(new Comparator<Solution>() {

        @Override
        public int compare(Solution s1, Solution s2) {
            double sum1 = 0.0;
            double sum2 = 0.0;

            for (int i = 0; i < problem.getNumberOfObjectives(); i++) {
                if (i != objective) {
                    sum1 += Math.pow(s1.getObjective(i), 2.0);
                    sum2 += Math.pow(s2.getObjective(i), 2.0);
                }
            }

            return Double.compare(sum1, sum2);
        }

    });

    return result;
}

From source file:ch.unil.genescore.pathway.GeneSetLibrary.java

License:asdf

/** Sort gene sets by enrichment p-value */
public void sortGeneSets() {

    class GeneSetComparator implements Comparator<GeneSet> {
        @Override//from   w  w  w  .j  ava 2 s.co  m
        public int compare(GeneSet set1, GeneSet set2) {
            if (Pascal.set.useChi2_)
                return Double.compare(set1.getChi2Pvalue(), set2.getChi2Pvalue());
            else
                return Double.compare(set1.getSimulPvalue(), set2.getSimulPvalue());
        }
    }
    Collections.sort(geneSets_, new GeneSetComparator());
}

From source file:eu.hansolo.tilesfx.tools.Location.java

@Override
public boolean equals(final Object OBJECT) {
    if (OBJECT instanceof Location) {
        final Location LOCATION = (Location) OBJECT;
        return (Double.compare(latitude, LOCATION.latitude) == 0
                && Double.compare(longitude, LOCATION.longitude) == 0
                && Double.compare(altitude, LOCATION.altitude) == 0);
    } else {/*  w  w  w  .j a  v a  2s  . c  om*/
        return false;
    }
}