From a274e297cd8138e280713a6623f06d9baa697db4 Mon Sep 17 00:00:00 2001 From: David Vo Date: Sat, 20 Jan 2024 15:46:38 +1100 Subject: [PATCH] Fix trivial errorprone warnings (NFC) (#6135) --- .../generate/main/java/NetworkTableEntry.java.jinja | 2 +- .../wpi/first/networktables/NetworkTableEntry.java | 2 +- .../edu/wpi/first/networktables/NetworkTable.java | 2 +- .../java/edu/wpi/first/wpilibj/ADIS16448_IMU.java | 2 +- .../java/edu/wpi/first/wpilibj/ADIS16470_IMU.java | 6 +++--- .../src/main/java/edu/wpi/first/wpilibj/Servo.java | 2 +- .../wpi/first/wpilibj/drive/DifferentialDrive.java | 4 ++-- .../edu/wpi/first/wpilibj/drive/MecanumDrive.java | 11 ++++------- .../main/java/edu/wpi/first/math/StateSpaceUtil.java | 2 +- .../ControlAffinePlantInversionFeedforward.java | 2 +- .../math/estimator/SteadyStateKalmanFilter.java | 2 +- .../edu/wpi/first/math/path/TravelingSalesman.java | 2 +- .../java/edu/wpi/first/math/system/LinearSystem.java | 2 +- .../edu/wpi/first/math/system/LinearSystemLoop.java | 2 +- .../controller/LinearQuadraticRegulatorTest.java | 12 ++++++------ .../math/controller/SimpleMotorFeedforwardTest.java | 2 +- .../edu/wpi/first/math/geometry/QuaternionTest.java | 2 +- wpiunits/src/main/java/edu/wpi/first/units/Mult.java | 2 +- wpiunits/src/main/java/edu/wpi/first/units/Per.java | 2 +- .../src/main/java/edu/wpi/first/units/Velocity.java | 2 +- .../test/java/edu/wpi/first/units/MeasureTest.java | 2 +- .../wpi/first/util/struct/StructFieldDescriptor.java | 2 +- 22 files changed, 33 insertions(+), 36 deletions(-) diff --git a/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja b/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja index 2c2c7373a8c..fa3a72a949a 100644 --- a/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableEntry.java.jinja @@ -608,6 +608,6 @@ public final class NetworkTableEntry implements Publisher, Subscriber { } private final Topic m_topic; - protected int m_handle; + private final int m_handle; } diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java index 69d107753a0..bec010bf238 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java @@ -1009,5 +1009,5 @@ public int hashCode() { } private final Topic m_topic; - protected int m_handle; + private final int m_handle; } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java index c88ce8b3c87..a9768ff7e89 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java @@ -330,7 +330,7 @@ public NetworkTable getSubTable(String key) { * @return true if the table as a value assigned to the given key */ public boolean containsKey(String key) { - return !("".equals(key)) && getTopic(key).exists(); + return !"".equals(key) && getTopic(key).exists(); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java index 0b55105c233..93260c0f2d2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java @@ -383,7 +383,7 @@ private static long toULong(int sint) { /** */ private static int toShort(int... buf) { - return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF))); + return (short) (((buf[0] & 0xFF) << 8) + (buf[1] & 0xFF)); } /** */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java index 67a5beca86a..23b6538c3c7 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java @@ -453,7 +453,7 @@ public boolean isConnected() { * @return */ private static int toUShort(ByteBuffer buf) { - return (buf.getShort(0)) & 0xFFFF; + return buf.getShort(0) & 0xFFFF; } /** @@ -469,7 +469,7 @@ private static long toULong(int sint) { * @return */ private static int toShort(int... buf) { - return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF))); + return (short) (((buf[0] & 0xFF) << 8) + (buf[1] & 0xFF)); } /** @@ -693,7 +693,7 @@ private int readRegister(int reg) { private void writeRegister(int reg, int val) { ByteBuffer buf = ByteBuffer.allocateDirect(2); // low byte - buf.put(0, (byte) ((0x80 | reg))); + buf.put(0, (byte) (0x80 | reg)); buf.put(1, (byte) (val & 0xff)); m_spi.write(buf, 2); // high byte diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Servo.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Servo.java index ebd2a8bb6c4..6ba3ed7d57a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Servo.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Servo.java @@ -84,7 +84,7 @@ public void setAngle(double degrees) { degrees = kMaxServoAngle; } - setPosition(((degrees - kMinServoAngle)) / getServoAngleRange()); + setPosition((degrees - kMinServoAngle) / getServoAngleRange()); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java index 171a44a2467..40e34a803da 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java @@ -368,7 +368,7 @@ public void initSendable(SendableBuilder builder) { builder.setSmartDashboardType("DifferentialDrive"); builder.setActuator(true); builder.setSafeState(this::stopMotor); - builder.addDoubleProperty("Left Motor Speed", () -> m_leftOutput, m_leftMotor::accept); - builder.addDoubleProperty("Right Motor Speed", () -> m_rightOutput, m_rightMotor::accept); + builder.addDoubleProperty("Left Motor Speed", () -> m_leftOutput, m_leftMotor); + builder.addDoubleProperty("Right Motor Speed", () -> m_rightOutput, m_rightMotor); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java index 236a4fbe93f..507e3719c81 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java @@ -321,13 +321,10 @@ public void initSendable(SendableBuilder builder) { builder.setSmartDashboardType("MecanumDrive"); builder.setActuator(true); builder.setSafeState(this::stopMotor); + builder.addDoubleProperty("Front Left Motor Speed", () -> m_frontLeftOutput, m_frontLeftMotor); builder.addDoubleProperty( - "Front Left Motor Speed", () -> m_frontLeftOutput, m_frontLeftMotor::accept); - builder.addDoubleProperty( - "Front Right Motor Speed", () -> m_frontRightOutput, m_frontRightMotor::accept); - builder.addDoubleProperty( - "Rear Left Motor Speed", () -> m_rearLeftOutput, m_rearLeftMotor::accept); - builder.addDoubleProperty( - "Rear Right Motor Speed", () -> m_rearRightOutput, m_rearRightMotor::accept); + "Front Right Motor Speed", () -> m_frontRightOutput, m_frontRightMotor); + builder.addDoubleProperty("Rear Left Motor Speed", () -> m_rearLeftOutput, m_rearLeftMotor); + builder.addDoubleProperty("Rear Right Motor Speed", () -> m_rearRightOutput, m_rearRightMotor); } } diff --git a/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java b/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java index 525d5ef1beb..4e003747693 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java +++ b/wpimath/src/main/java/edu/wpi/first/math/StateSpaceUtil.java @@ -80,7 +80,7 @@ public static Matrix makeCostMatrix( if (tolerances.get(i, 0) == Double.POSITIVE_INFINITY) { result.set(i, i, 0.0); } else { - result.set(i, i, 1.0 / (Math.pow(tolerances.get(i, 0), 2))); + result.set(i, i, 1.0 / Math.pow(tolerances.get(i, 0), 2)); } } diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java index 04865009304..9b14542207f 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java @@ -181,7 +181,7 @@ public Matrix calculate(Matrix nextR) { * @return The calculated feedforward. */ public Matrix calculate(Matrix r, Matrix nextR) { - var rDot = (nextR.minus(r)).div(m_dt); + var rDot = nextR.minus(r).div(m_dt); // ṙ = f(r) + Bu // Bu = ṙ − f(r) diff --git a/wpimath/src/main/java/edu/wpi/first/math/estimator/SteadyStateKalmanFilter.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/SteadyStateKalmanFilter.java index 0f2e4a5e5e3..e29032d7cba 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/estimator/SteadyStateKalmanFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/SteadyStateKalmanFilter.java @@ -114,7 +114,7 @@ public SteadyStateKalmanFilter( // K = (Sᵀ.solve(CPᵀ))ᵀ m_K = new Matrix<>( - S.transpose().getStorage().solve((C.times(P.transpose())).getStorage()).transpose()); + S.transpose().getStorage().solve(C.times(P.transpose()).getStorage()).transpose()); reset(); } diff --git a/wpimath/src/main/java/edu/wpi/first/math/path/TravelingSalesman.java b/wpimath/src/main/java/edu/wpi/first/math/path/TravelingSalesman.java index 83dd93ef0bc..b81db2036bc 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/path/TravelingSalesman.java +++ b/wpimath/src/main/java/edu/wpi/first/math/path/TravelingSalesman.java @@ -62,7 +62,7 @@ public Pose2d[] solve(Pose2d[] poses, int iterations) { sum += m_cost.applyAsDouble( poses[(int) state.get(i, 0)], - poses[(int) (state.get((i + 1) % poses.length, 0))]); + poses[(int) state.get((i + 1) % poses.length, 0)]); } return sum; }); diff --git a/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystem.java b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystem.java index 18deaa97fcd..703498fe527 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystem.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystem.java @@ -180,7 +180,7 @@ public Matrix calculateX( Matrix x, Matrix clampedU, double dtSeconds) { var discABpair = Discretization.discretizeAB(m_A, m_B, dtSeconds); - return (discABpair.getFirst().times(x)).plus(discABpair.getSecond().times(clampedU)); + return discABpair.getFirst().times(x).plus(discABpair.getSecond().times(clampedU)); } /** diff --git a/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystemLoop.java b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystemLoop.java index 94017fc0bb2..78cace9a21d 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystemLoop.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystemLoop.java @@ -292,7 +292,7 @@ public Matrix getError() { * @return The error at that index. */ public double getError(int index) { - return (getController().getR().minus(m_observer.getXhat())).get(index, 0); + return getController().getR().minus(m_observer.getXhat()).get(index, 0); } /** diff --git a/wpimath/src/test/java/edu/wpi/first/math/controller/LinearQuadraticRegulatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearQuadraticRegulatorTest.java index e915388cd3d..48278ced6e3 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/controller/LinearQuadraticRegulatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearQuadraticRegulatorTest.java @@ -78,8 +78,8 @@ void testLQROnArm() { * *

This is used to test the QRN overload of LQR. * - * @param States Number of states. - * @param Inputs Number of inputs. + * @param Number of states. + * @param Number of inputs. * @param A State matrix. * @param B Input matrix. * @param Q State cost matrix. @@ -119,10 +119,10 @@ void testMatrixOverloadsWithSingleIntegrator() { // QR overload var K = new LinearQuadraticRegulator<>(A, B, Q, R, 0.005).getK(); - assertEquals(0.99750312499512261, K.get(0, 0), 1e-10); + assertEquals(0.9975031249951226, K.get(0, 0), 1e-10); assertEquals(0.0, K.get(0, 1), 1e-10); assertEquals(0.0, K.get(1, 0), 1e-10); - assertEquals(0.99750312499512261, K.get(1, 1), 1e-10); + assertEquals(0.9975031249951226, K.get(1, 1), 1e-10); // QRN overload var N = MatBuilder.fill(Nat.N2(), Nat.N2(), 1, 0, 0, 1); @@ -146,13 +146,13 @@ void testMatrixOverloadsWithDoubleIntegrator() { // QR overload var K = new LinearQuadraticRegulator<>(A, B, Q, R, 0.005).getK(); assertEquals(1.9960017786537287, K.get(0, 0), 1e-10); - assertEquals(0.51182128351092726, K.get(0, 1), 1e-10); + assertEquals(0.5118212835109273, K.get(0, 1), 1e-10); // QRN overload var Aref = MatBuilder.fill(Nat.N2(), Nat.N2(), 0, 1, 0, -Kv / (Ka * 5.0)); var Kimf = getImplicitModelFollowingK(A, B, Q, R, Aref, 0.005); assertEquals(0.0, Kimf.get(0, 0), 1e-10); - assertEquals(-6.9190500116751458e-05, Kimf.get(0, 1), 1e-10); + assertEquals(-6.919050011675146e-05, Kimf.get(0, 1), 1e-10); } @Test diff --git a/wpimath/src/test/java/edu/wpi/first/math/controller/SimpleMotorFeedforwardTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/SimpleMotorFeedforwardTest.java index e690dafb2c9..6277c030cf7 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/controller/SimpleMotorFeedforwardTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/SimpleMotorFeedforwardTest.java @@ -29,7 +29,7 @@ void testCalculate() { var r = VecBuilder.fill(2.0); var nextR = VecBuilder.fill(3.0); - assertEquals(37.524995834325161 + 0.5, simpleMotor.calculate(2.0, 3.0, dt), 0.002); + assertEquals(37.52499583432516 + 0.5, simpleMotor.calculate(2.0, 3.0, dt), 0.002); assertEquals( plantInversion.calculate(r, nextR).get(0, 0) + Ks, simpleMotor.calculate(2.0, 3.0, dt), diff --git a/wpimath/src/test/java/edu/wpi/first/math/geometry/QuaternionTest.java b/wpimath/src/test/java/edu/wpi/first/math/geometry/QuaternionTest.java index 458b14dbd33..7e6159f573b 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/geometry/QuaternionTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/geometry/QuaternionTest.java @@ -125,7 +125,7 @@ void testTimes() { // Identity var q = new Quaternion( - 0.72760687510899891, 0.29104275004359953, 0.38805700005813276, 0.48507125007266594); + 0.7276068751089989, 0.29104275004359953, 0.38805700005813276, 0.48507125007266594); final var actual2 = q.times(q.inverse()); assertAll( () -> assertEquals(1.0, actual2.getW()), diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Mult.java b/wpiunits/src/main/java/edu/wpi/first/units/Mult.java index 8a0a5fd2de7..72de5cf80f2 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Mult.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Mult.java @@ -48,7 +48,7 @@ protected Mult(Class> baseType, A a, B b) { */ @SuppressWarnings({"unchecked", "rawtypes"}) public static , B extends Unit> Mult combine(A a, B b) { - final long key = ((long) a.hashCode()) << 32L | ((long) b.hashCode()) & 0xFFFFFFFFL; + final long key = ((long) a.hashCode()) << 32L | (((long) b.hashCode()) & 0xFFFFFFFFL); if (cache.containsKey(key)) { return cache.get(key); } diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Per.java b/wpiunits/src/main/java/edu/wpi/first/units/Per.java index e22b7d6caa3..03491cc9dd4 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Per.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Per.java @@ -58,7 +58,7 @@ protected Per(Class> baseType, N numerator, D denominator) { public static , D extends Unit> Per combine( N numerator, D denominator) { final long key = - ((long) numerator.hashCode()) << 32L | ((long) denominator.hashCode()) & 0xFFFFFFFFL; + ((long) numerator.hashCode()) << 32L | (((long) denominator.hashCode()) & 0xFFFFFFFFL); var existing = cache.get(key); if (existing != null) { diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java b/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java index 185c59e6254..ec4e612006d 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Velocity.java @@ -33,7 +33,7 @@ public class Velocity> extends Unit> { /** Generates a cache key used for cache lookups. */ private static long cacheKey(Unit numerator, Unit denominator) { - return ((long) numerator.hashCode()) << 32L | ((long) denominator.hashCode()) & 0xFFFFFFFFL; + return ((long) numerator.hashCode()) << 32L | (((long) denominator.hashCode()) & 0xFFFFFFFFL); } /** diff --git a/wpiunits/src/test/java/edu/wpi/first/units/MeasureTest.java b/wpiunits/src/test/java/edu/wpi/first/units/MeasureTest.java index b2c729e3ece..4b2f66c85f3 100644 --- a/wpiunits/src/test/java/edu/wpi/first/units/MeasureTest.java +++ b/wpiunits/src/test/java/edu/wpi/first/units/MeasureTest.java @@ -173,7 +173,7 @@ void testToLongString() { var measure = Units.Volts.of(343); assertEquals("343.0 Volt", measure.toLongString()); assertEquals("343.0001 Volt", Units.Volts.of(343.0001).toLongString()); - assertEquals("1.2345678912345679E8 Volt", Units.Volts.of(123456789.123456789).toLongString()); + assertEquals("1.2345678912345678E8 Volt", Units.Volts.of(123456789.12345678).toLongString()); } @Test diff --git a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructFieldDescriptor.java b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructFieldDescriptor.java index 25a69a575bc..1d5db379fdb 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructFieldDescriptor.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructFieldDescriptor.java @@ -206,7 +206,7 @@ public long getUintMax() { * @return minimum value */ public long getIntMin() { - return (-(m_bitMask >> 1)) - 1; + return -(m_bitMask >> 1) - 1; } /**