/** * Compares the two specified {@code double} values. The sign of the value returned is the same as * that of <code>((Double) a).{@linkplain Double#compareTo compareTo}(b)</code>. As with that * method, {@code NaN} is treated as greater than all other values, and {@code 0.0 > -0.0}. * * <p><b>Note:</b> this method simply delegates to the JDK method {@link Double#compare}. It is * provided for consistency with the other primitive types, whose compare methods were not added * to the JDK until JDK 7. * * @param a the first {@code double} to compare * @param b the second {@code double} to compare * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is * greater than {@code b}; or zero if they are equal */ public static int compare(double a, double b) { return Double.compare(a, b); }
@Override public int compare(PairFrequency o1, PairFrequency o2) { return -Double.compare(o1.mi, o2.mi); } });
@Override public int compareTo(QueueElement other) { return Double.compare(weight, other.weight); } }
@Override public int compare(PairFrequency o1, PairFrequency o2) { return -Double.compare(o1.le, o2.le); } });
@Override public int compare(PairFrequency o1, PairFrequency o2) { return -Double.compare(o1.re, o2.re); } });
@Override public int compare(PairFrequency o1, PairFrequency o2) { return -Double.compare(o1.score, o2.score); } });
@Override public int compareTo(State o) { return Double.compare(cost, o.cost); }
/** * Compares this mutable to another in ascending order. * * @param other the other mutable to compare to, not null * @return negative if this is less, zero if equal, positive if greater */ @Override public int compareTo(final MutableDouble other) { return Double.compare(this.value, other.value); }
@Override public int compare(double[] left, double[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Double.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
public int compareTo(Tag that) { int r = Double.compare(this.ordinal, that.ordinal); if (r!=0) return -r; // descending for ordinal return this.hierarchy.compareTo(that.hierarchy); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Estimate estimate = (Estimate) o; return Double.compare(estimate.value, value) == 0; }
private static String doubleToString(double value) { if (Double.compare(value, Math.floor(value)) == 0 && !Double.isInfinite(value)) { return Integer.toString((int) value); } // remove trailing zeroes NumberFormat f = NumberFormat.getInstance(Locale.ROOT); f.setMaximumFractionDigits(4); f.setMinimumIntegerDigits(1); return f.format(value); }
@Override public ComparisonChain compare(double left, double right) { return classify(Double.compare(left, right)); }
@Override public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { double leftValue = longBitsToDouble(leftBlock.getLong(leftPosition, 0)); double rightValue = longBitsToDouble(rightBlock.getLong(rightPosition, 0)); return Double.compare(leftValue, rightValue); }
@Override public int compareTo(Cluster<K> o) { return Double.compare(o.sectioned_gain(), sectioned_gain()); } }
@Override protected int compareParameters(MediaType mediaType1, MediaType mediaType2) { double quality1 = mediaType1.getQualityValue(); double quality2 = mediaType2.getQualityValue(); int qualityComparison = Double.compare(quality2, quality1); if (qualityComparison != 0) { return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3 } return super.compareParameters(mediaType1, mediaType2); } };
private static void testSortDescending( double[] input, int fromIndex, int toIndex, double[] expectedOutput) { input = Arrays.copyOf(input, input.length); Doubles.sortDescending(input, fromIndex, toIndex); // GWT's Arrays.equals doesn't appear to handle NaN correctly, so test each element individually for (int i = 0; i < input.length; i++) { assertEquals(0, Double.compare(expectedOutput[i], input[i])); } }
private static void testSortDescending(double[] input, double[] expectedOutput) { input = Arrays.copyOf(input, input.length); Doubles.sortDescending(input); // GWT's Arrays.equals doesn't appear to handle NaN correctly, so test each element individually for (int i = 0; i < input.length; i++) { assertEquals(0, Double.compare(expectedOutput[i], input[i])); } }
private static void runTestFuzzyCompare(int toleranceIndex) { double tolerance = get(TOLERANCE_CANDIDATES, toleranceIndex); for (double a : ALL_DOUBLE_CANDIDATES) { for (double b : ALL_DOUBLE_CANDIDATES) { int expected = DoubleMath.fuzzyEquals(a, b, tolerance) ? 0 : Double.compare(a, b); int actual = DoubleMath.fuzzyCompare(a, b, tolerance); assertEquals(Integer.signum(expected), Integer.signum(actual)); } } }
private void testCustomAggregation(Double[] values, int n) { PriorityQueue<Double> heap = new PriorityQueue<>(n, (x, y) -> -Double.compare(x, y)); Arrays.stream(values).filter(x -> x != null).forEach(heap::add); Double[] expected = new Double[heap.size()]; for (int i = heap.size() - 1; i >= 0; i--) { expected[i] = heap.remove(); } testAggregation(Arrays.asList(expected), createDoublesBlock(values), createLongRepeatBlock(n, values.length)); } }