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.codelanx.codelanxlib.util.Players.java

/**
 * Returns the closest {@link Player} adjacent to another {@link Player}
 * //from   w w w  . j  av  a2s  . c  o  m
 * @since 0.1.0
 * @version 0.1.0
 * 
 * @param p The {@link Player} at the origin to search around
 * @return The closest {@link Player}, or {@code null} if no one else is in
 *         the world
 */
public static Player getClosestPlayer(Player p) {
    Location loc = p.getLocation();
    return p.getWorld().getPlayers().stream().filter((o) -> !p.equals(o)).min((p1, p2) -> {
        return Double.compare(p1.getLocation().distanceSquared(loc), p2.getLocation().distanceSquared(loc));
    }).orElse(null);
}

From source file:it_minds.dk.eindberetningmobil_android.models.GPSCoordinateModel.java

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

    GPSCoordinateModel that = (GPSCoordinateModel) o;

    if (Double.compare(that.Latitude, Latitude) != 0)
        return false;
    if (Double.compare(that.Longitude, Longitude) != 0)
        return false;
    return IsViaPoint == that.IsViaPoint;

}

From source file:io.seldon.client.beans.UserTrustNodeBean.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (!(o instanceof UserTrustNodeBean))
        return false;

    UserTrustNodeBean that = (UserTrustNodeBean) o;

    if (pos != that.pos)
        return false;
    if (Double.compare(that.trust, trust) != 0)
        return false;
    if (dimension != null ? !dimension.equals(that.dimension) : that.dimension != null)
        return false;
    if (user != null ? !user.equals(that.user) : that.user != null)
        return false;

    return true;//  ww w . j a v  a2  s.co m
}

From source file:org.sonar.api.utils.WorkUnit.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/* w ww.j  a  v  a  2 s .c  o m*/
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    WorkUnit workUnit = (WorkUnit) o;

    if (Double.compare(workUnit.value, value) != 0) {
        return false;
    }
    return unit.equals(workUnit.unit);

}

From source file:org.zenoss.app.consumer.metric.data.Metric.java

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

    Metric metric = (Metric) o;//from   w ww.jav  a  2 s .  co  m

    if (timestamp != metric.timestamp)
        return false;
    if (Double.compare(metric.value, value) != 0)
        return false;
    if (this.metric != null ? !this.metric.equals(metric.metric) : metric.metric != null)
        return false;
    if (tags != null ? !tags.equals(metric.tags) : metric.tags != null)
        return false;

    return true;
}

From source file:io.seldon.client.beans.DimensionBean.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (!(o instanceof DimensionBean))
        return false;

    DimensionBean that = (DimensionBean) o;

    if (Double.compare(that.amount, amount) != 0)
        return false;
    if (attr != that.attr)
        return false;
    if (dimId != that.dimId)
        return false;
    if (val != that.val)
        return false;
    if (attrName != null ? !attrName.equals(that.attrName) : that.attrName != null)
        return false;
    if (itemType != null ? !itemType.equals(that.itemType) : that.itemType != null)
        return false;
    if (valName != null ? !valName.equals(that.valName) : that.valName != null)
        return false;

    return true;//  w w w .  j a v a2s . c  o m
}

From source file:com.cloudera.oryx.common.math.DoubleWeightedMean.java

@Override
public boolean equals(Object o) {
    if (!(o instanceof DoubleWeightedMean)) {
        return false;
    }//from  w  ww .ja  va2  s .c  o m
    DoubleWeightedMean other = (DoubleWeightedMean) o;
    return count == other.count && Double.compare(totalWeight, other.totalWeight) == 0
            && Double.compare(mean, other.mean) == 0;
}

From source file:hivemall.xgboost.classification.XGBoostMulticlassClassifierUDTF.java

@Override
protected void checkTargetValue(final double target) throws HiveException {
    double num_class = ((Integer) params.get("num_class")).doubleValue();
    if (target < 0.0 || target > num_class || Double.compare(target - Math.floor(target), 0.0) != 0) {
        throw new HiveException(
                "target must be {0.0, ..., " + String.format("%.1f", (num_class - 1.0)) + "}: " + target);
    }//w w  w . j  a va2s .  c o m
}

From source file:org.hawkular.metrics.core.api.NumericData.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (!(o instanceof NumericData))
        return false;
    if (!super.equals(o))
        return false;

    NumericData that = (NumericData) o;/*from  w w w.  j a v a  2s.  c o m*/

    if (Double.compare(that.value, value) != 0)
        return false;

    return true;
}

From source file:fll.web.playoff.Playoff.java

/**
 * Build the list of teams ordered from top to bottom (visually) of a single
 * elimination bracket./*from   w w  w  . ja v a  2 s .  co  m*/
 * 
 * @param connection connection to the database
 * @param teams the teams in the playoffs
 * @return a List of teams
 * @throws SQLException on a database error
 */
public static List<Team> buildInitialBracketOrder(final Connection connection,
        final BracketSortType bracketSort, final WinnerType winnerCriteria, final List<? extends Team> teams)
        throws SQLException {
    if (null == connection) {
        throw new NullPointerException("Connection cannot be null");
    }

    final List<? extends Team> seedingOrder;
    if (BracketSortType.ALPHA_TEAM == bracketSort) {
        seedingOrder = teams;

        // sort by team name
        Collections.sort(seedingOrder, Team.TEAM_NAME_COMPARATOR);
    } else if (BracketSortType.RANDOM == bracketSort) {
        seedingOrder = teams;
        // assign a random number to each team
        final double[] randoms = new double[seedingOrder.size()];
        final Random generator = new Random();
        for (int i = 0; i < randoms.length; ++i) {
            randoms[i] = generator.nextDouble();
        }
        Collections.sort(seedingOrder, new Comparator<Team>() {
            public int compare(final Team one, final Team two) {
                final int oneIdx = seedingOrder.indexOf(one);
                final int twoIdx = seedingOrder.indexOf(two);
                return Double.compare(randoms[oneIdx], randoms[twoIdx]);
            }
        });
    } else {
        // standard seeding
        final int tournament = Queries.getCurrentTournament(connection);
        final int numSeedingRounds = TournamentParameters.getNumSeedingRounds(connection, tournament);
        if (numSeedingRounds < 1) {
            throw new FLLRuntimeException(
                    "Cannot initialize playoff brackets using scores from seeding rounds when the number of seeing rounds is less than 1");
        }

        seedingOrder = Queries.getPlayoffSeedingOrder(connection, winnerCriteria, teams);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("seedingOrder: " + seedingOrder);
    }

    final int[] seeding = computeInitialBrackets(seedingOrder.size());

    // give byes to the last byesNeeded teams.
    final List<Team> list = new LinkedList<Team>();
    for (final int element : seeding) {
        if (element > seedingOrder.size()) {
            list.add(Team.BYE);
        } else {
            final Team team = seedingOrder.get(element - 1);
            list.add(team);
        }
    }

    if (list.size() != seeding.length) {
        throw new InternalError("Programming error, list size should be the same as seeding length");
    }
    return list;

}