Skip to content

Commit 97c96e0

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Address some PrimitiveComparisons warnings.
RELNOTES=n/a PiperOrigin-RevId: 746145356
1 parent 15a76d4 commit 97c96e0

File tree

18 files changed

+36
-38
lines changed

18 files changed

+36
-38
lines changed

android/guava-testlib/src/com/google/common/collect/testing/UnhashableObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ public String toString() {
5454

5555
@Override
5656
public int compareTo(UnhashableObject o) {
57-
return (this.value < o.value) ? -1 : (this.value > o.value) ? 1 : 0;
57+
return Integer.compare(this.value, o.value);
5858
}
5959
}

android/guava-tests/test/com/google/common/base/ObjectsTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@
3232
@NullUnmarked
3333
public class ObjectsTest extends TestCase {
3434

35-
@SuppressWarnings("YodaCondition") // test of reversed call
35+
@SuppressWarnings({
36+
"ObjectEqualsForPrimitives", // test of a trivial call
37+
"EqualsInteger", // test of a trivial call
38+
"EqualsLong", // b/273939864
39+
"EqualsDouble", // b/273939864
40+
"EqualsFloat", // b/273939864
41+
"YodaCondition", // test of reversed call
42+
})
3643
public void testEqual() throws Exception {
3744
assertTrue(Objects.equal(1, 1));
3845
assertTrue(Objects.equal(null, null));

android/guava-tests/test/com/google/common/primitives/CharsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testCompare() {
9999
for (char y : VALUES) {
100100
assertWithMessage(x + ", " + y)
101101
.that(Math.signum(Chars.compare(x, y)))
102-
.isEqualTo(Math.signum(Character.valueOf(x).compareTo(y)));
102+
.isEqualTo(Math.signum(Character.compare(x, y)));
103103
}
104104
}
105105
}

android/guava-tests/test/com/google/common/primitives/DoublesTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ public void testCompare() {
101101
for (double x : VALUES) {
102102
for (double y : VALUES) {
103103
// note: spec requires only that the sign is the same
104-
assertWithMessage(x + ", " + y)
105-
.that(Doubles.compare(x, y))
106-
.isEqualTo(Double.valueOf(x).compareTo(y));
104+
assertWithMessage(x + ", " + y).that(Doubles.compare(x, y)).isEqualTo(Double.compare(x, y));
107105
}
108106
}
109107
}

android/guava-tests/test/com/google/common/primitives/FloatsTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ public void testCompare() {
9696
for (float x : VALUES) {
9797
for (float y : VALUES) {
9898
// note: spec requires only that the sign is the same
99-
assertWithMessage(x + ", " + y)
100-
.that(Floats.compare(x, y))
101-
.isEqualTo(Float.valueOf(x).compareTo(y));
99+
assertWithMessage(x + ", " + y).that(Floats.compare(x, y)).isEqualTo(Float.compare(x, y));
102100
}
103101
}
104102
}

android/guava-tests/test/com/google/common/primitives/IntsTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ public void testCompare() {
100100
for (int x : VALUES) {
101101
for (int y : VALUES) {
102102
// note: spec requires only that the sign is the same
103-
assertWithMessage(x + ", " + y)
104-
.that(Ints.compare(x, y))
105-
.isEqualTo(Integer.valueOf(x).compareTo(y));
103+
assertWithMessage(x + ", " + y).that(Ints.compare(x, y)).isEqualTo(Integer.compare(x, y));
106104
}
107105
}
108106
}

android/guava-tests/test/com/google/common/primitives/LongsTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public void testCompare() {
7171
for (long x : VALUES) {
7272
for (long y : VALUES) {
7373
// note: spec requires only that the sign is the same
74-
assertWithMessage(x + ", " + y)
75-
.that(Longs.compare(x, y))
76-
.isEqualTo(Long.valueOf(x).compareTo(y));
74+
assertWithMessage(x + ", " + y).that(Longs.compare(x, y)).isEqualTo(Long.compare(x, y));
7775
}
7876
}
7977
}

android/guava-tests/test/com/google/common/primitives/ShortsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ private static void assertCastFails(long value) {
9898
public void testCompare() {
9999
for (short x : VALUES) {
100100
for (short y : VALUES) {
101-
// Only compare the sign of the result of compareTo().
102-
int expected = Short.valueOf(x).compareTo(y);
101+
// Only compare the sign of the result of compare().
102+
int expected = Short.compare(x, y);
103103
int actual = Shorts.compare(x, y);
104104
if (expected == 0) {
105105
assertWithMessage(x + ", " + y).that(actual).isEqualTo(expected);

android/guava-tests/test/com/google/common/primitives/SignedBytesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ private static void assertCastFails(long value) {
8484
public void testCompare() {
8585
for (byte x : VALUES) {
8686
for (byte y : VALUES) {
87-
// Only compare the sign of the result of compareTo().
88-
int expected = Byte.valueOf(x).compareTo(y);
87+
// Only compare the sign of the result of compare().
88+
int expected = Byte.compare(x, y);
8989
int actual = SignedBytes.compare(x, y);
9090
if (expected == 0) {
9191
assertWithMessage(x + ", " + y).that(actual).isEqualTo(expected);

guava-testlib/src/com/google/common/collect/testing/UnhashableObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ public String toString() {
5454

5555
@Override
5656
public int compareTo(UnhashableObject o) {
57-
return (this.value < o.value) ? -1 : (this.value > o.value) ? 1 : 0;
57+
return Integer.compare(this.value, o.value);
5858
}
5959
}

0 commit comments

Comments
 (0)