Skip to content

Commit

Permalink
Fix trivial errorprone warnings (NFC) (wpilibsuite#6135)
Browse files Browse the repository at this point in the history
  • Loading branch information
auscompgeek authored Jan 20, 2024
1 parent d198605 commit a274e29
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ntcore/src/generate/main/java/NetworkTableEntry.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/** */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public boolean isConnected() {
* @return
*/
private static int toUShort(ByteBuffer buf) {
return (buf.getShort(0)) & 0xFFFF;
return buf.getShort(0) & 0xFFFF;
}

/**
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wpilibj/src/main/java/edu/wpi/first/wpilibj/Servo.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setAngle(double degrees) {
degrees = kMaxServoAngle;
}

setPosition(((degrees - kMinServoAngle)) / getServoAngleRange());
setPosition((degrees - kMinServoAngle) / getServoAngleRange());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static <Elements extends Num> Matrix<Elements, Elements> 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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public Matrix<Inputs, N1> calculate(Matrix<States, N1> nextR) {
* @return The calculated feedforward.
*/
public Matrix<Inputs, N1> calculate(Matrix<States, N1> r, Matrix<States, N1> nextR) {
var rDot = (nextR.minus(r)).div(m_dt);
var rDot = nextR.minus(r).div(m_dt);

// ṙ = f(r) + Bu
// Bu = ṙ − f(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public <Poses extends Num> 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;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public Matrix<States, N1> calculateX(
Matrix<States, N1> x, Matrix<Inputs, N1> 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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public Matrix<States, N1> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void testLQROnArm() {
*
* <p>This is used to test the QRN overload of LQR.
*
* @param States Number of states.
* @param Inputs Number of inputs.
* @param <States> Number of states.
* @param <Inputs> Number of inputs.
* @param A State matrix.
* @param B Input matrix.
* @param Q State cost matrix.
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion wpiunits/src/main/java/edu/wpi/first/units/Mult.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected Mult(Class<? extends Mult<A, B>> baseType, A a, B b) {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static <A extends Unit<A>, B extends Unit<B>> Mult<A, B> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion wpiunits/src/main/java/edu/wpi/first/units/Per.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected Per(Class<Per<N, D>> baseType, N numerator, D denominator) {
public static <N extends Unit<N>, D extends Unit<D>> Per<N, D> 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) {
Expand Down
2 changes: 1 addition & 1 deletion wpiunits/src/main/java/edu/wpi/first/units/Velocity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Velocity<D extends Unit<D>> extends Unit<Velocity<D>> {

/** 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public long getUintMax() {
* @return minimum value
*/
public long getIntMin() {
return (-(m_bitMask >> 1)) - 1;
return -(m_bitMask >> 1) - 1;
}

/**
Expand Down

0 comments on commit a274e29

Please sign in to comment.