[cscore, wpilibj] Use pattern matching in equals overrides (#7003)

Fixes https://errorprone.info/bugpattern/EqualsGetClass
This commit is contained in:
David Vo
2024-08-24 23:48:20 +10:00
committed by GitHub
parent 173ffca14a
commit 36ff22a439
5 changed files with 12 additions and 21 deletions

View File

@@ -117,12 +117,12 @@ public class Color {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
if (other == null) {
return false;
}
Color color = (Color) other;
return Double.compare(color.red, red) == 0
return other instanceof Color color
&& Double.compare(color.red, red) == 0
&& Double.compare(color.green, green) == 0
&& Double.compare(color.blue, blue) == 0;
}

View File

@@ -69,12 +69,14 @@ public class Color8Bit {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
if (other == null) {
return false;
}
Color8Bit color8Bit = (Color8Bit) other;
return red == color8Bit.red && green == color8Bit.green && blue == color8Bit.blue;
return other instanceof Color8Bit color8Bit
&& red == color8Bit.red
&& green == color8Bit.green
&& blue == color8Bit.blue;
}
@Override