@Override public int compare(boolean[] left, boolean[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Booleans.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@Override public int compare(boolean[] left, boolean[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Booleans.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
@Override public ComparisonChain compareFalseFirst(boolean left, boolean right) { return classify(Booleans.compare(left, right)); }
@Override public ComparisonChain compareTrueFirst(boolean left, boolean right) { return classify(Booleans.compare(right, left)); // reversed }
@Override public int compare(boolean[] left, boolean[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Booleans.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
/** * Compares {@code a} and {@code b} "fuzzily," with a tolerance for nearly-equal values. * * <p>This method is equivalent to {@code fuzzyEquals(a, b, tolerance) ? 0 : Double.compare(a, * b)}. In particular, like {@link Double#compare(double, double)}, it treats all NaN values as * equal and greater than all other values (including {@link Double#POSITIVE_INFINITY}). * * <p>This is <em>not</em> a total ordering and is <em>not</em> suitable for use in {@link * Comparable#compareTo} implementations. In particular, it is not transitive. * * @throws IllegalArgumentException if {@code tolerance} is {@code < 0} or NaN * @since 13.0 */ public static int fuzzyCompare(double a, double b, double tolerance) { if (fuzzyEquals(a, b, tolerance)) { return 0; } else if (a < b) { return -1; } else if (a > b) { return 1; } else { return Booleans.compare(Double.isNaN(a), Double.isNaN(b)); } }
@Override public ComparisonChain compareFalseFirst(boolean left, boolean right) { return classify(Booleans.compare(left, right)); }
@Override public ComparisonChain compareTrueFirst(boolean left, boolean right) { return classify(Booleans.compare(right, left)); // reversed }
@Override public ComparisonChain compareFalseFirst(boolean left, boolean right) { return classify(Booleans.compare(left, right)); }
@Override public ComparisonChain compareTrueFirst(boolean left, boolean right) { return classify(Booleans.compare(right, left)); // reversed }
/** * Compares {@code a} and {@code b} "fuzzily," with a tolerance for nearly-equal values. * * <p>This method is equivalent to {@code fuzzyEquals(a, b, tolerance) ? 0 : Double.compare(a, * b)}. In particular, like {@link Double#compare(double, double)}, it treats all NaN values as * equal and greater than all other values (including {@link Double#POSITIVE_INFINITY}). * * <p>This is <em>not</em> a total ordering and is <em>not</em> suitable for use in {@link * Comparable#compareTo} implementations. In particular, it is not transitive. * * @throws IllegalArgumentException if {@code tolerance} is {@code < 0} or NaN * @since 13.0 */ public static int fuzzyCompare(double a, double b, double tolerance) { if (fuzzyEquals(a, b, tolerance)) { return 0; } else if (a < b) { return -1; } else if (a > b) { return 1; } else { return Booleans.compare(Double.isNaN(a), Double.isNaN(b)); } }
public void testCompare() { for (boolean x : VALUES) { for (boolean y : VALUES) { // note: spec requires only that the sign is the same assertEquals(x + ", " + y, Boolean.valueOf(x).compareTo(y), Booleans.compare(x, y)); } } }
@Override public int compareTo(Cut<C> that) { if (that == belowAll()) { return 1; } if (that == aboveAll()) { return -1; } int result = Range.compareOrThrow(endpoint, that.endpoint); if (result != 0) { return result; } // same value. below comes before above return Booleans.compare(this instanceof AboveValue, that instanceof AboveValue); }
/** * Compares {@code a} and {@code b} "fuzzily," with a tolerance for nearly-equal values. * * <p>This method is equivalent to {@code fuzzyEquals(a, b, tolerance) ? 0 : Double.compare(a, * b)}. In particular, like {@link Double#compare(double, double)}, it treats all NaN values as * equal and greater than all other values (including {@link Double#POSITIVE_INFINITY}). * * <p>This is <em>not</em> a total ordering and is <em>not</em> suitable for use in {@link * Comparable#compareTo} implementations. In particular, it is not transitive. * * @throws IllegalArgumentException if {@code tolerance} is {@code < 0} or NaN * @since 13.0 */ public static int fuzzyCompare(double a, double b, double tolerance) { if (fuzzyEquals(a, b, tolerance)) { return 0; } else if (a < b) { return -1; } else if (a > b) { return 1; } else { return Booleans.compare(Double.isNaN(a), Double.isNaN(b)); } }
@Override public int compareTo(Cut<C> that) { if (that == belowAll()) { return 1; } if (that == aboveAll()) { return -1; } int result = Range.compareOrThrow(endpoint, that.endpoint); if (result != 0) { return result; } // same value. below comes before above return Booleans.compare(this instanceof AboveValue, that instanceof AboveValue); }
@Override public int compareTo(Cut<C> that) { if (that == belowAll()) { return 1; } if (that == aboveAll()) { return -1; } int result = Range.compareOrThrow(endpoint, that.endpoint); if (result != 0) { return result; } // same value. below comes before above return Booleans.compare(this instanceof AboveValue, that instanceof AboveValue); }
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { if (lhs == rhs) { return 0; } if (lhs == null) { return -1; } if (rhs == null) { return 1; } return Booleans.compare((Boolean) lhs, (Boolean) rhs); }
@Override public int compareTo(Object lhs, Object rhs, PDataType rhsType) { return Booleans.compare((Boolean)lhs, (Boolean)rhs); }
@ExpectWarning(value="RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", num = 9) public static int testGuavaPrimitiveCompareCalls() { int count = 0; if (Booleans.compare(false, true) == -1) count++; if (Chars.compare('a', 'b') == -1) count++; if (Doubles.compare(1, 2) == -1) count++; if (Floats.compare(1, 2) == -1) count++; if (Ints.compare(1, 2) == -1) count++; if (Longs.compare(1, 2) == -1) count++; if (Shorts.compare((short) 1, (short) 2) == -1) count++; if (SignedBytes.compare((byte) 1, (byte) 2) == -1) count++; if (UnsignedBytes.compare((byte) 1, (byte) 2) == -1) count++; return count; }