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:de.pixida.logtest.designer.automaton.LineIntersector.java

static List<Intersection> calculateIntersections(final Point2D point, final Point2D vec,
        final List<Line> lines) {
    Validate.notNull(point);/*from   w  w w  .j  av a  2s. c  o m*/
    Validate.notNull(vec);
    Validate.notNull(lines);

    final List<Intersection> results = new ArrayList<>();
    for (final Line line : lines) {
        final Point2D intersection = calculateIntersection(point, vec, line);
        if (intersection == null) {
            continue;
        }

        if (!checkIfPointIsOnTheLine(intersection, line)) {
            continue;
        }

        results.add(new Intersection(intersection, line, point.distance(intersection)));
    }

    Collections.sort(results, (r0, r1) -> Double.compare(r0.getDistance(), r1.getDistance()));

    return results;
}

From source file:it.unibo.alchemist.SupportedIncarnations.java

/**
 * Fetches an incarnation whose name matches the supplied string.
 * /*from   ww w  .j av  a2s.c  o m*/
 * @param s
 *            the name of the {@link Incarnation}
 * @param <T>
 *            {@link Concentration} type
 * @return an {@link Optional} containing the incarnation, if one with a
 *         matching name exists
 */
@SuppressWarnings("unchecked")
public static <T> Optional<Incarnation<T>> get(final String s) {
    final String cmp = preprocess(s);
    return INCARNATIONS.stream()
            .map(clazz -> new Pair<>(METRIC.distance(preprocess(clazz.getSimpleName()), cmp), clazz))
            .min((p1, p2) -> Double.compare(p1.getFirst(), p2.getFirst())).map(Pair::getSecond)
            .flatMap(clazz -> {
                try {
                    return Optional.of(clazz.newInstance());
                } catch (Exception e) {
                    L.error("Unable to instance incarnation " + clazz + " (closest match to " + s + " among "
                            + INCARNATIONS + ")", e);
                    return Optional.empty();
                }
            });
}

From source file:com.teradata.benchto.driver.service.Measurement.java

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

    Measurement that = (Measurement) o;

    return Double.compare(that.value, value) == 0 && name.equals(that.name) && unit.equals(that.unit);
}

From source file:com.squarespace.template.JsonUtils.java

/**
 * Compare two JsonNode objects and return an integer.
 *
 * @return  a negative integer, zero, or a positive integer as this object
 *          is less than, equal to, or greater than the specified object.
 *///w w  w.j a va 2s. co  m
public static int compare(JsonNode left, JsonNode right) {
    if (left.isLong() || left.isInt()) {
        return Long.compare(left.asLong(), right.asLong());

    } else if (left.isDouble() || left.isFloat()) {
        return Double.compare(left.asDouble(), right.asDouble());

    } else if (left.isTextual()) {
        return left.asText().compareTo(right.asText());

    } else if (left.isBoolean()) {
        return Boolean.compare(left.asBoolean(), right.asBoolean());
    }

    // Not comparable in a relative sense, default to equals.
    return left.equals(right) ? 0 : -1;
}

From source file:com.amalto.core.storage.inmemory.matcher.CompareMatcher.java

@Override
public boolean match(DataRecord record) {
    Object recordValue = record.get(field);
    if (recordValue == null) {
        return false;
    }/*from  ww  w  .jav  a2s. c  o m*/
    Object matchValue = StorageMetadataUtils.convert(value, field);
    if (predicate == Predicate.CONTAINS) {
        return recordValue.toString().indexOf(matchValue.toString()) > 0;
    } else if (predicate == Predicate.EQUALS) {
        return recordValue.toString().equals(matchValue.toString());
    } else if (predicate == Predicate.GREATER_THAN) {
        return Double.compare(((Double) recordValue), ((Double) matchValue)) > 0;
    } else if (predicate == Predicate.GREATER_THAN_OR_EQUALS) {
        return Double.compare(((Double) recordValue), ((Double) matchValue)) >= 0;
    } else if (predicate == Predicate.LOWER_THAN) {
        return Double.compare(((Double) recordValue), ((Double) matchValue)) < 0;
    } else if (predicate == Predicate.LOWER_THAN_OR_EQUALS) {
        return Double.compare(((Double) recordValue), ((Double) matchValue)) <= 0;
    } else if (predicate == Predicate.STARTS_WITH) {
        return recordValue.toString().indexOf(matchValue.toString()) == 0;
    } else {
        throw new NotImplementedException();
    }
}

From source file:de.rallye.model.structures.LatLng.java

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

    LatLng latLng = (LatLng) o;//  ww w.  j  av a2  s  . co m

    return Double.compare(latLng.latitude, latitude) == 0 && Double.compare(latLng.longitude, longitude) == 0;

}

From source file:com.hbc.api.trade.bdata.common.util.ParameterValidator.java

/**
 * @param paramValue ??/*from   w w w .j  av  a2s  .co  m*/
 * @param paramNameTip ????
 */
public static void validateParamNumberGreaterThan0(Double paramValue, String paramNameTip) {
    if (paramValue == null || Double.compare(paramValue.doubleValue(), 0) <= 0) {
        throw new ParamValidateException(CommonReturnCodeEnum.PARAM_ERROR_WITHARG, paramNameTip);
    }
}

From source file:org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.java

/**
 * Returns a calendar object from a julian date.
 *//*from  ww  w .ja v a2  s .c  o  m*/
public static Calendar toCalendar(double julianDate) {
    if (Double.compare(julianDate, Double.NaN) == 0 || julianDate == 0) {
        return null;
    }
    long millis = (long) ((julianDate + 0.5 - J1970) * MILLISECONDS_PER_DAY);
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(millis);
    return DateUtils.round(cal, Calendar.MINUTE);
}

From source file:com.linkedin.cubert.memory.DoubleArrayList.java

@Override
public int compareIndices(int i1, int i2) {
    return Double.compare(getDouble(i1), getDouble(i2));
}

From source file:org.apache.mahout.utils.vectors.io.AbstractClusterWriter.java

public static String getTopFeatures(Vector vector, String[] dictionary, int numTerms) {

    List<TermIndexWeight> vectorTerms = Lists.newArrayList();

    Iterator<Vector.Element> iter = vector.iterateNonZero();
    while (iter.hasNext()) {
        Vector.Element elt = iter.next();
        vectorTerms.add(new TermIndexWeight(elt.index(), elt.get()));
    }/*from w w w.j  a v a2  s. c  om*/

    // 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 = new LinkedList<Pair<String, Double>>();

    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));
    }

    StringBuilder sb = new StringBuilder(100);

    for (Pair<String, Double> item : topTerms) {
        String term = item.getFirst();
        sb.append("\n\t\t");
        sb.append(StringUtils.rightPad(term, 40));
        sb.append("=>");
        sb.append(StringUtils.leftPad(item.getSecond().toString(), 20));
    }
    return sb.toString();
}