From e674a629a297857cb034fc624321649f0f1885f7 Mon Sep 17 00:00:00 2001 From: Sriman Achanta <68172138+srimanachanta@users.noreply.github.com> Date: Sat, 2 Dec 2023 00:17:20 -0500 Subject: [PATCH] newer stuff --- .../wpi/first/apriltag/LoadConfigTest.java | 3 +- .../src/main/java/edu/wpi/Main.java | 2 +- .../wpi/first/cameraserver/CameraServer.java | 2 +- .../java/edu/wpi/first/hal/DMAJNISample.java | 9 +-- .../networktables/NetworkTableEntry.java | 2 +- .../networktables/NetworkTableInstance.java | 2 +- .../networktables/NetworkTableValue.java | 16 ++--- .../networktables/ProtobufEntryImpl.java | 6 +- .../first/networktables/ProtobufTopic.java | 12 ++-- .../networktables/StructArrayEntryImpl.java | 7 +-- .../first/networktables/StructArrayTopic.java | 12 ++-- .../first/networktables/StructEntryImpl.java | 6 +- .../wpi/first/networktables/StructTopic.java | 12 ++-- .../command/ParallelRaceGroupTest.java | 2 +- .../command/SchedulingRecursionTest.java | 2 +- .../edu/wpi/first/wpilibj/SensorUtil.java | 60 +++++++++---------- .../edu/wpi/first/wpilibj/SerialPort.java | 2 +- .../edu/wpi/first/wpilibj/TimedRobotTest.java | 57 ++++-------------- .../wpi/first/wpilibj/TimesliceRobotTest.java | 20 ++----- .../edu/wpi/first/wpilibj/WatchdogTest.java | 42 ++----------- .../wpilibj/simulation/SimDeviceSimTest.java | 40 +++---------- .../smartdashboard/SendableChooserTest.java | 2 +- .../ReplaceMeTrapezoidProfileCommand.java | 4 +- .../examples/unittest/subsystems/Intake.java | 2 +- .../first/wpilibj/AbstractInterruptTest.java | 2 +- .../java/edu/wpi/first/wpilibj/PDPTest.java | 2 +- .../java/edu/wpi/first/wpilibj/PIDTest.java | 2 +- .../first/wpilibj/test/AbstractComsSetup.java | 2 +- .../first/wpilibj/test/AbstractTestSuite.java | 7 +-- .../first/wpilibj/test/AntJunitLauncher.java | 3 +- .../edu/wpi/first/wpilibj/test/TestBench.java | 18 +++--- .../edu/wpi/first/wpilibj/test/TestSuite.java | 44 +++++++------- .../controller/LinearQuadraticRegulator.java | 14 ++--- .../first/math/estimator/KalmanFilter.java | 15 ++--- .../estimator/SteadyStateKalmanFilter.java | 15 ++--- .../wpi/first/math/geometry/Rotation3d.java | 14 ++--- .../first/math/path/TravelingSalesman.java | 2 +- .../first/math/spline/CubicHermiteSpline.java | 17 +----- .../math/spline/QuinticHermiteSpline.java | 22 ++++--- .../math/trajectory/ExponentialProfile.java | 46 +++++++------- .../java/edu/wpi/first/math/DARETest.java | 6 +- ...olAffinePlantInversionFeedforwardTest.java | 6 +- .../controller/ImplicitModelFollowerTest.java | 4 +- .../LinearPlantInversionFeedforwardTest.java | 2 +- .../first/math/filter/LinearFilterTest.java | 20 +++---- .../optimization/SimulatedAnnealingTest.java | 4 +- .../math/system/NumericalIntegrationTest.java | 7 +-- .../system/RungeKuttaTimeVaryingTest.java | 7 +-- ...ifferentialDriveVoltageConstraintTest.java | 5 +- .../wpi/first/util/CombinedRuntimeLoader.java | 3 +- .../wpi/first/util/cleanup/CleanupPool.java | 2 +- .../first/util/datalog/ProtobufLogEntry.java | 2 +- .../util/datalog/StructArrayLogEntry.java | 2 +- .../first/util/datalog/StructLogEntry.java | 2 +- .../first/util/protobuf/ProtobufBuffer.java | 2 +- .../wpi/first/util/struct/StructBuffer.java | 2 +- .../util/struct/StructDescriptorDatabase.java | 4 +- .../first/util/struct/parser/ParserTest.java | 49 +++++++-------- 58 files changed, 258 insertions(+), 420 deletions(-) diff --git a/apriltag/src/test/java/edu/wpi/first/apriltag/LoadConfigTest.java b/apriltag/src/test/java/edu/wpi/first/apriltag/LoadConfigTest.java index 901c72bd89b..d5deb573af9 100644 --- a/apriltag/src/test/java/edu/wpi/first/apriltag/LoadConfigTest.java +++ b/apriltag/src/test/java/edu/wpi/first/apriltag/LoadConfigTest.java @@ -12,7 +12,6 @@ import edu.wpi.first.math.geometry.Pose3d; import edu.wpi.first.math.geometry.Rotation3d; import edu.wpi.first.math.util.Units; -import java.io.IOException; import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -28,7 +27,7 @@ void testLoad(AprilTagFields field) { } @Test - void test2022RapidReact() throws IOException { + void test2022RapidReact() { AprilTagFieldLayout layout = AprilTagFields.k2022RapidReact.loadAprilTagLayoutField(); // Blue Hangar Truss - Hub diff --git a/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java b/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java index 1f791821898..f69a6feec53 100644 --- a/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java +++ b/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java @@ -98,7 +98,7 @@ public static boolean readConfig() { // parse file JsonElement top; try { - top = new JsonParser().parse(Files.newBufferedReader(Paths.get(configFile))); + top = JsonParser.parseReader(Files.newBufferedReader(Paths.get(configFile))); } catch (IOException ex) { System.err.println("could not open '" + configFile + "': " + ex); return false; diff --git a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java index 376f9608bd4..397cd20809e 100644 --- a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java +++ b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java @@ -114,7 +114,7 @@ void update(VideoEvent event) { } @Override - public void close() throws Exception { + public void close() { if (m_booleanValueEntry != null) { m_booleanValueEntry.close(); } diff --git a/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java b/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java index 22f21c8c6b6..51494a616d4 100644 --- a/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java +++ b/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java @@ -131,8 +131,7 @@ public int getAnalogInputAveraged(int analogInputHandle) { } // + 2 Hack, but needed to not have to call into JNI - int value = readValue(data.m_valueType + 2, data.m_index); - return value; + return readValue(data.m_valueType + 2, data.m_index); } public void getAnalogAccumulator(int analogInputHandle, AccumulatorResult result) { @@ -144,14 +143,12 @@ public void getAnalogAccumulator(int analogInputHandle, AccumulatorResult result if (data.m_index == 0) { int val0 = readValue(kEnable_Accumulator0, 0); int val1 = readValue(kEnable_Accumulator0, 1); - int val2 = readValue(kEnable_Accumulator0, 2); - result.count = val2; + result.count = readValue(kEnable_Accumulator0, 2); result.value = ((long) val1 << 32) | val0; } else if (data.m_index == 1) { int val0 = readValue(kEnable_Accumulator1, 0); int val1 = readValue(kEnable_Accumulator1, 1); - int val2 = readValue(kEnable_Accumulator1, 2); - result.count = val2; + result.count = readValue(kEnable_Accumulator1, 2); result.value = ((long) val1 << 32) | val0; } else { throw new RuntimeException("Resource not found in DMA capture"); 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/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java index e5872ba425f..d32ccce1fec 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -890,7 +890,7 @@ private void startThread() { } catch (Throwable throwable) { System.err.println( "Unhandled exception during listener callback: " - + throwable.toString()); + + throwable); throwable.printStackTrace(); } } diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java index 3045d284a50..bf8a441069a 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java @@ -336,7 +336,7 @@ public String[] getStringArray() { * @return The entry value */ public static NetworkTableValue makeBoolean(boolean value) { - return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value)); + return new NetworkTableValue(NetworkTableType.kBoolean, value); } /** @@ -347,7 +347,7 @@ public static NetworkTableValue makeBoolean(boolean value) { * @return The entry value */ public static NetworkTableValue makeBoolean(boolean value, long time) { - return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value), time); + return new NetworkTableValue(NetworkTableType.kBoolean, value, time); } /** @@ -357,7 +357,7 @@ public static NetworkTableValue makeBoolean(boolean value, long time) { * @return The entry value */ public static NetworkTableValue makeInteger(long value) { - return new NetworkTableValue(NetworkTableType.kInteger, Long.valueOf(value)); + return new NetworkTableValue(NetworkTableType.kInteger, value); } /** @@ -368,7 +368,7 @@ public static NetworkTableValue makeInteger(long value) { * @return The entry value */ public static NetworkTableValue makeInteger(long value, long time) { - return new NetworkTableValue(NetworkTableType.kInteger, Long.valueOf(value), time); + return new NetworkTableValue(NetworkTableType.kInteger, value, time); } /** @@ -378,7 +378,7 @@ public static NetworkTableValue makeInteger(long value, long time) { * @return The entry value */ public static NetworkTableValue makeFloat(float value) { - return new NetworkTableValue(NetworkTableType.kFloat, Float.valueOf(value)); + return new NetworkTableValue(NetworkTableType.kFloat, value); } /** @@ -389,7 +389,7 @@ public static NetworkTableValue makeFloat(float value) { * @return The entry value */ public static NetworkTableValue makeFloat(float value, long time) { - return new NetworkTableValue(NetworkTableType.kFloat, Float.valueOf(value), time); + return new NetworkTableValue(NetworkTableType.kFloat, value, time); } /** @@ -399,7 +399,7 @@ public static NetworkTableValue makeFloat(float value, long time) { * @return The entry value */ public static NetworkTableValue makeDouble(double value) { - return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value)); + return new NetworkTableValue(NetworkTableType.kDouble, value); } /** @@ -410,7 +410,7 @@ public static NetworkTableValue makeDouble(double value) { * @return The entry value */ public static NetworkTableValue makeDouble(double value, long time) { - return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value), time); + return new NetworkTableValue(NetworkTableType.kDouble, value, time); } /** diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufEntryImpl.java b/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufEntryImpl.java index b4359eaf030..6d891c45169 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufEntryImpl.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufEntryImpl.java @@ -190,14 +190,14 @@ private T fromRaw(byte[] raw, T defaultValue) { private TimestampedObject fromRaw(TimestampedRaw raw, T defaultValue) { if (raw.value.length == 0) { - return new TimestampedObject(0, 0, defaultValue); + return new TimestampedObject<>(0, 0, defaultValue); } try { synchronized (m_buf) { - return new TimestampedObject(raw.timestamp, raw.serverTime, m_buf.read(raw.value)); + return new TimestampedObject<>(raw.timestamp, raw.serverTime, m_buf.read(raw.value)); } } catch (IOException e) { - return new TimestampedObject(0, 0, defaultValue); + return new TimestampedObject<>(0, 0, defaultValue); } } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java b/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java index c3dad133a58..15313d7f683 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/ProtobufTopic.java @@ -32,7 +32,7 @@ private ProtobufTopic(NetworkTableInstance inst, int handle, Protobuf prot * @return ProtobufTopic for value class */ public static ProtobufTopic wrap(Topic topic, Protobuf proto) { - return new ProtobufTopic(topic, proto); + return new ProtobufTopic<>(topic, proto); } /** @@ -47,7 +47,7 @@ public static ProtobufTopic wrap(Topic topic, Protobuf proto) { */ public static ProtobufTopic wrap( NetworkTableInstance inst, int handle, Protobuf proto) { - return new ProtobufTopic(inst, handle, proto); + return new ProtobufTopic<>(inst, handle, proto); } /** @@ -63,7 +63,7 @@ public static ProtobufTopic wrap( * @return subscriber */ public ProtobufSubscriber subscribe(T defaultValue, PubSubOption... options) { - return new ProtobufEntryImpl( + return new ProtobufEntryImpl<>( this, ProtobufBuffer.create(m_proto), NetworkTablesJNI.subscribe( @@ -87,7 +87,7 @@ public ProtobufSubscriber subscribe(T defaultValue, PubSubOption... options) */ public ProtobufPublisher publish(PubSubOption... options) { m_inst.addSchema(m_proto); - return new ProtobufEntryImpl( + return new ProtobufEntryImpl<>( this, ProtobufBuffer.create(m_proto), NetworkTablesJNI.publish( @@ -113,7 +113,7 @@ public ProtobufPublisher publish(PubSubOption... options) { */ public ProtobufPublisher publishEx(String properties, PubSubOption... options) { m_inst.addSchema(m_proto); - return new ProtobufEntryImpl( + return new ProtobufEntryImpl<>( this, ProtobufBuffer.create(m_proto), NetworkTablesJNI.publishEx( @@ -144,7 +144,7 @@ public ProtobufPublisher publishEx(String properties, PubSubOption... options * @return entry */ public ProtobufEntry getEntry(T defaultValue, PubSubOption... options) { - return new ProtobufEntryImpl( + return new ProtobufEntryImpl<>( this, ProtobufBuffer.create(m_proto), NetworkTablesJNI.getEntry( diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayEntryImpl.java b/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayEntryImpl.java index 4e8a4a0495a..1e6b69ec0fd 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayEntryImpl.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayEntryImpl.java @@ -177,15 +177,14 @@ private T[] fromRaw(byte[] raw, T[] defaultValue) { @SuppressWarnings("PMD.AvoidCatchingGenericException") private TimestampedObject fromRaw(TimestampedRaw raw, T[] defaultValue) { if (raw.value.length == 0) { - return new TimestampedObject(0, 0, defaultValue); + return new TimestampedObject<>(0, 0, defaultValue); } try { synchronized (m_buf) { - return new TimestampedObject( - raw.timestamp, raw.serverTime, m_buf.readArray(raw.value)); + return new TimestampedObject<>(raw.timestamp, raw.serverTime, m_buf.readArray(raw.value)); } } catch (RuntimeException e) { - return new TimestampedObject(0, 0, defaultValue); + return new TimestampedObject<>(0, 0, defaultValue); } } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java b/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java index 247501bbfa0..557e9ddf4ef 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/StructArrayTopic.java @@ -32,7 +32,7 @@ private StructArrayTopic(NetworkTableInstance inst, int handle, Struct struct * @return StructArrayTopic for value class */ public static StructArrayTopic wrap(Topic topic, Struct struct) { - return new StructArrayTopic(topic, struct); + return new StructArrayTopic<>(topic, struct); } /** @@ -47,7 +47,7 @@ public static StructArrayTopic wrap(Topic topic, Struct struct) { */ public static StructArrayTopic wrap( NetworkTableInstance inst, int handle, Struct struct) { - return new StructArrayTopic(inst, handle, struct); + return new StructArrayTopic<>(inst, handle, struct); } /** @@ -63,7 +63,7 @@ public static StructArrayTopic wrap( * @return subscriber */ public StructArraySubscriber subscribe(T[] defaultValue, PubSubOption... options) { - return new StructArrayEntryImpl( + return new StructArrayEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.subscribe( @@ -87,7 +87,7 @@ public StructArraySubscriber subscribe(T[] defaultValue, PubSubOption... opti */ public StructArrayPublisher publish(PubSubOption... options) { m_inst.addSchema(m_struct); - return new StructArrayEntryImpl( + return new StructArrayEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.publish( @@ -113,7 +113,7 @@ public StructArrayPublisher publish(PubSubOption... options) { */ public StructArrayPublisher publishEx(String properties, PubSubOption... options) { m_inst.addSchema(m_struct); - return new StructArrayEntryImpl( + return new StructArrayEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.publishEx( @@ -144,7 +144,7 @@ public StructArrayPublisher publishEx(String properties, PubSubOption... opti * @return entry */ public StructArrayEntry getEntry(T[] defaultValue, PubSubOption... options) { - return new StructArrayEntryImpl( + return new StructArrayEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.getEntry( diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/StructEntryImpl.java b/ntcore/src/main/java/edu/wpi/first/networktables/StructEntryImpl.java index bd02d27fe5d..5d377657075 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/StructEntryImpl.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/StructEntryImpl.java @@ -188,14 +188,14 @@ private T fromRaw(byte[] raw, T defaultValue) { @SuppressWarnings("PMD.AvoidCatchingGenericException") private TimestampedObject fromRaw(TimestampedRaw raw, T defaultValue) { if (raw.value.length == 0) { - return new TimestampedObject(0, 0, defaultValue); + return new TimestampedObject<>(0, 0, defaultValue); } try { synchronized (m_buf) { - return new TimestampedObject(raw.timestamp, raw.serverTime, m_buf.read(raw.value)); + return new TimestampedObject<>(raw.timestamp, raw.serverTime, m_buf.read(raw.value)); } } catch (RuntimeException e) { - return new TimestampedObject(0, 0, defaultValue); + return new TimestampedObject<>(0, 0, defaultValue); } } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java b/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java index b1ff0264f3c..22dbd2d7a17 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/StructTopic.java @@ -32,7 +32,7 @@ private StructTopic(NetworkTableInstance inst, int handle, Struct struct) { * @return StructTopic for value class */ public static StructTopic wrap(Topic topic, Struct struct) { - return new StructTopic(topic, struct); + return new StructTopic<>(topic, struct); } /** @@ -46,7 +46,7 @@ public static StructTopic wrap(Topic topic, Struct struct) { * @return StructTopic for value class */ public static StructTopic wrap(NetworkTableInstance inst, int handle, Struct struct) { - return new StructTopic(inst, handle, struct); + return new StructTopic<>(inst, handle, struct); } /** @@ -62,7 +62,7 @@ public static StructTopic wrap(NetworkTableInstance inst, int handle, Str * @return subscriber */ public StructSubscriber subscribe(T defaultValue, PubSubOption... options) { - return new StructEntryImpl( + return new StructEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.subscribe( @@ -86,7 +86,7 @@ public StructSubscriber subscribe(T defaultValue, PubSubOption... options) { */ public StructPublisher publish(PubSubOption... options) { m_inst.addSchema(m_struct); - return new StructEntryImpl( + return new StructEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.publish( @@ -112,7 +112,7 @@ public StructPublisher publish(PubSubOption... options) { */ public StructPublisher publishEx(String properties, PubSubOption... options) { m_inst.addSchema(m_struct); - return new StructEntryImpl( + return new StructEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.publishEx( @@ -143,7 +143,7 @@ public StructPublisher publishEx(String properties, PubSubOption... options) * @return entry */ public StructEntry getEntry(T defaultValue, PubSubOption... options) { - return new StructEntryImpl( + return new StructEntryImpl<>( this, StructBuffer.create(m_struct), NetworkTablesJNI.getEntry( diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java index 67524960ca3..dd650c4bac8 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java @@ -153,7 +153,7 @@ void parallelRaceOnlyCallsEndOnceTest() { scheduler.run(); command2Holder.setFinished(true); // at this point the sequential group should be done - assertDoesNotThrow(() -> scheduler.run()); + assertDoesNotThrow(scheduler::run); assertFalse(scheduler.isScheduled(group2)); } } diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java index 5e8fd392e46..a253740c028 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java @@ -288,7 +288,7 @@ void cancelFromEndLoopWhileInRunLoop() { scheduler.schedule(cCancelsD); scheduler.schedule(dCancelsAll); - assertDoesNotThrow(() -> scheduler.run()); + assertDoesNotThrow(scheduler::run); assertEquals(4, counter.get()); assertFalse(scheduler.isScheduled(aCancelsB)); assertFalse(scheduler.isScheduled(bCancelsC)); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SensorUtil.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SensorUtil.java index bcedd81fea7..18ee44e9751 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SensorUtil.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SensorUtil.java @@ -59,12 +59,12 @@ public final class SensorUtil { */ public static void checkDigitalChannel(final int channel) { if (!DIOJNI.checkDIOChannel(channel)) { - StringBuilder buf = new StringBuilder(); - buf.append("Requested DIO channel is out of range. Minimum: 0, Maximum: ") - .append(kDigitalChannels) - .append(", Requested: ") - .append(channel); - throw new IllegalArgumentException(buf.toString()); + String buf = + "Requested DIO channel is out of range. Minimum: 0, Maximum: " + + kDigitalChannels + + ", Requested: " + + channel; + throw new IllegalArgumentException(buf); } } @@ -76,12 +76,12 @@ public static void checkDigitalChannel(final int channel) { */ public static void checkRelayChannel(final int channel) { if (!RelayJNI.checkRelayChannel(channel)) { - StringBuilder buf = new StringBuilder(); - buf.append("Requested relay channel is out of range. Minimum: 0, Maximum: ") - .append(kRelayChannels) - .append(", Requested: ") - .append(channel); - throw new IllegalArgumentException(buf.toString()); + String buf = + "Requested relay channel is out of range. Minimum: 0, Maximum: " + + kRelayChannels + + ", Requested: " + + channel; + throw new IllegalArgumentException(buf); } } @@ -93,12 +93,12 @@ public static void checkRelayChannel(final int channel) { */ public static void checkPWMChannel(final int channel) { if (!PWMJNI.checkPWMChannel(channel)) { - StringBuilder buf = new StringBuilder(); - buf.append("Requested PWM channel is out of range. Minimum: 0, Maximum: ") - .append(kPwmChannels) - .append(", Requested: ") - .append(channel); - throw new IllegalArgumentException(buf.toString()); + String buf = + "Requested PWM channel is out of range. Minimum: 0, Maximum: " + + kPwmChannels + + ", Requested: " + + channel; + throw new IllegalArgumentException(buf); } } @@ -110,12 +110,12 @@ public static void checkPWMChannel(final int channel) { */ public static void checkAnalogInputChannel(final int channel) { if (!AnalogJNI.checkAnalogInputChannel(channel)) { - StringBuilder buf = new StringBuilder(); - buf.append("Requested analog input channel is out of range. Minimum: 0, Maximum: ") - .append(kAnalogInputChannels) - .append(", Requested: ") - .append(channel); - throw new IllegalArgumentException(buf.toString()); + String buf = + "Requested analog input channel is out of range. Minimum: 0, Maximum: " + + kAnalogInputChannels + + ", Requested: " + + channel; + throw new IllegalArgumentException(buf); } } @@ -127,12 +127,12 @@ public static void checkAnalogInputChannel(final int channel) { */ public static void checkAnalogOutputChannel(final int channel) { if (!AnalogJNI.checkAnalogOutputChannel(channel)) { - StringBuilder buf = new StringBuilder(); - buf.append("Requested analog output channel is out of range. Minimum: 0, Maximum: ") - .append(kAnalogOutputChannels) - .append(", Requested: ") - .append(channel); - throw new IllegalArgumentException(buf.toString()); + String buf = + "Requested analog output channel is out of range. Minimum: 0, Maximum: " + + kAnalogOutputChannels + + ", Requested: " + + channel; + throw new IllegalArgumentException(buf); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java index 1a05c8af4da..ada1839e5d4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java @@ -216,7 +216,7 @@ public String readString() { */ public String readString(int count) { byte[] out = read(count); - return new String(out, 0, out.length, StandardCharsets.US_ASCII); + return new String(out, StandardCharsets.US_ASCII); } /** diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimedRobotTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimedRobotTest.java index c1c5f3c1286..920fb546e8c 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimedRobotTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimedRobotTest.java @@ -144,11 +144,7 @@ void cleanup() { void disabledModeTest() { MockRobot robot = new MockRobot(); - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); DriverStationSim.setEnabled(false); @@ -231,11 +227,7 @@ void disabledModeTest() { void autonomousModeTest() { MockRobot robot = new MockRobot(); - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); DriverStationSim.setEnabled(true); @@ -320,11 +312,7 @@ void autonomousModeTest() { void teleopModeTest() { MockRobot robot = new MockRobot(); - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); DriverStationSim.setEnabled(true); @@ -411,11 +399,7 @@ void testModeTest(boolean isLW) { MockRobot robot = new MockRobot(); robot.enableLiveWindowInTest(isLW); - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); DriverStationSim.setEnabled(true); @@ -531,11 +515,7 @@ void testModeTest(boolean isLW) { void modeChangeTest() { MockRobot robot = new MockRobot(); - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); // Start in disabled @@ -655,17 +635,9 @@ void addPeriodicTest() { MockRobot robot = new MockRobot(); final AtomicInteger callbackCount = new AtomicInteger(0); - robot.addPeriodic( - () -> { - callbackCount.addAndGet(1); - }, - kPeriod / 2.0); - - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + robot.addPeriodic(() -> callbackCount.addAndGet(1), kPeriod / 2.0); + + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); DriverStationSim.setEnabled(false); @@ -704,12 +676,7 @@ void addPeriodicWithOffsetTest() { MockRobot robot = new MockRobot(); final AtomicInteger callbackCount = new AtomicInteger(0); - robot.addPeriodic( - () -> { - callbackCount.addAndGet(1); - }, - kPeriod / 2.0, - kPeriod / 4.0); + robot.addPeriodic(() -> callbackCount.addAndGet(1), kPeriod / 2.0, kPeriod / 4.0); // Expirations in this test (ms) // @@ -720,11 +687,7 @@ void addPeriodicWithOffsetTest() { // p | 0.75p // 2p | 1.25p - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); DriverStationSim.setEnabled(false); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimesliceRobotTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimesliceRobotTest.java index ee4860deb7f..5cff0d0dc9a 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimesliceRobotTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/TimesliceRobotTest.java @@ -54,22 +54,10 @@ void scheduleTest() { // | RobotPeriodic() | 0 | 2 | // | Callback 1 | 2 | 0.5 | // | Callback 2 | 2.5 | 1 | - robot.schedule( - () -> { - callbackCount1.addAndGet(1); - }, - 0.0005); - robot.schedule( - () -> { - callbackCount2.addAndGet(1); - }, - 0.001); - - Thread robotThread = - new Thread( - () -> { - robot.startCompetition(); - }); + robot.schedule(() -> callbackCount1.addAndGet(1), 0.0005); + robot.schedule(() -> callbackCount2.addAndGet(1), 0.001); + + Thread robotThread = new Thread(robot::startCompetition); robotThread.start(); DriverStationSim.setEnabled(false); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/WatchdogTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/WatchdogTest.java index c1676e0c36e..5e9e1229418 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/WatchdogTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/WatchdogTest.java @@ -33,12 +33,7 @@ void cleanup() { void enableDisableTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - try (Watchdog watchdog = - new Watchdog( - 0.4, - () -> { - watchdogCounter.addAndGet(1); - })) { + try (Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1))) { // Run 1 watchdog.enable(); SimHooks.stepTiming(0.2); @@ -71,12 +66,7 @@ void enableDisableTest() { void resetTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - try (Watchdog watchdog = - new Watchdog( - 0.4, - () -> { - watchdogCounter.addAndGet(1); - })) { + try (Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1))) { watchdog.enable(); SimHooks.stepTiming(0.2); watchdog.reset(); @@ -92,12 +82,7 @@ void resetTest() { void setTimeoutTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - try (Watchdog watchdog = - new Watchdog( - 1.0, - () -> { - watchdogCounter.addAndGet(1); - })) { + try (Watchdog watchdog = new Watchdog(1.0, () -> watchdogCounter.addAndGet(1))) { watchdog.enable(); SimHooks.stepTiming(0.2); watchdog.setTimeout(0.2); @@ -137,12 +122,7 @@ void isExpiredTest() { void epochsTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - try (Watchdog watchdog = - new Watchdog( - 0.4, - () -> { - watchdogCounter.addAndGet(1); - })) { + try (Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1))) { // Run 1 watchdog.enable(); watchdog.addEpoch("Epoch 1"); @@ -173,18 +153,8 @@ void multiWatchdogTest() { final AtomicInteger watchdogCounter1 = new AtomicInteger(0); final AtomicInteger watchdogCounter2 = new AtomicInteger(0); - try (Watchdog watchdog1 = - new Watchdog( - 0.2, - () -> { - watchdogCounter1.addAndGet(1); - }); - Watchdog watchdog2 = - new Watchdog( - 0.6, - () -> { - watchdogCounter2.addAndGet(1); - })) { + try (Watchdog watchdog1 = new Watchdog(0.2, () -> watchdogCounter1.addAndGet(1)); + Watchdog watchdog2 = new Watchdog(0.6, () -> watchdogCounter2.addAndGet(1))) { watchdog2.enable(); SimHooks.stepTiming(0.25); assertEquals(0, watchdogCounter1.get(), "Watchdog triggered early"); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SimDeviceSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SimDeviceSimTest.java index 62a24d1d75a..89b4333e609 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SimDeviceSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SimDeviceSimTest.java @@ -41,18 +41,10 @@ void testDeviceCreatedCallback() { SimDevice dev1 = SimDevice.create("testDC1")) { try (CallbackStore callback1 = SimDeviceSim.registerDeviceCreatedCallback( - "testDC", - (name, handle) -> { - callback1Counter.addAndGet(1); - }, - false); + "testDC", (name, handle) -> callback1Counter.addAndGet(1), false); CallbackStore callback2 = SimDeviceSim.registerDeviceCreatedCallback( - "testDC", - (name, handle) -> { - callback2Counter.addAndGet(1); - }, - true)) { + "testDC", (name, handle) -> callback2Counter.addAndGet(1), true)) { assertEquals(0, callback1Counter.get(), "Callback 1 called early"); assertEquals( 1, @@ -82,11 +74,7 @@ void testDeviceFreedCallback() { SimDevice dev1 = SimDevice.create("testDF1"); try (CallbackStore callback = SimDeviceSim.registerDeviceFreedCallback( - "testDF", - (name, handle) -> { - counter.addAndGet(1); - }, - false)) { + "testDF", (name, handle) -> counter.addAndGet(1), false)) { assertEquals(0, counter.get(), "Callback called early"); dev1.close(); assertEquals(1, counter.get(), "Callback called either more than once or not at all"); @@ -108,16 +96,10 @@ void testValueCreatedCallback() { SimDeviceSim sim = new SimDeviceSim("testVM1"); try (CallbackStore callback1 = sim.registerValueCreatedCallback( - (name, handle, readonly, value) -> { - callback1Counter.addAndGet(1); - }, - false); + (name, handle, readonly, value) -> callback1Counter.addAndGet(1), false); CallbackStore callback2 = sim.registerValueCreatedCallback( - (name, handle, readonly, value) -> { - callback2Counter.addAndGet(1); - }, - true)) { + (name, handle, readonly, value) -> callback2Counter.addAndGet(1), true)) { assertEquals(0, callback1Counter.get(), "Callback 1 called early"); assertEquals( 1, @@ -148,18 +130,10 @@ void testValueChangedCallback() { SimValue simVal = sim.getValue("v1"); try (CallbackStore callback1 = sim.registerValueChangedCallback( - simVal, - (name, handle, readonly, value) -> { - callback1Counter.addAndGet(1); - }, - false); + simVal, (name, handle, readonly, value) -> callback1Counter.addAndGet(1), false); CallbackStore callback2 = sim.registerValueChangedCallback( - simVal, - (name, handle, readonly, value) -> { - callback2Counter.addAndGet(1); - }, - true)) { + simVal, (name, handle, readonly, value) -> callback2Counter.addAndGet(1), true)) { assertEquals(0, callback1Counter.get(), "Callback 1 called early"); assertEquals( 1, diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooserTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooserTest.java index 07f09af3cd2..d97d54c243c 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooserTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooserTest.java @@ -75,7 +75,7 @@ void testChangeListener() { chooser.addOption(String.valueOf(i), i); } AtomicInteger currentVal = new AtomicInteger(); - chooser.onChange(val -> currentVal.set(val)); + chooser.onChange(currentVal::set); SmartDashboard.putData("changeListenerChooser", chooser); SmartDashboard.updateValues(); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java index 5ed9fda3d28..fa55f451d2a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java @@ -22,8 +22,8 @@ public ReplaceMeTrapezoidProfileCommand() { // Use current trajectory state here }, // Goal state - () -> new TrapezoidProfile.State(), + TrapezoidProfile.State::new, // Current state - () -> new TrapezoidProfile.State()); + TrapezoidProfile.State::new); } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/Intake.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/Intake.java index a51d505a988..e84a6079a6a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/Intake.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/unittest/subsystems/Intake.java @@ -44,7 +44,7 @@ public boolean isDeployed() { } @Override - public void close() throws Exception { + public void close() { m_piston.close(); m_motor.close(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java index bdc467578f2..22267b13f82 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import edu.wpi.first.wpilibj.test.AbstractComsSetup; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java index 9124251a453..d668d16d5a0 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import edu.wpi.first.hal.can.CANMessageNotFoundException; import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java index 16da126caf5..f2cd12fd0ad 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java @@ -72,7 +72,7 @@ public PIDTest(Double p, Double i, Double d, MotorEncoderFixture mef) { @Parameters public static Collection generateData() { // logger.fine("Loading the MotorList"); - Collection data = new ArrayList(); + Collection data = new ArrayList<>(); double kp = 0.001; double ki = 0.0005; double kd = 0.0; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java index 056ff5ff1c7..4a912931bde 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java @@ -31,7 +31,7 @@ public abstract class AbstractComsSetup { // We have no way to stop the MockDS, so its thread is daemon. private static MockDS ds; - /** + /* * This sets up the network communications library to enable the driver station. After starting * network coms, it will loop until the driver station returns that the robot is enabled, to * ensure that tests will be able to run on the hardware. diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java index ff0542c7b2c..9573ec3454a 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java @@ -7,6 +7,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -34,15 +35,11 @@ public abstract class AbstractTestSuite { */ protected List> getAnnotatedTestClasses() { SuiteClasses annotation = getClass().getAnnotation(SuiteClasses.class); - List> classes = new ArrayList<>(); if (annotation == null) { throw new RuntimeException( String.format("class '%s' must have a SuiteClasses annotation", getClass().getName())); } - for (Class c : annotation.value()) { - classes.add(c); - } - return classes; + return new ArrayList<>(Arrays.asList(annotation.value())); } private boolean areAnySuperClassesOfTypeAbstractTestSuite(Class check) { diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLauncher.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLauncher.java index 07d0af72f35..31da1036fad 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLauncher.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLauncher.java @@ -24,9 +24,8 @@ public class AntJunitLauncher { */ public static void main(String... args) { if (args.length == 0) { - String path = + String pathToReports = String.format("%s/%s", System.getProperty("user.dir"), "/testResults/AntReports"); - String pathToReports = path; Project project = new Project(); try { diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java index 87baff0e8c0..508c432cbfc 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java @@ -58,7 +58,7 @@ public final class TestBench { * The single constructor for the TestBench. This method is private in order to prevent multiple * TestBench objects from being allocated. */ - protected TestBench() {} + private TestBench() {} /** * Constructs a new set of objects representing a connected set of Talon controlled Motors and an @@ -67,7 +67,7 @@ protected TestBench() {} * @return a freshly allocated Talon, Encoder pair */ public static MotorEncoderFixture getTalonPair() { - return new MotorEncoderFixture() { + return new MotorEncoderFixture<>() { @Override protected Talon giveMotorController() { return new Talon(kTalonChannel); @@ -97,7 +97,7 @@ public int getPDPChannel() { * @return a freshly allocated Victor, Encoder pair */ public static MotorEncoderFixture getVictorPair() { - return new MotorEncoderFixture() { + return new MotorEncoderFixture<>() { @Override protected Victor giveMotorController() { return new Victor(kVictorChannel); @@ -127,7 +127,7 @@ public int getPDPChannel() { * @return a freshly allocated Jaguar, Encoder pair */ public static MotorEncoderFixture getJaguarPair() { - return new MotorEncoderFixture() { + return new MotorEncoderFixture<>() { @Override protected Jaguar giveMotorController() { return new Jaguar(kJaguarChannel); @@ -189,7 +189,7 @@ public static DIOCrossConnectFixture getDIOCrossConnectFixture(int inputPort, in /** Gets two lists of possible DIO pairs for the two pairs. */ private static List> getDIOCrossConnect() { - List> pairs = new ArrayList>(); + List> pairs = new ArrayList<>(); List setA = List.of( new Integer[][] { @@ -251,7 +251,7 @@ protected DigitalInput giveInputOne() { * @return pairs of DIOCrossConnectFixtures */ public static Collection getDIOCrossConnectCollection() { - Collection pairs = new ArrayList(); + Collection pairs = new ArrayList<>(); for (Collection collection : getDIOCrossConnect()) { pairs.addAll(collection); } @@ -266,7 +266,7 @@ public static Collection getDIOCrossConnectCollection() { */ private static Collection getPairArray( List listA, List listB, boolean flip) { - Collection encoderPortPairs = new ArrayList(); + Collection encoderPortPairs = new ArrayList<>(); for (Integer[] portPairsA : listA) { Integer[] inputs = new Integer[5]; inputs[0] = portPairsA[0]; // InputA @@ -278,7 +278,7 @@ private static Collection getPairArray( inputs[4] = flip ? 0 : 1; // The flip bit } - ArrayList construtorInput = new ArrayList(); + ArrayList construtorInput = new ArrayList<>(); construtorInput.add(inputs); inputs = inputs.clone(); @@ -299,7 +299,7 @@ private static Collection getPairArray( * @return A collection of different input pairs to use for the encoder */ public static Collection getEncoderDIOCrossConnectCollection() { - Collection encoderPortPairs = new ArrayList(); + Collection encoderPortPairs = new ArrayList<>(); assert getDIOCrossConnect().size() == 2; encoderPortPairs.addAll( getPairArray(getDIOCrossConnect().get(0), getDIOCrossConnect().get(1), false)); diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestSuite.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestSuite.java index 81b3b0e0d76..befc0668bbd 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestSuite.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestSuite.java @@ -76,40 +76,36 @@ public TestSuite() {} /** Displays a help message for the user when they use the --help flag at runtime. */ protected static void displayHelp() { - StringBuilder helpMessage = new StringBuilder("Test Parameters help: \n"); - helpMessage.append( - "\t" + String helpMessage = + "Test Parameters help: \n" + + "\t" + QUICK_TEST_FLAG + " will cause the quick test to be run. Ignores other flags except for " + METHOD_REPEAT_FILTER - + "\n"); - helpMessage.append( - "\t" + + "\n" + + "\t" + CLASS_NAME_FILTER + " will use the supplied regex text to search for suite/test class names " - + "matching the regex and run them.\n"); - helpMessage.append( - "\t" + + "matching the regex and run them.\n" + + "\t" + METHOD_NAME_FILTER + " will use the supplied regex text to search for test methods (excluding methods " + "with the @Ignore annotation) and run only those methods. Can be paired with " + METHOD_REPEAT_FILTER + " to " - + "repeat the selected tests multiple times.\n"); - helpMessage.append( - "\t" + + "repeat the selected tests multiple times.\n" + + "\t" + METHOD_REPEAT_FILTER + " will repeat the tests selected with either " + QUICK_TEST_FLAG + " or " + CLASS_NAME_FILTER - + " and run them the given number of times.\n"); - helpMessage.append( - "[NOTE] All regex uses the syntax defined by java.util.regex.Pattern. This " + + " and run them the given number of times.\n" + + "[NOTE] All regex uses the syntax defined by java.util.regex.Pattern. This " + "documentation can be found at " - + "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html\n"); - helpMessage.append("\n"); - helpMessage.append("\n"); + + "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html\n" + + "\n" + + "\n"; TestBench.out().println(helpMessage); } @@ -122,7 +118,7 @@ protected static void displayInvalidUsage(String message, String... args) { StringBuilder invalidMessage = new StringBuilder("Invalid Usage: " + message + "\n"); invalidMessage.append("Params received: "); for (String a : args) { - invalidMessage.append(a + " "); + invalidMessage.append(a).append(" "); } invalidMessage.append("\n"); invalidMessage.append( @@ -144,9 +140,9 @@ protected static void printLoadedTests(final Class... classes) { for (Class c : classes) { if (c.getPackage().equals(packagE)) { packagE = c.getPackage(); - loadedTestsMessage.append(packagE.getName() + "\n"); + loadedTestsMessage.append(packagE.getName()).append("\n"); } - loadedTestsMessage.append("\t" + c.getSimpleName() + "\n"); + loadedTestsMessage.append("\t").append(c.getSimpleName()).append("\n"); } TestBench.out().println(loadedTestsMessage); } @@ -192,7 +188,7 @@ protected static Result parseArgsRunAndGetResult(final String[] args) { } } - ArrayList argsParsed = new ArrayList(List.of(args)); + ArrayList argsParsed = new ArrayList<>(List.of(args)); if (argsParsed.contains(HELP_FLAG)) { // If the user inputs the help flag then return the help message and exit // without running any tests @@ -256,7 +252,7 @@ void addResult(Result result) { // If a specific method has been requested if (methodFilter) { List pairs = (new TestSuite()).getMethodMatching(methodRegex); - if (pairs.size() == 0) { + if (pairs.isEmpty()) { displayInvalidUsage( "None of the arguments passed to the method name filter matched.", args); return null; @@ -291,7 +287,7 @@ void addResult(Result result) { // If a specific class has been requested if (classFilter) { List> testClasses = (new TestSuite()).getSuiteOrTestMatchingRegex(classRegex); - if (testClasses.size() == 0) { + if (testClasses.isEmpty()) { displayInvalidUsage("None of the arguments passed to the filter matched.", args); return null; } diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java index 1bf8ae9d465..e3aa90aa4b7 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java @@ -107,14 +107,12 @@ public LinearQuadraticRegulator( var discB = discABPair.getSecond(); if (!StateSpaceUtil.isStabilizable(discA, discB)) { - var builder = new StringBuilder("The system passed to the LQR is uncontrollable!\n\nA =\n"); - builder - .append(discA.getStorage().toString()) - .append("\nB =\n") - .append(discB.getStorage().toString()) - .append('\n'); - - var msg = builder.toString(); + var msg = + "The system passed to the LQR is uncontrollable!\n\nA =\n" + + discA.getStorage().toString() + + "\nB =\n" + + discB.getStorage().toString() + + '\n'; MathSharedStore.reportError(msg, Thread.currentThread().getStackTrace()); throw new IllegalArgumentException(msg); } diff --git a/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java index 0817c30b987..d74db4e4d99 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java @@ -82,15 +82,12 @@ public KalmanFilter( var C = plant.getC(); if (!StateSpaceUtil.isDetectable(discA, C)) { - var builder = - new StringBuilder("The system passed to the Kalman filter is unobservable!\n\nA =\n"); - builder - .append(discA.getStorage().toString()) - .append("\nC =\n") - .append(C.getStorage().toString()) - .append('\n'); - - var msg = builder.toString(); + var msg = + "The system passed to the Kalman filter is unobservable!\n\nA =\n" + + discA.getStorage().toString() + + "\nC =\n" + + C.getStorage().toString() + + '\n'; MathSharedStore.reportError(msg, Thread.currentThread().getStackTrace()); throw new IllegalArgumentException(msg); } 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 64dbb3faa8e..bf31ae7293b 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 @@ -81,15 +81,12 @@ public SteadyStateKalmanFilter( var C = plant.getC(); if (!StateSpaceUtil.isDetectable(discA, C)) { - var builder = - new StringBuilder("The system passed to the Kalman filter is unobservable!\n\nA =\n"); - builder - .append(discA.getStorage().toString()) - .append("\nC =\n") - .append(C.getStorage().toString()) - .append('\n'); - - var msg = builder.toString(); + var msg = + "The system passed to the Kalman filter is unobservable!\n\nA =\n" + + discA.getStorage().toString() + + "\nC =\n" + + C.getStorage().toString() + + '\n'; MathSharedStore.reportError(msg, Thread.currentThread().getStackTrace()); throw new IllegalArgumentException(msg); } diff --git a/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java index ee547f74839..25473c0927b 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java @@ -117,19 +117,15 @@ public Rotation3d(Matrix rotationMatrix) { // Require that the rotation matrix is special orthogonal. This is true if // the matrix is orthogonal (RRᵀ = I) and normalized (determinant is 1). if (R.times(R.transpose()).minus(Matrix.eye(Nat.N3())).normF() > 1e-9) { - var builder = new StringBuilder("Rotation matrix isn't orthogonal\n\nR =\n"); - builder.append(R.getStorage().toString()).append('\n'); - - var msg = builder.toString(); + var msg = "Rotation matrix isn't orthogonal\n\nR =\n" + R.getStorage().toString() + '\n'; MathSharedStore.reportError(msg, Thread.currentThread().getStackTrace()); throw new IllegalArgumentException(msg); } if (Math.abs(R.det() - 1.0) > 1e-9) { - var builder = - new StringBuilder("Rotation matrix is orthogonal but not special orthogonal\n\nR =\n"); - builder.append(R.getStorage().toString()).append('\n'); - - var msg = builder.toString(); + var msg = + "Rotation matrix is orthogonal but not special orthogonal\n\nR =\n" + + R.getStorage().toString() + + '\n'; MathSharedStore.reportError(msg, Thread.currentThread().getStackTrace()); throw new IllegalArgumentException(msg); } 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 7eea7024a95..1b885fb7cfb 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 @@ -87,7 +87,7 @@ public Pose2d[] solve(Pose2d[] poses, int iterations) { * array. */ private Vector neighbor(Vector state) { - var proposedState = new Vector(state); + var proposedState = new Vector<>(state); int rangeStart = (int) (Math.random() * (state.getNumRows() - 1)); int rangeEnd = (int) (Math.random() * (state.getNumRows() - 1)); diff --git a/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java b/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java index 8f93661f995..b1788576315 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java @@ -128,13 +128,8 @@ private SimpleMatrix makeHermiteBasis() { // [a₀] = [ 1 0 0 0][P'(i+1)] hermiteBasis = new SimpleMatrix( - 4, - 4, - true, - new double[] { - +2.0, +1.0, -2.0, +1.0, -3.0, -2.0, +3.0, -1.0, +0.0, +1.0, +0.0, +0.0, +1.0, +0.0, - +0.0, +0.0 - }); + 4, 4, true, +2.0, +1.0, -2.0, +1.0, -3.0, -2.0, +3.0, -1.0, +0.0, +1.0, +0.0, +0.0, + +1.0, +0.0, +0.0, +0.0); } return hermiteBasis; } @@ -152,12 +147,6 @@ private SimpleMatrix getControlVectorFromArrays(double[] initialVector, double[] throw new IllegalArgumentException("Size of vectors must be 2 or greater."); } return new SimpleMatrix( - 4, - 1, - true, - new double[] { - initialVector[0], initialVector[1], - finalVector[0], finalVector[1] - }); + 4, 1, true, initialVector[0], initialVector[1], finalVector[0], finalVector[1]); } } diff --git a/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java b/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java index 6d9ded02430..af162456fd0 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java @@ -135,14 +135,10 @@ private SimpleMatrix makeHermiteBasis() { // [a₀] = [ 1.0 0.0 0.0 0.0 0.0 0.0][P"(i+1)] hermiteBasis = new SimpleMatrix( - 6, - 6, - true, - new double[] { - -06.0, -03.0, -00.5, +06.0, -03.0, +00.5, +15.0, +08.0, +01.5, -15.0, +07.0, -01.0, - -10.0, -06.0, -01.5, +10.0, -04.0, +00.5, +00.0, +00.0, +00.5, +00.0, +00.0, +00.0, - +00.0, +01.0, +00.0, +00.0, +00.0, +00.0, +01.0, +00.0, +00.0, +00.0, +00.0, +00.0 - }); + 6, 6, true, -06.0, -03.0, -00.5, +06.0, -03.0, +00.5, +15.0, +08.0, +01.5, -15.0, + +07.0, -01.0, -10.0, -06.0, -01.5, +10.0, -04.0, +00.5, +00.0, +00.0, +00.5, +00.0, + +00.0, +00.0, +00.0, +01.0, +00.0, +00.0, +00.0, +00.0, +01.0, +00.0, +00.0, +00.0, + +00.0, +00.0); } return hermiteBasis; } @@ -163,9 +159,11 @@ private SimpleMatrix getControlVectorFromArrays(double[] initialVector, double[] 6, 1, true, - new double[] { - initialVector[0], initialVector[1], initialVector[2], - finalVector[0], finalVector[1], finalVector[2] - }); + initialVector[0], + initialVector[1], + initialVector[2], + finalVector[0], + finalVector[1], + finalVector[2]); } } diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java index 1580e853c77..e0ed9de9a18 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java @@ -208,14 +208,12 @@ public State calculateInflectionPoint(State current, State goal) { * @return The position and velocity of the profile at the inflection point. */ private State calculateInflectionPoint(State current, State goal, double input) { - var u = input; - if (current.equals(goal)) { return current; } - var inflectionVelocity = solveForInflectionVelocity(u, current, goal); - var inflectionPosition = computeDistanceFromVelocity(inflectionVelocity, -u, goal); + var inflectionVelocity = solveForInflectionVelocity(input, current, goal); + var inflectionPosition = computeDistanceFromVelocity(inflectionVelocity, -input, goal); return new State(inflectionPosition, inflectionVelocity); } @@ -261,8 +259,6 @@ public ProfileTiming calculateProfileTiming(State current, State goal) { */ private ProfileTiming calculateProfileTiming( State current, State inflectionPoint, State goal, double input) { - var u = input; - double inflectionT_forward; // We need to handle 5 cases here: @@ -287,13 +283,13 @@ private ProfileTiming calculateProfileTiming( x_at_solvable_v = current.position; } else { if (Math.abs(current.velocity) > m_constraints.maxVelocity()) { - solvableV += Math.signum(u) * epsilon; + solvableV += Math.signum(input) * epsilon; } else { - solvableV -= Math.signum(u) * epsilon; + solvableV -= Math.signum(input) * epsilon; } - t_to_solvable_v = computeTimeFromVelocity(solvableV, u, current.velocity); - x_at_solvable_v = computeDistanceFromVelocity(solvableV, u, current); + t_to_solvable_v = computeTimeFromVelocity(solvableV, input, current.velocity); + x_at_solvable_v = computeDistanceFromVelocity(solvableV, input, current); } inflectionT_forward = @@ -302,10 +298,12 @@ private ProfileTiming calculateProfileTiming( * (inflectionPoint.position - x_at_solvable_v) / m_constraints.maxVelocity(); } else { - inflectionT_forward = computeTimeFromVelocity(inflectionPoint.velocity, u, current.velocity); + inflectionT_forward = + computeTimeFromVelocity(inflectionPoint.velocity, input, current.velocity); } - var inflectionT_backward = computeTimeFromVelocity(inflectionPoint.velocity, -u, goal.velocity); + var inflectionT_backward = + computeTimeFromVelocity(inflectionPoint.velocity, -input, goal.velocity); return new ProfileTiming(inflectionT_forward, inflectionT_forward - inflectionT_backward); } @@ -321,10 +319,9 @@ private ProfileTiming calculateProfileTiming( private double computeDistanceFromTime(double t, double input, State initial) { var A = m_constraints.A; var B = m_constraints.B; - var u = input; return initial.position - + (-B * u * t + (initial.velocity + B * u / A) * (Math.exp(A * t) - 1)) / A; + + (-B * input * t + (initial.velocity + B * input / A) * (Math.exp(A * t) - 1)) / A; } /** @@ -338,9 +335,8 @@ private double computeDistanceFromTime(double t, double input, State initial) { private double computeVelocityFromTime(double t, double input, State initial) { var A = m_constraints.A; var B = m_constraints.B; - var u = input; - return (initial.velocity + B * u / A) * Math.exp(A * t) - B * u / A; + return (initial.velocity + B * input / A) * Math.exp(A * t) - B * input / A; } /** @@ -354,9 +350,8 @@ private double computeVelocityFromTime(double t, double input, State initial) { private double computeTimeFromVelocity(double velocity, double input, double initial) { var A = m_constraints.A; var B = m_constraints.B; - var u = input; - return Math.log((A * velocity + B * u) / (A * initial + B * u)) / A; + return Math.log((A * velocity + B * input) / (A * initial + B * input)) / A; } /** @@ -371,11 +366,13 @@ private double computeTimeFromVelocity(double velocity, double input, double ini private double computeDistanceFromVelocity(double velocity, double input, State initial) { var A = m_constraints.A; var B = m_constraints.B; - var u = input; return initial.position + (velocity - initial.velocity) / A - - B * u / (A * A) * Math.log((A * velocity + B * u) / (A * initial.velocity + B * u)); + - B + * input + / (A * A) + * Math.log((A * velocity + B * input) / (A * initial.velocity + B * input)); } /** @@ -390,18 +387,17 @@ private double computeDistanceFromVelocity(double velocity, double input, State private double solveForInflectionVelocity(double input, State current, State goal) { var A = m_constraints.A; var B = m_constraints.B; - var u = input; - var U_dir = Math.signum(u); + var U_dir = Math.signum(input); var position_delta = goal.position - current.position; var velocity_delta = goal.velocity - current.velocity; - var scalar = (A * current.velocity + B * u) * (A * goal.velocity - B * u); - var power = -A / B / u * (A * position_delta - velocity_delta); + var scalar = (A * current.velocity + B * input) * (A * goal.velocity - B * input); + var power = -A / B / input * (A * position_delta - velocity_delta); var a = -A * A; - var c = (B * B) * (u * u) + scalar * Math.exp(power); + var c = (B * B) * (input * input) + scalar * Math.exp(power); if (-1e-9 < c && c < 0) { // Numerical stability issue - the heuristic gets it right but c is around -1e-13 diff --git a/wpimath/src/test/java/edu/wpi/first/math/DARETest.java b/wpimath/src/test/java/edu/wpi/first/math/DARETest.java index 0d697bdd27d..50ff38a940b 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/DARETest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/DARETest.java @@ -42,8 +42,7 @@ void assertDARESolution( .times((B.transpose().times(X).times(B).plus(R)).inv()) .times(B.transpose().times(X).times(A))) .plus(Q); - assertMatrixEqual( - new Matrix(new SimpleMatrix(Y.getNumRows(), Y.getNumCols())), Y); + assertMatrixEqual(new Matrix<>(new SimpleMatrix(Y.getNumRows(), Y.getNumCols())), Y); } void assertDARESolution( @@ -63,8 +62,7 @@ void assertDARESolution( .times((B.transpose().times(X).times(B).plus(R)).inv()) .times(B.transpose().times(X).times(A).plus(N.transpose()))) .plus(Q); - assertMatrixEqual( - new Matrix(new SimpleMatrix(Y.getNumRows(), Y.getNumCols())), Y); + assertMatrixEqual(new Matrix<>(new SimpleMatrix(Y.getNumRows(), Y.getNumCols())), Y); } @Test diff --git a/wpimath/src/test/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforwardTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforwardTest.java index 60300fb838b..b5e808a5ef2 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforwardTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforwardTest.java @@ -18,8 +18,7 @@ class ControlAffinePlantInversionFeedforwardTest { @Test void testCalculate() { ControlAffinePlantInversionFeedforward feedforward = - new ControlAffinePlantInversionFeedforward( - Nat.N2(), Nat.N1(), this::getDynamics, 0.02); + new ControlAffinePlantInversionFeedforward<>(Nat.N2(), Nat.N1(), this::getDynamics, 0.02); assertEquals( 48.0, feedforward.calculate(VecBuilder.fill(2, 2), VecBuilder.fill(3, 3)).get(0, 0), 1e-6); @@ -28,8 +27,7 @@ void testCalculate() { @Test void testCalculateState() { ControlAffinePlantInversionFeedforward feedforward = - new ControlAffinePlantInversionFeedforward( - Nat.N2(), Nat.N1(), this::getDynamics, 0.02); + new ControlAffinePlantInversionFeedforward<>(Nat.N2(), Nat.N1(), this::getDynamics, 0.02); assertEquals( 48.0, feedforward.calculate(VecBuilder.fill(2, 2), VecBuilder.fill(3, 3)).get(0, 0), 1e-6); diff --git a/wpimath/src/test/java/edu/wpi/first/math/controller/ImplicitModelFollowerTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/ImplicitModelFollowerTest.java index cfcc71d1ee2..90f21275592 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/controller/ImplicitModelFollowerTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/ImplicitModelFollowerTest.java @@ -21,7 +21,7 @@ void testSameModel() { var plant = LinearSystemId.identifyDrivetrainSystem(1.0, 1.0, 1.0, 1.0); - var imf = new ImplicitModelFollower(plant, plant); + var imf = new ImplicitModelFollower<>(plant, plant); Matrix x = VecBuilder.fill(0.0, 0.0); Matrix xImf = VecBuilder.fill(0.0, 0.0); @@ -66,7 +66,7 @@ void testSlowerRefModel() { // Linear acceleration is slower, but angular acceleration is the same var plantRef = LinearSystemId.identifyDrivetrainSystem(1.0, 2.0, 1.0, 1.0); - var imf = new ImplicitModelFollower(plant, plantRef); + var imf = new ImplicitModelFollower<>(plant, plantRef); Matrix x = VecBuilder.fill(0.0, 0.0); Matrix xImf = VecBuilder.fill(0.0, 0.0); diff --git a/wpimath/src/test/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforwardTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforwardTest.java index eb8d36a503b..8901330d138 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforwardTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforwardTest.java @@ -21,7 +21,7 @@ void testCalculate() { Matrix B = VecBuilder.fill(0, 1); LinearPlantInversionFeedforward feedforward = - new LinearPlantInversionFeedforward(A, B, 0.02); + new LinearPlantInversionFeedforward<>(A, B, 0.02); assertEquals( 47.502599, diff --git a/wpimath/src/test/java/edu/wpi/first/math/filter/LinearFilterTest.java b/wpimath/src/test/java/edu/wpi/first/math/filter/LinearFilterTest.java index ec43cd578ae..72ea1743f14 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/filter/LinearFilterTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/filter/LinearFilterTest.java @@ -129,9 +129,9 @@ void centralFiniteDifferenceTest() { 1, 3, // f(x) = sin(x) - (double x) -> Math.sin(x), + Math::sin, // df/dx = cos(x) - (double x) -> Math.cos(x), + Math::cos, h, -20.0, 20.0); @@ -140,7 +140,7 @@ void centralFiniteDifferenceTest() { 1, 3, // f(x) = ln(x) - (double x) -> Math.log(x), + Math::log, // df/dx = 1/x (double x) -> 1.0 / x, h, @@ -162,7 +162,7 @@ void centralFiniteDifferenceTest() { 2, 5, // f(x) = sin(x) - (double x) -> Math.sin(x), + Math::sin, // d²f/dx² = -sin(x) (double x) -> -Math.sin(x), h, @@ -173,7 +173,7 @@ void centralFiniteDifferenceTest() { 2, 5, // f(x) = ln(x) - (double x) -> Math.log(x), + Math::log, // d²f/dx² = -1/x² (double x) -> -1.0 / (x * x), h, @@ -201,9 +201,9 @@ void backwardFiniteDifferenceTest() { 1, 2, // f(x) = sin(x) - (double x) -> Math.sin(x), + Math::sin, // df/dx = cos(x) - (double x) -> Math.cos(x), + Math::cos, h, -20.0, 20.0); @@ -212,7 +212,7 @@ void backwardFiniteDifferenceTest() { 1, 2, // f(x) = ln(x) - (double x) -> Math.log(x), + Math::log, // df/dx = 1/x (double x) -> 1.0 / x, h, @@ -234,7 +234,7 @@ void backwardFiniteDifferenceTest() { 2, 4, // f(x) = sin(x) - (double x) -> Math.sin(x), + Math::sin, // d²f/dx² = -sin(x) (double x) -> -Math.sin(x), h, @@ -245,7 +245,7 @@ void backwardFiniteDifferenceTest() { 2, 4, // f(x) = ln(x) - (double x) -> Math.log(x), + Math::log, // d²f/dx² = -1/x² (double x) -> -1.0 / (x * x), h, diff --git a/wpimath/src/test/java/edu/wpi/first/math/optimization/SimulatedAnnealingTest.java b/wpimath/src/test/java/edu/wpi/first/math/optimization/SimulatedAnnealingTest.java index d051b4328d0..baf9275dbb0 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/optimization/SimulatedAnnealingTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/optimization/SimulatedAnnealingTest.java @@ -21,7 +21,7 @@ void testDoubleFunctionOptimizationHeartBeat() { new SimulatedAnnealing( 2.0, x -> MathUtil.clamp(x + (Math.random() - 0.5) * stepSize, -3, 3), - x -> function.applyAsDouble(x)); + function::applyAsDouble); double solution = simulatedAnnealing.solve(-1.0, 5000); @@ -38,7 +38,7 @@ void testDoubleFunctionOptimizationMultimodal() { new SimulatedAnnealing( 2.0, x -> MathUtil.clamp(x + (Math.random() - 0.5) * stepSize, 0, 7), - x -> function.applyAsDouble(x)); + function::applyAsDouble); double solution = simulatedAnnealing.solve(-1.0, 5000); diff --git a/wpimath/src/test/java/edu/wpi/first/math/system/NumericalIntegrationTest.java b/wpimath/src/test/java/edu/wpi/first/math/system/NumericalIntegrationTest.java index 9b47148bf90..a0c7689cb03 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/system/NumericalIntegrationTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/system/NumericalIntegrationTest.java @@ -34,12 +34,7 @@ void testExponential() { void testZeroRKDP() { var y1 = NumericalIntegration.rkdp( - (x, u) -> { - return VecBuilder.fill(0); - }, - VecBuilder.fill(0), - VecBuilder.fill(0), - 0.1); + (x, u) -> VecBuilder.fill(0), VecBuilder.fill(0), VecBuilder.fill(0), 0.1); assertEquals(0.0, y1.get(0, 0), 1e-3); } diff --git a/wpimath/src/test/java/edu/wpi/first/math/system/RungeKuttaTimeVaryingTest.java b/wpimath/src/test/java/edu/wpi/first/math/system/RungeKuttaTimeVaryingTest.java index e0757eafe8b..bb28b73a9aa 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/system/RungeKuttaTimeVaryingTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/system/RungeKuttaTimeVaryingTest.java @@ -31,10 +31,9 @@ void rungeKuttaTimeVaryingTest() { final var y1 = RungeKuttaTimeVarying.rungeKuttaTimeVarying( - (Double t, Matrix x) -> { - return MatBuilder.fill( - Nat.N1(), Nat.N1(), x.get(0, 0) * (2.0 / (Math.exp(t) + 1.0) - 1.0)); - }, + (Double t, Matrix x) -> + MatBuilder.fill( + Nat.N1(), Nat.N1(), x.get(0, 0) * (2.0 / (Math.exp(t) + 1.0) - 1.0)), 5.0, y0, 1.0); diff --git a/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveVoltageConstraintTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveVoltageConstraintTest.java index 917edb45fa8..58ee8305b16 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveVoltageConstraintTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveVoltageConstraintTest.java @@ -11,7 +11,6 @@ import edu.wpi.first.math.controller.SimpleMotorFeedforward; import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.geometry.Rotation2d; -import edu.wpi.first.math.geometry.Translation2d; import edu.wpi.first.math.kinematics.ChassisSpeeds; import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; import edu.wpi.first.math.trajectory.constraint.DifferentialDriveVoltageConstraint; @@ -89,7 +88,7 @@ void testEndpointHighCurvature() { () -> TrajectoryGenerator.generateTrajectory( new Pose2d(1, 0, Rotation2d.fromDegrees(90)), - new ArrayList(), + new ArrayList<>(), new Pose2d(0, 1, Rotation2d.fromDegrees(180)), config)); @@ -97,7 +96,7 @@ void testEndpointHighCurvature() { () -> TrajectoryGenerator.generateTrajectory( new Pose2d(0, 1, Rotation2d.fromDegrees(180)), - new ArrayList(), + new ArrayList<>(), new Pose2d(1, 0, Rotation2d.fromDegrees(90)), config.setReversed(true))); } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/CombinedRuntimeLoader.java b/wpiutil/src/main/java/edu/wpi/first/util/CombinedRuntimeLoader.java index 09e739da943..23149bd3817 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/CombinedRuntimeLoader.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/CombinedRuntimeLoader.java @@ -59,8 +59,7 @@ private static String getLoadErrorMessage(String libraryName, UnsatisfiedLinkErr @SuppressWarnings("unchecked") public static List extractLibraries(Class clazz, String resourceName) throws IOException { - TypeReference> typeRef = - new TypeReference>() {}; + TypeReference> typeRef = new TypeReference<>() {}; ObjectMapper mapper = new ObjectMapper(); Map map; try (var stream = clazz.getResourceAsStream(resourceName)) { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/cleanup/CleanupPool.java b/wpiutil/src/main/java/edu/wpi/first/util/cleanup/CleanupPool.java index fab83166267..0ae5200e8c4 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/cleanup/CleanupPool.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/cleanup/CleanupPool.java @@ -14,7 +14,7 @@ public class CleanupPool implements AutoCloseable { // Use a Deque instead of a Stack, as Stack's iterators go the wrong way, and docs // state ArrayDeque is faster anyway. - private final Deque m_closers = new ArrayDeque(); + private final Deque m_closers = new ArrayDeque<>(); /** * Registers an object in the object stack for cleanup. diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java b/wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java index 1db2647b58f..9e7fa43b344 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java @@ -37,7 +37,7 @@ private ProtobufLogEntry( */ public static > ProtobufLogEntry create( DataLog log, String name, Protobuf proto, String metadata, long timestamp) { - return new ProtobufLogEntry(log, name, proto, metadata, timestamp); + return new ProtobufLogEntry<>(log, name, proto, metadata, timestamp); } /** diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java b/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java index 0f6cb2e7d03..b3a31c9a52e 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java @@ -35,7 +35,7 @@ private StructArrayLogEntry( */ public static StructArrayLogEntry create( DataLog log, String name, Struct struct, String metadata, long timestamp) { - return new StructArrayLogEntry(log, name, struct, metadata, timestamp); + return new StructArrayLogEntry<>(log, name, struct, metadata, timestamp); } /** diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java b/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java index a227c32d8bc..0d09182315e 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java @@ -34,7 +34,7 @@ private StructLogEntry( */ public static StructLogEntry create( DataLog log, String name, Struct struct, String metadata, long timestamp) { - return new StructLogEntry(log, name, struct, metadata, timestamp); + return new StructLogEntry<>(log, name, struct, metadata, timestamp); } /** diff --git a/wpiutil/src/main/java/edu/wpi/first/util/protobuf/ProtobufBuffer.java b/wpiutil/src/main/java/edu/wpi/first/util/protobuf/ProtobufBuffer.java index 334cb161c9c..ae03c633002 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/protobuf/ProtobufBuffer.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/protobuf/ProtobufBuffer.java @@ -28,7 +28,7 @@ private ProtobufBuffer(Protobuf proto) { public static > ProtobufBuffer create( Protobuf proto) { - return new ProtobufBuffer(proto); + return new ProtobufBuffer<>(proto); } /** diff --git a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructBuffer.java b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructBuffer.java index 0e8aa187d25..8bd5768f09e 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructBuffer.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructBuffer.java @@ -22,7 +22,7 @@ private StructBuffer(Struct struct) { } public static StructBuffer create(Struct struct) { - return new StructBuffer(struct); + return new StructBuffer<>(struct); } /** diff --git a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java index be7343fcfea..1eb58c9baf0 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/struct/StructDescriptorDatabase.java @@ -33,7 +33,7 @@ public StructDescriptor add(String name, String schema) throws BadSchemaExceptio } // turn parsed schema into descriptors - StructDescriptor theStruct = m_structs.computeIfAbsent(name, k -> new StructDescriptor(k)); + StructDescriptor theStruct = m_structs.computeIfAbsent(name, StructDescriptor::new); theStruct.m_schema = schema; theStruct.m_fields.clear(); boolean isValid = true; @@ -76,7 +76,7 @@ public StructDescriptor add(String name, String schema) throws BadSchemaExceptio // cross-reference struct, creating a placeholder if necessary StructDescriptor aStruct = - m_structs.computeIfAbsent(decl.typeString, k -> new StructDescriptor(k)); + m_structs.computeIfAbsent(decl.typeString, StructDescriptor::new); // if the struct isn't valid, we can't be valid either if (aStruct.isValid()) { diff --git a/wpiutil/src/test/java/edu/wpi/first/util/struct/parser/ParserTest.java b/wpiutil/src/test/java/edu/wpi/first/util/struct/parser/ParserTest.java index 52ba8dafcff..b985b2ae2bc 100644 --- a/wpiutil/src/test/java/edu/wpi/first/util/struct/parser/ParserTest.java +++ b/wpiutil/src/test/java/edu/wpi/first/util/struct/parser/ParserTest.java @@ -15,21 +15,21 @@ class ParserTest { @Test void testEmpty() { Parser p = new Parser(""); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertTrue(schema.declarations.isEmpty()); } @Test void testEmptySemicolon() { Parser p = new Parser(";"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertTrue(schema.declarations.isEmpty()); } @Test void testSimple() { Parser p = new Parser("int32 a"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -40,14 +40,14 @@ void testSimple() { @Test void testSimpleTrailingSemi() { Parser p = new Parser("int32 a;"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); } @Test void testArray() { Parser p = new Parser("int32 a[2]"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -58,14 +58,14 @@ void testArray() { @Test void testArrayTrailingSemi() { Parser p = new Parser("int32 a[2];"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); } @Test void testBitfield() { Parser p = new Parser("int32 a:2"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -76,14 +76,14 @@ void testBitfield() { @Test void testBitfieldTrailingSemi() { Parser p = new Parser("int32 a:2;"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); } @Test void testEnumKeyword() { Parser p = new Parser("enum {x=1} int32 a;"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -95,7 +95,7 @@ void testEnumKeyword() { @Test void testEnumNoKeyword() { Parser p = new Parser("{x=1} int32 a;"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -107,7 +107,7 @@ void testEnumNoKeyword() { @Test void testEnumNoValues() { Parser p = new Parser("{} int32 a;"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -118,7 +118,7 @@ void testEnumNoValues() { @Test void testEnumMultipleValues() { Parser p = new Parser("{x=1,y=-2} int32 a;"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -131,7 +131,7 @@ void testEnumMultipleValues() { @Test void testEnumTrailingComma() { Parser p = new Parser("{x=1,y=2,} int32 a;"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 1); var decl = schema.declarations.get(0); assertEquals(decl.typeString, "int32"); @@ -144,7 +144,7 @@ void testEnumTrailingComma() { @Test void testMultipleNoTrailingSemi() { Parser p = new Parser("int32 a; int16 b"); - ParsedSchema schema = assertDoesNotThrow(() -> p.parse()); + ParsedSchema schema = assertDoesNotThrow(p::parse); assertEquals(schema.declarations.size(), 2); assertEquals(schema.declarations.get(0).typeString, "int32"); assertEquals(schema.declarations.get(0).name, "a"); @@ -155,58 +155,55 @@ void testMultipleNoTrailingSemi() { @Test void testErrBitfieldArray() { Parser p = new Parser("int32 a[1]:2"); - assertThrows(ParseException.class, () -> p.parse(), "10: expected ';', got ':'"); + assertThrows(ParseException.class, p::parse, "10: expected ';', got ':'"); } @Test void testErrNoArrayValue() { Parser p = new Parser("int32 a[]"); - assertThrows(ParseException.class, () -> p.parse(), "8: expected integer, got ']'"); + assertThrows(ParseException.class, p::parse, "8: expected integer, got ']'"); } @Test void testErrNoBitfieldValue() { Parser p = new Parser("int32 a:"); - assertThrows(ParseException.class, () -> p.parse(), "8: expected integer, got ''"); + assertThrows(ParseException.class, p::parse, "8: expected integer, got ''"); } @Test void testErrNoNameArray() { Parser p = new Parser("int32 [2]"); - assertThrows(ParseException.class, () -> p.parse(), "6: expected identifier, got '['"); + assertThrows(ParseException.class, p::parse, "6: expected identifier, got '['"); } @Test void testErrNoNameBitField() { Parser p = new Parser("int32 :2"); - assertThrows(ParseException.class, () -> p.parse(), "6: expected identifier, got ':'"); + assertThrows(ParseException.class, p::parse, "6: expected identifier, got ':'"); } @Test void testNegativeBitField() { Parser p = new Parser("int32 a:-1"); assertThrows( - ParseException.class, () -> p.parse(), "8: bitfield width '-1' is not a positive integer"); + ParseException.class, p::parse, "8: bitfield width '-1' is not a positive integer"); } @Test void testNegativeArraySize() { Parser p = new Parser("int32 a[-1]"); - assertThrows( - ParseException.class, () -> p.parse(), "8: array size '-1' is not a positive integer"); + assertThrows(ParseException.class, p::parse, "8: array size '-1' is not a positive integer"); } @Test void testZeroBitField() { Parser p = new Parser("int32 a:0"); - assertThrows( - ParseException.class, () -> p.parse(), "8: bitfield width '0' is not a positive integer"); + assertThrows(ParseException.class, p::parse, "8: bitfield width '0' is not a positive integer"); } @Test void testZeroArraySize() { Parser p = new Parser("int32 a[0]"); - assertThrows( - ParseException.class, () -> p.parse(), "8: array size '0' is not a positive integer"); + assertThrows(ParseException.class, p::parse, "8: array size '0' is not a positive integer"); } }