diff --git a/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java b/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java index dba1335df52c..a4f3b45e7582 100644 --- a/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java +++ b/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java @@ -33,7 +33,6 @@ import com.google.common.collect.MutableClassToInstanceMap; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; -import com.google.common.primitives.Ints; import com.google.common.reflect.Invokable; import com.google.common.reflect.Parameter; import com.google.common.reflect.Reflection; @@ -104,7 +103,7 @@ public int compare(Invokable left, Invokable right) { new Ordering>() { @Override public int compare(Invokable left, Invokable right) { - return Ints.compare(left.getParameters().size(), right.getParameters().size()); + return Integer.compare(left.getParameters().size(), right.getParameters().size()); } }; diff --git a/android/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java b/android/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java index e70572b046f5..068122588312 100644 --- a/android/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java +++ b/android/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java @@ -20,7 +20,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.Longs; import com.google.common.util.concurrent.AbstractFuture; import com.google.common.util.concurrent.AbstractListeningExecutorService; import com.google.common.util.concurrent.ListenableScheduledFuture; @@ -166,7 +165,7 @@ public long getDelay(TimeUnit unit) { @Override public int compareTo(Delayed other) { - return Longs.compare(getDelay(NANOSECONDS), other.getDelay(NANOSECONDS)); + return Long.compare(getDelay(NANOSECONDS), other.getDelay(NANOSECONDS)); } } } diff --git a/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java b/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java index 0504e6a745f6..550c237b7256 100644 --- a/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java +++ b/android/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.primitives.Ints; import java.util.Collections; import java.util.List; import java.util.Set; @@ -123,7 +122,7 @@ public int hashCode() { @Override public int compareTo(Element that) { - return Ints.compare(hash, that.hash); + return Integer.compare(hash, that.hash); } @Override diff --git a/android/guava-tests/test/com/google/common/collect/OrderingTest.java b/android/guava-tests/test/com/google/common/collect/OrderingTest.java index c4d0f316500c..d0d65662f5c3 100644 --- a/android/guava-tests/test/com/google/common/collect/OrderingTest.java +++ b/android/guava-tests/test/com/google/common/collect/OrderingTest.java @@ -31,7 +31,6 @@ import com.google.common.collect.Ordering.ArbitraryOrdering; import com.google.common.collect.Ordering.IncomparableValueException; import com.google.common.collect.testing.Helpers; -import com.google.common.primitives.Ints; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; import java.util.Arrays; @@ -209,6 +208,7 @@ public void testExplicit_sortingExample() { reserializeAndAssert(c); } + @SuppressWarnings("DistinctVarargsChecker") // test of buggy call public void testExplicit_withDuplicates() { try { Ordering.explicit(1, 2, 3, 4, 2); @@ -1143,7 +1143,7 @@ private static class Composite implements Comparable // order of 't'. @Override public int compareTo(Composite that) { - return Ints.compare(rank, that.rank); + return Integer.compare(rank, that.rank); } static Function, T> getValueFunction() { diff --git a/android/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java b/android/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java index 842d0b386983..6a4149ea6526 100644 --- a/android/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java +++ b/android/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java @@ -91,8 +91,8 @@ public void testCompare() { byte y = VALUES[j]; // note: spec requires only that the sign is the same assertWithMessage(x + ", " + y) - .that(Math.signum(Ints.compare(i, j))) - .isEqualTo(Math.signum(UnsignedBytes.compare(x, y))); + .that(Math.signum(UnsignedBytes.compare(x, y))) + .isEqualTo(Math.signum(Integer.compare(i, j))); } } } diff --git a/android/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java b/android/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java index d0988efd7f82..b527d9f6e86e 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java @@ -20,7 +20,6 @@ import com.google.common.base.CaseFormat; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.Ints; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -215,7 +214,7 @@ public int compare(Method m1, Method m2) { if (nameComparison != 0) { return nameComparison; } else { - return Ints.compare(m1.getParameterTypes().length, m2.getParameterTypes().length); + return Integer.compare(m1.getParameterTypes().length, m2.getParameterTypes().length); } } }); diff --git a/android/guava/src/com/google/common/collect/ComparisonChain.java b/android/guava/src/com/google/common/collect/ComparisonChain.java index 9c05205ec01d..ee4d8ddb4ec9 100644 --- a/android/guava/src/com/google/common/collect/ComparisonChain.java +++ b/android/guava/src/com/google/common/collect/ComparisonChain.java @@ -17,9 +17,6 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; -import com.google.common.primitives.Booleans; -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; import java.util.Comparator; import org.checkerframework.checker.nullness.qual.Nullable; @@ -82,12 +79,12 @@ public ComparisonChain compare(Comparable left, Comparable right) { @Override public ComparisonChain compare(int left, int right) { - return classify(Ints.compare(left, right)); + return classify(Integer.compare(left, right)); } @Override public ComparisonChain compare(long left, long right) { - return classify(Longs.compare(left, right)); + return classify(Long.compare(left, right)); } @Override @@ -102,12 +99,12 @@ public ComparisonChain compare(double left, double right) { @Override public ComparisonChain compareTrueFirst(boolean left, boolean right) { - return classify(Booleans.compare(right, left)); // reversed + return classify(Boolean.compare(right, left)); // reversed } @Override public ComparisonChain compareFalseFirst(boolean left, boolean right) { - return classify(Booleans.compare(left, right)); + return classify(Boolean.compare(left, right)); } ComparisonChain classify(int result) { @@ -204,13 +201,13 @@ public int result() { @ParametricNullness T left, @ParametricNullness T right, Comparator comparator); /** - * Compares two {@code int} values as specified by {@link Ints#compare}, if the result of - * this comparison chain has not already been determined. + * Compares two {@code int} values as specified by {@link Integer#compare}, if the result + * of this comparison chain has not already been determined. */ public abstract ComparisonChain compare(int left, int right); /** - * Compares two {@code long} values as specified by {@link Longs#compare}, if the result of + * Compares two {@code long} values as specified by {@link Long#compare}, if the result of * this comparison chain has not already been determined. */ public abstract ComparisonChain compare(long left, long right); diff --git a/android/guava/src/com/google/common/collect/Cut.java b/android/guava/src/com/google/common/collect/Cut.java index 3231d29dafc8..7de1a44f7e36 100644 --- a/android/guava/src/com/google/common/collect/Cut.java +++ b/android/guava/src/com/google/common/collect/Cut.java @@ -17,7 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; -import com.google.common.primitives.Booleans; import java.io.Serializable; import java.util.NoSuchElementException; import javax.annotation.CheckForNull; @@ -83,7 +82,7 @@ public int compareTo(Cut that) { return result; } // same value. below comes before above - return Booleans.compare(this instanceof AboveValue, that instanceof AboveValue); + return Boolean.compare(this instanceof AboveValue, that instanceof AboveValue); } C endpoint() { diff --git a/android/guava/src/com/google/common/math/DoubleMath.java b/android/guava/src/com/google/common/math/DoubleMath.java index 61f768bd9179..be0d8cfc9e0d 100644 --- a/android/guava/src/com/google/common/math/DoubleMath.java +++ b/android/guava/src/com/google/common/math/DoubleMath.java @@ -33,7 +33,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.VisibleForTesting; -import com.google.common.primitives.Booleans; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.math.BigInteger; import java.math.RoundingMode; @@ -393,7 +392,7 @@ public static int fuzzyCompare(double a, double b, double tolerance) { } else if (a > b) { return 1; } else { - return Booleans.compare(Double.isNaN(a), Double.isNaN(b)); + return Boolean.compare(Double.isNaN(a), Double.isNaN(b)); } } diff --git a/android/guava/src/com/google/common/math/LongMath.java b/android/guava/src/com/google/common/math/LongMath.java index 9c5b0e750396..6de6aacf897d 100644 --- a/android/guava/src/com/google/common/math/LongMath.java +++ b/android/guava/src/com/google/common/math/LongMath.java @@ -28,7 +28,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.VisibleForTesting; -import com.google.common.primitives.Longs; import com.google.common.primitives.UnsignedLongs; import java.math.BigInteger; import java.math.RoundingMode; @@ -1255,7 +1254,7 @@ public static double roundToDouble(long x, RoundingMode mode) { if (roundArbitrarilyAsLong == Long.MAX_VALUE) { /* * For most values, the conversion from roundArbitrarily to roundArbitrarilyAsLong is - * lossless. In that case we can compare x to roundArbitrarily using Longs.compare(x, + * lossless. In that case we can compare x to roundArbitrarily using Long.compare(x, * roundArbitrarilyAsLong). The exception is for values where the conversion to double rounds * up to give roundArbitrarily equal to 2^63, so the conversion back to long overflows and * roundArbitrarilyAsLong is Long.MAX_VALUE. (This is the only way this condition can occur as @@ -1265,7 +1264,7 @@ public static double roundToDouble(long x, RoundingMode mode) { */ cmpXToRoundArbitrarily = -1; } else { - cmpXToRoundArbitrarily = Longs.compare(x, roundArbitrarilyAsLong); + cmpXToRoundArbitrarily = Long.compare(x, roundArbitrarilyAsLong); } switch (mode) { @@ -1324,7 +1323,7 @@ public static double roundToDouble(long x, RoundingMode mode) { deltaToCeiling++; } - int diff = Longs.compare(deltaToFloor, deltaToCeiling); + int diff = Long.compare(deltaToFloor, deltaToCeiling); if (diff < 0) { // closer to floor return roundFloorAsDouble; } else if (diff > 0) { // closer to ceiling diff --git a/android/guava/src/com/google/common/primitives/Booleans.java b/android/guava/src/com/google/common/primitives/Booleans.java index d924ba1de42c..81a85adc6c25 100644 --- a/android/guava/src/com/google/common/primitives/Booleans.java +++ b/android/guava/src/com/google/common/primitives/Booleans.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkPositionIndexes; import com.google.common.annotations.GwtCompatible; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -121,8 +122,9 @@ public static int hashCode(boolean value) { * @return a positive number if only {@code a} is {@code true}, a negative number if only {@code * b} is true, or zero if {@code a == b} */ + @InlineMe(replacement = "Boolean.compare(a, b)") public static int compare(boolean a, boolean b) { - return (a == b) ? 0 : (a ? 1 : -1); + return Boolean.compare(a, b); } /** @@ -310,7 +312,7 @@ private enum LexicographicalComparator implements Comparator { 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]); + int result = Boolean.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/android/guava/src/com/google/common/primitives/Chars.java b/android/guava/src/com/google/common/primitives/Chars.java index 7a558adf4654..9b91cdadc070 100644 --- a/android/guava/src/com/google/common/primitives/Chars.java +++ b/android/guava/src/com/google/common/primitives/Chars.java @@ -21,6 +21,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -113,8 +114,9 @@ public static char saturatedCast(long value) { * @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 */ + @InlineMe(replacement = "Character.compare(a, b)") public static int compare(char a, char b) { - return a - b; // safe due to restricted range + return Character.compare(a, b); } /** @@ -391,7 +393,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(char[] left, char[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Chars.compare(left[i], right[i]); + int result = Character.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/android/guava/src/com/google/common/primitives/Ints.java b/android/guava/src/com/google/common/primitives/Ints.java index b3423d5b29e1..c0b1ff28079f 100644 --- a/android/guava/src/com/google/common/primitives/Ints.java +++ b/android/guava/src/com/google/common/primitives/Ints.java @@ -22,6 +22,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Converter; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -118,8 +119,9 @@ public static int saturatedCast(long value) { * @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 */ + @InlineMe(replacement = "Integer.compare(a, b)") public static int compare(int a, int b) { - return (a < b) ? -1 : ((a > b) ? 1 : 0); + return Integer.compare(a, b); } /** @@ -439,7 +441,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Ints.compare(left[i], right[i]); + int result = Integer.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/android/guava/src/com/google/common/primitives/Longs.java b/android/guava/src/com/google/common/primitives/Longs.java index 45e22da2949f..f481ef77da57 100644 --- a/android/guava/src/com/google/common/primitives/Longs.java +++ b/android/guava/src/com/google/common/primitives/Longs.java @@ -21,6 +21,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Converter; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -89,8 +90,9 @@ public static int hashCode(long value) { * @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 */ + @InlineMe(replacement = "Long.compare(a, b)") public static int compare(long a, long b) { - return (a < b) ? -1 : ((a > b) ? 1 : 0); + return Long.compare(a, b); } /** @@ -543,7 +545,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(long[] left, long[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Longs.compare(left[i], right[i]); + int result = Long.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/android/guava/src/com/google/common/primitives/Shorts.java b/android/guava/src/com/google/common/primitives/Shorts.java index 18be90760fb2..fef9a0d9fad0 100644 --- a/android/guava/src/com/google/common/primitives/Shorts.java +++ b/android/guava/src/com/google/common/primitives/Shorts.java @@ -22,6 +22,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Converter; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -117,8 +118,9 @@ public static short saturatedCast(long value) { * @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 */ + @InlineMe(replacement = "Short.compare(a, b)") public static int compare(short a, short b) { - return a - b; // safe due to restricted range + return Short.compare(a, b); } /** @@ -441,7 +443,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(short[] left, short[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Shorts.compare(left[i], right[i]); + int result = Short.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/android/guava/src/com/google/common/primitives/SignedBytes.java b/android/guava/src/com/google/common/primitives/SignedBytes.java index 5fabaab6bd93..667bb04d6321 100644 --- a/android/guava/src/com/google/common/primitives/SignedBytes.java +++ b/android/guava/src/com/google/common/primitives/SignedBytes.java @@ -89,10 +89,8 @@ public static byte saturatedCast(long value) { * @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 */ - // TODO(kevinb): if Ints.compare etc. are ever removed, *maybe* remove this - // one too, which would leave compare methods only on the Unsigned* classes. public static int compare(byte a, byte b) { - return a - b; // safe due to restricted range + return Byte.compare(a, b); } /** @@ -181,7 +179,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(byte[] left, byte[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = SignedBytes.compare(left[i], right[i]); + int result = Byte.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/android/guava/src/com/google/common/primitives/UnsignedBytes.java b/android/guava/src/com/google/common/primitives/UnsignedBytes.java index 75e0266047a0..25410827e438 100644 --- a/android/guava/src/com/google/common/primitives/UnsignedBytes.java +++ b/android/guava/src/com/google/common/primitives/UnsignedBytes.java @@ -366,6 +366,8 @@ public Unsafe run() throws Exception { } @Override + // Long.compareUnsigned is available under Android, which is what we really care about. + @SuppressWarnings("Java7ApiChecker") public int compare(byte[] left, byte[] right) { int stride = 8; int minLength = Math.min(left.length, right.length); @@ -381,7 +383,7 @@ public int compare(byte[] left, byte[] right) { long rw = theUnsafe.getLong(right, BYTE_ARRAY_BASE_OFFSET + (long) i); if (lw != rw) { if (BIG_ENDIAN) { - return UnsignedLongs.compare(lw, rw); + return Long.compareUnsigned(lw, rw); } /* diff --git a/guava-testlib/src/com/google/common/testing/ClassSanityTester.java b/guava-testlib/src/com/google/common/testing/ClassSanityTester.java index 3ed1fc08d14e..12933eaeaee7 100644 --- a/guava-testlib/src/com/google/common/testing/ClassSanityTester.java +++ b/guava-testlib/src/com/google/common/testing/ClassSanityTester.java @@ -33,7 +33,6 @@ import com.google.common.collect.MutableClassToInstanceMap; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; -import com.google.common.primitives.Ints; import com.google.common.reflect.Invokable; import com.google.common.reflect.Parameter; import com.google.common.reflect.Reflection; @@ -104,7 +103,7 @@ public int compare(Invokable left, Invokable right) { new Ordering>() { @Override public int compare(Invokable left, Invokable right) { - return Ints.compare(left.getParameters().size(), right.getParameters().size()); + return Integer.compare(left.getParameters().size(), right.getParameters().size()); } }; diff --git a/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java b/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java index e70572b046f5..068122588312 100644 --- a/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java +++ b/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java @@ -20,7 +20,6 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.Longs; import com.google.common.util.concurrent.AbstractFuture; import com.google.common.util.concurrent.AbstractListeningExecutorService; import com.google.common.util.concurrent.ListenableScheduledFuture; @@ -166,7 +165,7 @@ public long getDelay(TimeUnit unit) { @Override public int compareTo(Delayed other) { - return Longs.compare(getDelay(NANOSECONDS), other.getDelay(NANOSECONDS)); + return Long.compare(getDelay(NANOSECONDS), other.getDelay(NANOSECONDS)); } } } diff --git a/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java b/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java index 0504e6a745f6..550c237b7256 100644 --- a/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java +++ b/guava-tests/test/com/google/common/collect/CollectionBenchmarkSampleData.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.primitives.Ints; import java.util.Collections; import java.util.List; import java.util.Set; @@ -123,7 +122,7 @@ public int hashCode() { @Override public int compareTo(Element that) { - return Ints.compare(hash, that.hash); + return Integer.compare(hash, that.hash); } @Override diff --git a/guava-tests/test/com/google/common/collect/OrderingTest.java b/guava-tests/test/com/google/common/collect/OrderingTest.java index c4d0f316500c..d0d65662f5c3 100644 --- a/guava-tests/test/com/google/common/collect/OrderingTest.java +++ b/guava-tests/test/com/google/common/collect/OrderingTest.java @@ -31,7 +31,6 @@ import com.google.common.collect.Ordering.ArbitraryOrdering; import com.google.common.collect.Ordering.IncomparableValueException; import com.google.common.collect.testing.Helpers; -import com.google.common.primitives.Ints; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; import java.util.Arrays; @@ -209,6 +208,7 @@ public void testExplicit_sortingExample() { reserializeAndAssert(c); } + @SuppressWarnings("DistinctVarargsChecker") // test of buggy call public void testExplicit_withDuplicates() { try { Ordering.explicit(1, 2, 3, 4, 2); @@ -1143,7 +1143,7 @@ private static class Composite implements Comparable // order of 't'. @Override public int compareTo(Composite that) { - return Ints.compare(rank, that.rank); + return Integer.compare(rank, that.rank); } static Function, T> getValueFunction() { diff --git a/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java b/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java index 842d0b386983..6a4149ea6526 100644 --- a/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java +++ b/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java @@ -91,8 +91,8 @@ public void testCompare() { byte y = VALUES[j]; // note: spec requires only that the sign is the same assertWithMessage(x + ", " + y) - .that(Math.signum(Ints.compare(i, j))) - .isEqualTo(Math.signum(UnsignedBytes.compare(x, y))); + .that(Math.signum(UnsignedBytes.compare(x, y))) + .isEqualTo(Math.signum(Integer.compare(i, j))); } } } diff --git a/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java b/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java index 458d6e0a7e43..5276b189fafe 100644 --- a/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java @@ -20,7 +20,6 @@ import com.google.common.base.CaseFormat; import com.google.common.collect.ImmutableList; -import com.google.common.primitives.Ints; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -230,7 +229,7 @@ public int compare(Method m1, Method m2) { if (nameComparison != 0) { return nameComparison; } else { - return Ints.compare(m1.getParameterTypes().length, m2.getParameterTypes().length); + return Integer.compare(m1.getParameterTypes().length, m2.getParameterTypes().length); } } }); diff --git a/guava/src/com/google/common/collect/ComparisonChain.java b/guava/src/com/google/common/collect/ComparisonChain.java index 79b7c6cc8906..f8cd62cf81d1 100644 --- a/guava/src/com/google/common/collect/ComparisonChain.java +++ b/guava/src/com/google/common/collect/ComparisonChain.java @@ -18,8 +18,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.primitives.Booleans; -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; import java.util.Comparator; import org.checkerframework.checker.nullness.qual.Nullable; @@ -116,12 +114,12 @@ public ComparisonChain compare(Comparable left, Comparable right) { @Override public ComparisonChain compare(int left, int right) { - return classify(Ints.compare(left, right)); + return classify(Integer.compare(left, right)); } @Override public ComparisonChain compare(long left, long right) { - return classify(Longs.compare(left, right)); + return classify(Long.compare(left, right)); } @Override @@ -136,12 +134,12 @@ public ComparisonChain compare(double left, double right) { @Override public ComparisonChain compareTrueFirst(boolean left, boolean right) { - return classify(Booleans.compare(right, left)); // reversed + return classify(Boolean.compare(right, left)); // reversed } @Override public ComparisonChain compareFalseFirst(boolean left, boolean right) { - return classify(Booleans.compare(left, right)); + return classify(Boolean.compare(left, right)); } ComparisonChain classify(int result) { @@ -238,13 +236,13 @@ public int result() { @ParametricNullness T left, @ParametricNullness T right, Comparator comparator); /** - * Compares two {@code int} values as specified by {@link Ints#compare}, if the result of - * this comparison chain has not already been determined. + * Compares two {@code int} values as specified by {@link Integer#compare}, if the result + * of this comparison chain has not already been determined. */ public abstract ComparisonChain compare(int left, int right); /** - * Compares two {@code long} values as specified by {@link Longs#compare}, if the result of + * Compares two {@code long} values as specified by {@link Long#compare}, if the result of * this comparison chain has not already been determined. */ public abstract ComparisonChain compare(long left, long right); diff --git a/guava/src/com/google/common/collect/Cut.java b/guava/src/com/google/common/collect/Cut.java index 3231d29dafc8..7de1a44f7e36 100644 --- a/guava/src/com/google/common/collect/Cut.java +++ b/guava/src/com/google/common/collect/Cut.java @@ -17,7 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; -import com.google.common.primitives.Booleans; import java.io.Serializable; import java.util.NoSuchElementException; import javax.annotation.CheckForNull; @@ -83,7 +82,7 @@ public int compareTo(Cut that) { return result; } // same value. below comes before above - return Booleans.compare(this instanceof AboveValue, that instanceof AboveValue); + return Boolean.compare(this instanceof AboveValue, that instanceof AboveValue); } C endpoint() { diff --git a/guava/src/com/google/common/math/DoubleMath.java b/guava/src/com/google/common/math/DoubleMath.java index 61f768bd9179..be0d8cfc9e0d 100644 --- a/guava/src/com/google/common/math/DoubleMath.java +++ b/guava/src/com/google/common/math/DoubleMath.java @@ -33,7 +33,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.VisibleForTesting; -import com.google.common.primitives.Booleans; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.math.BigInteger; import java.math.RoundingMode; @@ -393,7 +392,7 @@ public static int fuzzyCompare(double a, double b, double tolerance) { } else if (a > b) { return 1; } else { - return Booleans.compare(Double.isNaN(a), Double.isNaN(b)); + return Boolean.compare(Double.isNaN(a), Double.isNaN(b)); } } diff --git a/guava/src/com/google/common/math/LongMath.java b/guava/src/com/google/common/math/LongMath.java index 9c5b0e750396..6de6aacf897d 100644 --- a/guava/src/com/google/common/math/LongMath.java +++ b/guava/src/com/google/common/math/LongMath.java @@ -28,7 +28,6 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.VisibleForTesting; -import com.google.common.primitives.Longs; import com.google.common.primitives.UnsignedLongs; import java.math.BigInteger; import java.math.RoundingMode; @@ -1255,7 +1254,7 @@ public static double roundToDouble(long x, RoundingMode mode) { if (roundArbitrarilyAsLong == Long.MAX_VALUE) { /* * For most values, the conversion from roundArbitrarily to roundArbitrarilyAsLong is - * lossless. In that case we can compare x to roundArbitrarily using Longs.compare(x, + * lossless. In that case we can compare x to roundArbitrarily using Long.compare(x, * roundArbitrarilyAsLong). The exception is for values where the conversion to double rounds * up to give roundArbitrarily equal to 2^63, so the conversion back to long overflows and * roundArbitrarilyAsLong is Long.MAX_VALUE. (This is the only way this condition can occur as @@ -1265,7 +1264,7 @@ public static double roundToDouble(long x, RoundingMode mode) { */ cmpXToRoundArbitrarily = -1; } else { - cmpXToRoundArbitrarily = Longs.compare(x, roundArbitrarilyAsLong); + cmpXToRoundArbitrarily = Long.compare(x, roundArbitrarilyAsLong); } switch (mode) { @@ -1324,7 +1323,7 @@ public static double roundToDouble(long x, RoundingMode mode) { deltaToCeiling++; } - int diff = Longs.compare(deltaToFloor, deltaToCeiling); + int diff = Long.compare(deltaToFloor, deltaToCeiling); if (diff < 0) { // closer to floor return roundFloorAsDouble; } else if (diff > 0) { // closer to ceiling diff --git a/guava/src/com/google/common/primitives/Booleans.java b/guava/src/com/google/common/primitives/Booleans.java index d924ba1de42c..81a85adc6c25 100644 --- a/guava/src/com/google/common/primitives/Booleans.java +++ b/guava/src/com/google/common/primitives/Booleans.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkPositionIndexes; import com.google.common.annotations.GwtCompatible; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -121,8 +122,9 @@ public static int hashCode(boolean value) { * @return a positive number if only {@code a} is {@code true}, a negative number if only {@code * b} is true, or zero if {@code a == b} */ + @InlineMe(replacement = "Boolean.compare(a, b)") public static int compare(boolean a, boolean b) { - return (a == b) ? 0 : (a ? 1 : -1); + return Boolean.compare(a, b); } /** @@ -310,7 +312,7 @@ private enum LexicographicalComparator implements Comparator { 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]); + int result = Boolean.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/guava/src/com/google/common/primitives/Chars.java b/guava/src/com/google/common/primitives/Chars.java index 7a558adf4654..9b91cdadc070 100644 --- a/guava/src/com/google/common/primitives/Chars.java +++ b/guava/src/com/google/common/primitives/Chars.java @@ -21,6 +21,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -113,8 +114,9 @@ public static char saturatedCast(long value) { * @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 */ + @InlineMe(replacement = "Character.compare(a, b)") public static int compare(char a, char b) { - return a - b; // safe due to restricted range + return Character.compare(a, b); } /** @@ -391,7 +393,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(char[] left, char[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Chars.compare(left[i], right[i]); + int result = Character.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/guava/src/com/google/common/primitives/Ints.java b/guava/src/com/google/common/primitives/Ints.java index 6eaec960214e..02b520cc0f40 100644 --- a/guava/src/com/google/common/primitives/Ints.java +++ b/guava/src/com/google/common/primitives/Ints.java @@ -22,6 +22,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Converter; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -120,8 +121,9 @@ public static int saturatedCast(long value) { * @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 */ + @InlineMe(replacement = "Integer.compare(a, b)") public static int compare(int a, int b) { - return (a < b) ? -1 : ((a > b) ? 1 : 0); + return Integer.compare(a, b); } /** @@ -441,7 +443,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Ints.compare(left[i], right[i]); + int result = Integer.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/guava/src/com/google/common/primitives/Longs.java b/guava/src/com/google/common/primitives/Longs.java index 0cfb465df14a..f457fce6b1cf 100644 --- a/guava/src/com/google/common/primitives/Longs.java +++ b/guava/src/com/google/common/primitives/Longs.java @@ -21,6 +21,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Converter; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -91,8 +92,9 @@ public static int hashCode(long value) { * @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 */ + @InlineMe(replacement = "Long.compare(a, b)") public static int compare(long a, long b) { - return (a < b) ? -1 : ((a > b) ? 1 : 0); + return Long.compare(a, b); } /** @@ -545,7 +547,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(long[] left, long[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Longs.compare(left[i], right[i]); + int result = Long.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/guava/src/com/google/common/primitives/Shorts.java b/guava/src/com/google/common/primitives/Shorts.java index 18be90760fb2..fef9a0d9fad0 100644 --- a/guava/src/com/google/common/primitives/Shorts.java +++ b/guava/src/com/google/common/primitives/Shorts.java @@ -22,6 +22,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Converter; +import com.google.errorprone.annotations.InlineMe; import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; @@ -117,8 +118,9 @@ public static short saturatedCast(long value) { * @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 */ + @InlineMe(replacement = "Short.compare(a, b)") public static int compare(short a, short b) { - return a - b; // safe due to restricted range + return Short.compare(a, b); } /** @@ -441,7 +443,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(short[] left, short[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = Shorts.compare(left[i], right[i]); + int result = Short.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/guava/src/com/google/common/primitives/SignedBytes.java b/guava/src/com/google/common/primitives/SignedBytes.java index 5fabaab6bd93..667bb04d6321 100644 --- a/guava/src/com/google/common/primitives/SignedBytes.java +++ b/guava/src/com/google/common/primitives/SignedBytes.java @@ -89,10 +89,8 @@ public static byte saturatedCast(long value) { * @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 */ - // TODO(kevinb): if Ints.compare etc. are ever removed, *maybe* remove this - // one too, which would leave compare methods only on the Unsigned* classes. public static int compare(byte a, byte b) { - return a - b; // safe due to restricted range + return Byte.compare(a, b); } /** @@ -181,7 +179,7 @@ private enum LexicographicalComparator implements Comparator { public int compare(byte[] left, byte[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { - int result = SignedBytes.compare(left[i], right[i]); + int result = Byte.compare(left[i], right[i]); if (result != 0) { return result; } diff --git a/guava/src/com/google/common/primitives/UnsignedBytes.java b/guava/src/com/google/common/primitives/UnsignedBytes.java index 75e0266047a0..25410827e438 100644 --- a/guava/src/com/google/common/primitives/UnsignedBytes.java +++ b/guava/src/com/google/common/primitives/UnsignedBytes.java @@ -366,6 +366,8 @@ public Unsafe run() throws Exception { } @Override + // Long.compareUnsigned is available under Android, which is what we really care about. + @SuppressWarnings("Java7ApiChecker") public int compare(byte[] left, byte[] right) { int stride = 8; int minLength = Math.min(left.length, right.length); @@ -381,7 +383,7 @@ public int compare(byte[] left, byte[] right) { long rw = theUnsafe.getLong(right, BYTE_ARRAY_BASE_OFFSET + (long) i); if (lw != rw) { if (BIG_ENDIAN) { - return UnsignedLongs.compare(lw, rw); + return Long.compareUnsigned(lw, rw); } /*