From df12fc2a869c4e0a1307c570825e87f1832edd70 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Thu, 1 Aug 2019 01:19:48 -0400 Subject: [PATCH] Java cleanups (#1776) * Remove extra ';'s * Remove unnecessary conversions to String * Use StandardCharsets object * Replace infinite while with check for interrupted thread * Remove redundant local vars * Remove redundant throws clause * Remove redundant primitive wrapping * Fix malformed Nested class test * Remove unnecessary unboxing * Remove unnecessary explicit type argument * Replace lambdas with method references * Replace statement lambdas with expression lambdas * Replace null check with method call * Replace number comparison with method call * Fix broken javadoc comments * Replace Arrays.asList with singletonLists * Remove excessive lambda usage * Remove redundant string operation * Remove redundant type casts * Remove unnecessary returns * Remove redundant suppressions * Fix unresolved file reference * static analysis fixes --- CONTRIBUTING.md | 2 +- .../wpi/first/cameraserver/CameraServer.java | 11 ++++----- .../edu/wpi/first/vision/VisionRunner.java | 6 ++--- .../java/edu/wpi/cscore/UsbCameraTest.java | 14 ++++------- .../first/hal/can/CANExceptionFactory.java | 7 +++--- .../wpi/first/networktables/NetworkTable.java | 6 ++--- .../networktables/NetworkTableEntry.java | 8 +++---- .../networktables/NetworkTableValue.java | 4 ++-- .../first/networktables/NetworkTableTest.java | 7 +++--- .../edu/wpi/first/wpilibj/DriverStation.java | 2 +- .../wpilibj/InterruptableSensorBase.java | 9 ++++--- .../edu/wpi/first/wpilibj/IterativeRobot.java | 4 ++-- .../edu/wpi/first/wpilibj/SerialPort.java | 10 ++------ .../java/edu/wpi/first/wpilibj/Timer.java | 3 +-- .../java/edu/wpi/first/wpilibj/Watchdog.java | 17 ++++--------- .../wpilibj/controller/PIDController.java | 2 +- .../smartdashboard/SendableChooser.java | 8 ++----- .../wpilibj/trajectory/TrapezoidProfile.java | 1 - .../first/wpilibj/vision/VisionRunner.java | 6 ++--- .../first/wpilibj/MockHardwareExtension.java | 4 ++-- .../first/wpilibj/TrapezoidProfileTest.java | 2 +- .../wpi/first/wpilibj/UtilityClassTest.java | 4 ++-- .../edu/wpi/first/wpilibj/WatchdogTest.java | 24 +++++-------------- .../gearsbot/subsystems/Elevator.java | 4 ++-- .../examples/gearsbot/subsystems/Wrist.java | 4 ++-- .../first/wpilibj/examples/pacgoat/Robot.java | 6 ++--- .../templates/robotbaseskeleton/Robot.java | 2 +- .../first/wpilibj/AbstractInterruptTest.java | 4 ++-- .../first/wpilibj/AnalogCrossConnectTest.java | 8 +++---- .../wpilibj/AnalogPotentiometerTest.java | 4 ++-- .../edu/wpi/first/wpilibj/CounterTest.java | 8 +++---- .../first/wpilibj/DIOCrossConnectTest.java | 6 ++--- .../edu/wpi/first/wpilibj/EncoderTest.java | 8 +++---- .../java/edu/wpi/first/wpilibj/GyroTest.java | 6 ++--- .../wpi/first/wpilibj/MotorEncoderTest.java | 2 +- .../java/edu/wpi/first/wpilibj/PCMTest.java | 8 +++---- .../java/edu/wpi/first/wpilibj/PDPTest.java | 8 +++---- .../java/edu/wpi/first/wpilibj/PIDTest.java | 14 +++++------ .../first/wpilibj/RelayCrossConnectTest.java | 6 ++--- .../wpilibj/test/AbstractTestSuiteTest.java | 15 ++++++------ .../edu/wpi/first/wpilibj/test/TestBench.java | 23 +++++++----------- .../wpi/first/wpiutil/RuntimeDetector.java | 8 +++---- .../edu/wpi/first/wpiutil/RuntimeLoader.java | 4 +--- 43 files changed, 129 insertions(+), 180 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b25e4d4e28..fb9aab5b40 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,4 +53,4 @@ When you first submit changes, Travis-CI will attempt to run `./gradlew check` o ## Licensing -By contributing to WPILib, you agree that your code will be distributed with WPILib, and licensed under the license for the WPILib project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as WPILib is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](license.txt). +By contributing to WPILib, you agree that your code will be distributed with WPILib, and licensed under the license for the WPILib project. You should not contribute code that you do not have permission to relicense in this manner. This includes code that is licensed under the GPL that you do not have permission to relicense, as WPILib is not released under a copyleft license. Our license is the 3-clause BSD license, which you can find [here](LICENSE.txt). 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 401184f429..92af95a1c3 100644 --- a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java +++ b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Hashtable; import java.util.Map; +import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import edu.wpi.cscore.AxisCamera; @@ -170,13 +171,9 @@ public final class CameraServer { int sink = i.getHandle(); // Get the source's subtable (if none exists, we're done) - int source; - Integer fixedSource = m_fixedSources.get(sink); - if (fixedSource != null) { - source = fixedSource; - } else { - source = CameraServerJNI.getSinkSource(sink); - } + int source = Objects.requireNonNullElseGet(m_fixedSources.get(sink), + () -> CameraServerJNI.getSinkSource(sink)); + if (source == 0) { continue; } diff --git a/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java b/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java index 24ffcda560..8d8b12edc3 100644 --- a/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java +++ b/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -77,7 +77,7 @@ public class VisionRunner

{ public void runOnce() { Long id = CameraServerSharedStore.getCameraServerShared().getRobotMainThreadId(); - if (id != null && Thread.currentThread().getId() == id.longValue()) { + if (id != null && Thread.currentThread().getId() == id) { throw new IllegalStateException( "VisionRunner.runOnce() cannot be called from the main robot thread"); } @@ -110,7 +110,7 @@ public class VisionRunner

{ public void runForever() { Long id = CameraServerSharedStore.getCameraServerShared().getRobotMainThreadId(); - if (id != null && Thread.currentThread().getId() == id.longValue()) { + if (id != null && Thread.currentThread().getId() == id) { throw new IllegalStateException( "VisionRunner.runForever() cannot be called from the main robot thread"); } diff --git a/cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java b/cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java index b55dc4e88f..9df364506f 100644 --- a/cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java +++ b/cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -25,16 +25,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class UsbCameraTest { @Nested @EnabledOnOs(OS.LINUX) - static class ConnectVerbose { + class ConnectVerbose { @Test void setConnectVerboseEnabledTest() { try (UsbCamera camera = new UsbCamera("Nonexistant Camera", getNonexistentCameraDev())) { camera.setConnectVerbose(1); CompletableFuture result = new CompletableFuture<>(); - CameraServerJNI.setLogger((level, file, line, message) -> { - result.complete(message); - }, 20); + CameraServerJNI.setLogger((level, file, line, message) -> result.complete(message), 20); assertTimeoutPreemptively(Duration.ofSeconds(5), () -> assertTrue(result.get().contains("Connecting to USB camera on "))); @@ -47,9 +45,7 @@ class UsbCameraTest { camera.setConnectVerbose(0); CompletableFuture result = new CompletableFuture<>(); - CameraServerJNI.setLogger((level, file, line, message) -> { - result.complete(message); - }, 20); + CameraServerJNI.setLogger((level, file, line, message) -> result.complete(message), 20); assertThrows(TimeoutException.class, () -> result.get(3, TimeUnit.SECONDS)); @@ -60,6 +56,6 @@ class UsbCameraTest { private static int getNonexistentCameraDev() { return Arrays.stream(CameraServerJNI.enumerateUsbCameras()) .mapToInt(info -> info.dev) - .max().orElseGet(() -> -1) + 1; + .max().orElse(-1) + 1; } } diff --git a/hal/src/main/java/edu/wpi/first/hal/can/CANExceptionFactory.java b/hal/src/main/java/edu/wpi/first/hal/can/CANExceptionFactory.java index 132dae1827..dc089f8ecb 100644 --- a/hal/src/main/java/edu/wpi/first/hal/can/CANExceptionFactory.java +++ b/hal/src/main/java/edu/wpi/first/hal/can/CANExceptionFactory.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -32,13 +32,12 @@ public final class CANExceptionFactory { throw new CANMessageNotFoundException(); case ERR_CANSessionMux_NotAllowed: case NIRioStatus.kRIOStatusFeatureNotSupported: - throw new CANMessageNotAllowedException("MessageID = " + Integer.toString(messageID)); + throw new CANMessageNotAllowedException("MessageID = " + messageID); case ERR_CANSessionMux_NotInitialized: case NIRioStatus.kRIOStatusResourceNotInitialized: throw new CANNotInitializedException(); default: - throw new UncleanStatusException("Fatal status code detected: " + Integer.toString( - status)); + throw new UncleanStatusException("Fatal status code detected: " + status); } } diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java index 1cd21bf1d1..ad25f230aa 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTable.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -218,7 +218,7 @@ public final class NetworkTable { final int prefixLen = m_path.length() + 1; final NetworkTable parent = this; - return m_inst.addEntryListener(m_pathWithSep, new Consumer() { + return m_inst.addEntryListener(m_pathWithSep, new Consumer<>() { final Set m_notifiedTables = new HashSet<>(); @Override @@ -358,7 +358,7 @@ public final class NetworkTable { * * @param key the key * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type + * @return False if the table key exists with a different type */ boolean setDefaultValue(String key, NetworkTableValue defaultValue) { return getEntry(key).setDefaultValue(defaultValue); diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableEntry.java b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableEntry.java index 63ed984b4f..6eea5ca619 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableEntry.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableEntry.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -280,7 +280,7 @@ public final class NetworkTableEntry { switch (((NetworkTableValue) defaultValue).getType()) { case kBoolean: return NetworkTablesJNI.setDefaultBoolean(m_handle, time, - ((Boolean) otherValue).booleanValue()); + (Boolean) otherValue); case kDouble: return NetworkTablesJNI.setDefaultDouble(m_handle, time, ((Number) otherValue).doubleValue()); @@ -438,7 +438,7 @@ public final class NetworkTableEntry { Object otherValue = ((NetworkTableValue) value).getValue(); switch (((NetworkTableValue) value).getType()) { case kBoolean: - return NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean) otherValue).booleanValue(), + return NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue, false); case kDouble: return NetworkTablesJNI.setDouble(m_handle, time, ((Number) otherValue).doubleValue(), @@ -612,7 +612,7 @@ public final class NetworkTableEntry { Object otherValue = ((NetworkTableValue) value).getValue(); switch (((NetworkTableValue) value).getType()) { case kBoolean: - NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean) otherValue).booleanValue(), true); + NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue, true); return; case kDouble: NetworkTablesJNI.setDouble(m_handle, time, ((Number) otherValue).doubleValue(), true); diff --git a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableValue.java b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableValue.java index e1179ea328..eb7e2c229b 100644 --- a/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableValue.java +++ b/ntcore/src/main/java/edu/wpi/first/networktables/NetworkTableValue.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -153,7 +153,7 @@ public final class NetworkTableValue { if (m_type != NetworkTableType.kBoolean) { throw new ClassCastException("cannot convert " + m_type + " to boolean"); } - return ((Boolean) m_value).booleanValue(); + return (Boolean) m_value; } /** diff --git a/ntcore/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java b/ntcore/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java index e45f197cef..71ce0aeb2d 100644 --- a/ntcore/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java +++ b/ntcore/src/test/java/edu/wpi/first/networktables/NetworkTableTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -8,6 +8,7 @@ package edu.wpi.first.networktables; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Stream; @@ -65,8 +66,8 @@ class NetworkTableTest { private static Stream getHierarchyArguments() { return Stream.of( - Arguments.of(Arrays.asList("/"), ""), - Arguments.of(Arrays.asList("/"), "/"), + Arguments.of(Collections.singletonList("/"), ""), + Arguments.of(Collections.singletonList("/"), "/"), Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/baz"), "/foo/bar/baz"), Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/"), "/foo/bar/") ); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index 1bd261c819..366adbbc8d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -282,7 +282,7 @@ public class DriverStation { } else { locString = ""; } - StringBuilder traceString = new StringBuilder(""); + StringBuilder traceString = new StringBuilder(); if (printTrace) { boolean haveLoc = false; for (int i = stackTraceFirst; i < stackTrace.length; i++) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java index d7d4025118..52e1571d3b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java @@ -84,11 +84,10 @@ public abstract class InterruptableSensorBase extends SendableBase { /** * Request one of the 8 interrupts asynchronously on this digital input. * - * @param handler The {@link InterruptHandler} that contains the method {@link - * InterruptHandlerFunction#onInterrupt(boolean, boolean)} that will be called - * whenever there is an interrupt on this device. Request interrupts in synchronous - * mode where the user program interrupt handler will be called when an interrupt - * occurs. The default is interrupt on rising edges only. + * @param handler The {@link Consumer} that will be called whenever there is an interrupt on this + * device. Request interrupts in synchronous mode where the user program interrupt + * handler will be called when an interrupt occurs. The default is interrupt on + * rising edges only. */ public void requestInterrupts(Consumer handler) { if (m_interrupt != 0) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java index e72033edae..01fa26a0d3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -46,7 +46,7 @@ public class IterativeRobot extends IterativeRobotBase { HAL.observeUserProgramStarting(); // Loop forever, calling the appropriate mode-dependent function - while (true) { + while (!Thread.currentThread().isInterrupted()) { // Wait for new data to arrive m_ds.waitForData(); 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 019a490f50..4c392f54e8 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SerialPort.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,7 +7,6 @@ package edu.wpi.first.wpilibj; -import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import edu.wpi.first.hal.FRCNetComm.tResourceType; @@ -271,12 +270,7 @@ public class SerialPort implements AutoCloseable { */ public String readString(int count) { byte[] out = read(count); - try { - return new String(out, 0, out.length, "US-ASCII"); - } catch (UnsupportedEncodingException ex) { - ex.printStackTrace(); - return ""; - } + return new String(out, 0, out.length, StandardCharsets.US_ASCII); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java index 3ae837a226..e1e312f429 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java @@ -100,8 +100,7 @@ public class Timer { * clock. */ public synchronized void stop() { - final double temp = get(); - m_accumulatedTime = temp; + m_accumulatedTime = get(); m_running = false; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java index 52fc0869eb..223e992bc9 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java @@ -42,7 +42,7 @@ public class Watchdog implements Closeable, Comparable { boolean m_suppressTimeoutMessage; static { - startDaemonThread(() -> schedulerFunc()); + startDaemonThread(Watchdog::schedulerFunc); } private static final PriorityQueue m_watchdogs = new PriorityQueue<>(); @@ -69,13 +69,7 @@ public class Watchdog implements Closeable, Comparable { public int compareTo(Watchdog rhs) { // Elements with sooner expiration times are sorted as lesser. The head of // Java's PriorityQueue is the least element. - if (m_expirationTime < rhs.m_expirationTime) { - return -1; - } else if (m_expirationTime > rhs.m_expirationTime) { - return 1; - } else { - return 0; - } + return Long.compare(m_expirationTime, rhs.m_expirationTime); } /** @@ -154,9 +148,7 @@ public class Watchdog implements Closeable, Comparable { long now = RobotController.getFPGATime(); if (now - m_lastEpochsPrintTime > kMinPrintPeriod) { m_lastEpochsPrintTime = now; - m_epochs.forEach((key, value) -> { - System.out.format("\t%s: %.6fs\n", key, value / 1.0e6); - }); + m_epochs.forEach((key, value) -> System.out.format("\t%s: %.6fs\n", key, value / 1.0e6)); } } @@ -221,11 +213,12 @@ public class Watchdog implements Closeable, Comparable { } + @SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts") private static void schedulerFunc() { m_queueMutex.lock(); try { - while (true) { + while (!Thread.currentThread().isInterrupted()) { if (m_watchdogs.size() > 0) { boolean timedOut = !awaitUntil(m_schedulerWaiter, m_watchdogs.peek().m_expirationTime); if (timedOut) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java index 4e8507b8ec..b4394a4bbd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java @@ -66,7 +66,7 @@ public class PIDController extends SendableBase { private double m_totalError; enum Tolerance { - kAbsolute, kPercent; + kAbsolute, kPercent } private Tolerance m_toleranceType = Tolerance.kAbsolute; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java index 40b95eedc9..653f96f7f1 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java @@ -148,12 +148,8 @@ public class SendableChooser extends SendableBase { public void initSendable(SendableBuilder builder) { builder.setSmartDashboardType("String Chooser"); builder.getEntry(INSTANCE).setDouble(m_instance); - builder.addStringProperty(DEFAULT, () -> { - return m_defaultChoice; - }, null); - builder.addStringArrayProperty(OPTIONS, () -> { - return m_map.keySet().toArray(new String[0]); - }, null); + builder.addStringProperty(DEFAULT, () -> m_defaultChoice, null); + builder.addStringArrayProperty(OPTIONS, () -> m_map.keySet().toArray(new String[0]), null); builder.addStringProperty(ACTIVE, () -> { m_mutex.lock(); try { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfile.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfile.java index e6c7baea56..74ee846b1b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfile.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfile.java @@ -279,7 +279,6 @@ public class TrapezoidProfile { * @param initial The initial state (usually the current state). * @param goal The desired state when the profile is complete. */ - @SuppressWarnings("LocalVariableName") private static boolean shouldFlipAcceleration(State initial, State goal) { return initial.position > goal.position; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java index 701b86ea9c..328686a033 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -80,7 +80,7 @@ public class VisionRunner

{ public void runOnce() { Long id = CameraServerSharedStore.getCameraServerShared().getRobotMainThreadId(); - if (id != null && Thread.currentThread().getId() == id.longValue()) { + if (id != null && Thread.currentThread().getId() == id) { throw new IllegalStateException( "VisionRunner.runOnce() cannot be called from the main robot thread"); } @@ -113,7 +113,7 @@ public class VisionRunner

{ public void runForever() { Long id = CameraServerSharedStore.getCameraServerShared().getRobotMainThreadId(); - if (id != null && Thread.currentThread().getId() == id.longValue()) { + if (id != null && Thread.currentThread().getId() == id) { throw new IllegalStateException( "VisionRunner.runForever() cannot be called from the main robot thread"); } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java index 6990b50ab5..d97b35237f 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -20,7 +20,7 @@ public final class MockHardwareExtension implements BeforeAllCallback { } @Override - public void beforeAll(ExtensionContext context) throws Exception { + public void beforeAll(ExtensionContext context) { getRoot(context).getStore(Namespace.GLOBAL).getOrComputeIfAbsent("HAL Initalized", key -> { initializeHardware(); return true; diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/TrapezoidProfileTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/TrapezoidProfileTest.java index 77b099e6e1..5fc1056233 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/TrapezoidProfileTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/TrapezoidProfileTest.java @@ -26,7 +26,7 @@ class TrapezoidProfileTest { * @param val2 Second operand in comparison. */ private static void assertLessThanOrEquals(double val1, double val2) { - assertTrue(val1 <= val2, Double.toString(val1) + " is greater than " + val2); + assertTrue(val1 <= val2, val1 + " is greater than " + val2); } /** diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/UtilityClassTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/UtilityClassTest.java index 126542908b..4cfe01f872 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/UtilityClassTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/UtilityClassTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -48,7 +48,7 @@ public abstract class UtilityClassTest { public void constructorReflectionTest() { Constructor constructor = m_clazz.getDeclaredConstructors()[0]; constructor.setAccessible(true); - assertThrows(InvocationTargetException.class, () -> constructor.newInstance()); + assertThrows(InvocationTargetException.class, constructor::newInstance); } @TestFactory 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 9abd3aba9f..ee5655d52b 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/WatchdogTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/WatchdogTest.java @@ -23,9 +23,7 @@ class WatchdogTest { void enableDisableTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - final Watchdog watchdog = new Watchdog(0.4, () -> { - watchdogCounter.addAndGet(1); - }); + final Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1)); System.out.println("Run 1"); watchdog.enable(); @@ -69,9 +67,7 @@ class WatchdogTest { void resetTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - final Watchdog watchdog = new Watchdog(0.4, () -> { - watchdogCounter.addAndGet(1); - }); + final Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1)); watchdog.enable(); try { @@ -94,9 +90,7 @@ class WatchdogTest { void setTimeoutTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - final Watchdog watchdog = new Watchdog(1.0, () -> { - watchdogCounter.addAndGet(1); - }); + final Watchdog watchdog = new Watchdog(1.0, () -> watchdogCounter.addAndGet(1)); watchdog.enable(); try { @@ -146,9 +140,7 @@ class WatchdogTest { void epochsTest() { final AtomicInteger watchdogCounter = new AtomicInteger(0); - final Watchdog watchdog = new Watchdog(0.4, () -> { - watchdogCounter.addAndGet(1); - }); + final Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1)); System.out.println("Run 1"); watchdog.enable(); @@ -194,12 +186,8 @@ class WatchdogTest { final AtomicInteger watchdogCounter1 = new AtomicInteger(0); final AtomicInteger watchdogCounter2 = new AtomicInteger(0); - final Watchdog watchdog1 = new Watchdog(0.2, () -> { - watchdogCounter1.addAndGet(1); - }); - final Watchdog watchdog2 = new Watchdog(0.6, () -> { - watchdogCounter2.addAndGet(1); - }); + final Watchdog watchdog1 = new Watchdog(0.2, () -> watchdogCounter1.addAndGet(1)); + final Watchdog watchdog2 = new Watchdog(0.6, () -> watchdogCounter2.addAndGet(1)); watchdog2.enable(); try { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java index 02d308c3e3..48da5c47e6 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -61,7 +61,7 @@ public class Elevator extends PIDSubsystem { * The log method puts interesting information to the SmartDashboard. */ public void log() { - SmartDashboard.putData("Elevator Pot", (AnalogPotentiometer) m_pot); + SmartDashboard.putData("Elevator Pot", m_pot); } /** diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java index 30fa38e11d..6bda222e70 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -58,7 +58,7 @@ public class Wrist extends PIDSubsystem { * The log method puts interesting information to the SmartDashboard. */ public void log() { - SmartDashboard.putData("Wrist Angle", (AnalogPotentiometer) m_pot); + SmartDashboard.putData("Wrist Angle", m_pot); } /** diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Robot.java index 3e1c397da4..0f4da55012 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Robot.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -61,7 +61,7 @@ public class Robot extends TimedRobot { oi = new OI(); // instantiate the command used for the autonomous period - m_autoChooser = new SendableChooser(); + m_autoChooser = new SendableChooser<>(); m_autoChooser.setDefaultOption("Drive and Shoot", new DriveAndShootAutonomous()); m_autoChooser.addOption("Drive Forward", new DriveForward()); SmartDashboard.putData("Auto Mode", m_autoChooser); @@ -69,7 +69,7 @@ public class Robot extends TimedRobot { @Override public void autonomousInit() { - m_autonomousCommand = (Command) m_autoChooser.getSelected(); + m_autonomousCommand = m_autoChooser.getSelected(); m_autonomousCommand.start(); } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java index f50c6a61cb..615af87020 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java @@ -41,7 +41,7 @@ public class Robot extends RobotBase { // Tell the DS that the robot is ready to be enabled HAL.observeUserProgramStarting(); - while (true) { + while (!Thread.currentThread().isInterrupted()) { if (isDisabled()) { m_ds.InDisabled(true); disabled(); 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 3e40bd9643..0c27ee7ea3 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -161,7 +161,7 @@ public abstract class AbstractInterruptTest extends AbstractComsSetup { } @Test(timeout = 2000) - public void testMultipleInterruptsTriggering() throws Exception { + public void testMultipleInterruptsTriggering() { // Given final InterruptCounter counter = new InterruptCounter(); TestInterruptHandlerFunction function = new TestInterruptHandlerFunction(counter); diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java index 796e919d09..2e2557a5bd 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -39,18 +39,18 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest { @BeforeClass - public static void setUpBeforeClass() throws Exception { + public static void setUpBeforeClass() { analogIO = TestBench.getAnalogCrossConnectFixture(); } @AfterClass - public static void tearDownAfterClass() throws Exception { + public static void tearDownAfterClass() { analogIO.teardown(); analogIO = null; } @Before - public void setUp() throws Exception { + public void setUp() { analogIO.setup(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java index 9e5594d436..8ac65f6d5e 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometerTest.java @@ -32,7 +32,7 @@ public class AnalogPotentiometerTest extends AbstractComsSetup { private static final double DOUBLE_COMPARISON_DELTA = 2.0; @Before - public void setUp() throws Exception { + public void setUp() { m_analogIO = TestBench.getAnalogCrossConnectFixture(); m_potSource = new FakePotentiometerSource(m_analogIO.getOutput(), 360); m_pot = new AnalogPotentiometer(m_analogIO.getInput(), 360.0, 0); @@ -40,7 +40,7 @@ public class AnalogPotentiometerTest extends AbstractComsSetup { } @After - public void tearDown() throws Exception { + public void tearDown() { m_potSource.reset(); m_pot.close(); m_analogIO.teardown(); diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/CounterTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/CounterTest.java index 3d6bd2e40c..f6e33267af 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/CounterTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/CounterTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -78,17 +78,17 @@ public class CounterTest extends AbstractComsSetup { @BeforeClass - public static void setUpBeforeClass() throws Exception { + public static void setUpBeforeClass() { } @AfterClass - public static void tearDownAfterClass() throws Exception { + public static void tearDownAfterClass() { counter.teardown(); counter = null; } @Before - public void setUp() throws Exception { + public void setUp() { counter.setup(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DIOCrossConnectTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DIOCrossConnectTest.java index b61b76180a..5f59b5e824 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DIOCrossConnectTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/DIOCrossConnectTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -70,13 +70,13 @@ public class DIOCrossConnectTest extends AbstractInterruptTest { } @AfterClass - public static void tearDownAfterClass() throws Exception { + public static void tearDownAfterClass() { dio.teardown(); dio = null; } @After - public void tearDown() throws Exception { + public void tearDown() { dio.reset(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/EncoderTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/EncoderTest.java index 98337907a6..3a639abe8b 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/EncoderTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/EncoderTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -79,7 +79,7 @@ public class EncoderTest extends AbstractComsSetup { } @AfterClass - public static void tearDownAfterClass() throws Exception { + public static void tearDownAfterClass() { encoder.teardown(); encoder = null; } @@ -88,13 +88,13 @@ public class EncoderTest extends AbstractComsSetup { * Sets up the test and verifies that the test was reset to the default state. */ @Before - public void setUp() throws Exception { + public void setUp() { encoder.setup(); testDefaultState(); } @After - public void tearDown() throws Exception { + public void tearDown() { encoder.reset(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/GyroTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/GyroTest.java index aee0514106..3a5e1d29bd 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/GyroTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/GyroTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -35,14 +35,14 @@ public class GyroTest extends AbstractComsSetup { } @Before - public void setUp() throws Exception { + public void setUp() { logger.fine("Setup: TiltPan camera"); m_tpcam = TestBench.getInstance().getTiltPanCam(); m_tpcam.setup(); } @After - public void tearDown() throws Exception { + public void tearDown() { m_tpcam.teardown(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java index e93e29e23f..0fbfcb0046 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java @@ -75,7 +75,7 @@ public class MotorEncoderTest extends AbstractComsSetup { } @After - public void tearDown() throws Exception { + public void tearDown() { me.reset(); encodersResetCheck(me); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java index b703138d86..e73f716e76 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PCMTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2014-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -51,7 +51,7 @@ public class PCMTest extends AbstractComsSetup { private static DigitalInput fakeSolenoid2; @BeforeClass - public static void setUpBeforeClass() throws Exception { + public static void setUpBeforeClass() { compressor = new Compressor(); fakePressureSwitch = new DigitalOutput(11); @@ -62,7 +62,7 @@ public class PCMTest extends AbstractComsSetup { } @AfterClass - public static void tearDownAfterClass() throws Exception { + public static void tearDownAfterClass() { compressor.close(); fakePressureSwitch.close(); @@ -73,7 +73,7 @@ public class PCMTest extends AbstractComsSetup { } @Before - public void reset() throws Exception { + public void reset() { compressor.stop(); fakePressureSwitch.set(false); } 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 7c49f810a5..54ab1ca3ee 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -41,12 +41,12 @@ public class PDPTest extends AbstractComsSetup { private final double m_expectedStoppedCurrentDraw; @BeforeClass - public static void setUpBeforeClass() throws Exception { + public static void setUpBeforeClass() { pdp = new PowerDistributionPanel(); } @AfterClass - public static void tearDownAfterClass() throws Exception { + public static void tearDownAfterClass() { pdp.close(); pdp = null; me.teardown(); @@ -74,7 +74,7 @@ public class PDPTest extends AbstractComsSetup { } @After - public void tearDown() throws Exception { + public void tearDown() { me.reset(); } 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 f5805f6b14..39b4423cf3 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PIDTest.java @@ -94,18 +94,18 @@ public class PIDTest extends AbstractComsSetup { } @BeforeClass - public static void setUpBeforeClass() throws Exception { + public static void setUpBeforeClass() { } @AfterClass - public static void tearDownAfterClass() throws Exception { + public static void tearDownAfterClass() { logger.fine("TearDownAfterClass: " + me.getType()); me.teardown(); me = null; } @Before - public void setUp() throws Exception { + public void setUp() { logger.fine("Setup: " + me.getType()); me.setup(); m_table = NetworkTableInstance.getDefault().getTable("TEST_PID"); @@ -118,7 +118,7 @@ public class PIDTest extends AbstractComsSetup { } @After - public void tearDown() throws Exception { + public void tearDown() { logger.fine("Teardown: " + me.getType()); m_runner.disable(); m_controller.close(); @@ -174,12 +174,12 @@ public class PIDTest extends AbstractComsSetup { public void testSetSetpoint() { setupAbsoluteTolerance(); setupOutputRange(); - Double reference = 2500.0; + double reference = 2500.0; m_runner.disable(); m_controller.setSetpoint(reference); m_runner.enable(); - assertEquals("Did not correctly set reference", reference, new Double(m_controller - .getSetpoint())); + assertEquals("Did not correctly set reference", reference, m_controller + .getSetpoint(), 1e-3); } @Test(timeout = 10000) diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RelayCrossConnectTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RelayCrossConnectTest.java index a55a81689a..29fad5f8ab 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RelayCrossConnectTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/RelayCrossConnectTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -39,7 +39,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup { @Before - public void setUp() throws Exception { + public void setUp() { m_relayFixture = TestBench.getRelayCrossConnectFixture(); m_relayFixture.setup(); m_builder = new SendableBuilderImpl(); @@ -48,7 +48,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup { } @After - public void tearDown() throws Exception { + public void tearDown() { m_relayFixture.reset(); m_relayFixture.teardown(); } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuiteTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuiteTest.java index acff9d4bad..d788b8191f 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuiteTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuiteTest.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -15,7 +15,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.junit.runners.model.InitializationError; import edu.wpi.first.wpilibj.test.AbstractTestSuite.ClassMethodPair; @@ -40,12 +39,12 @@ public class AbstractTestSuiteTest { TestForAbstractTestSuite m_testSuite; @Before - public void setUp() throws Exception { + public void setUp() { m_testSuite = new TestForAbstractTestSuite(); } @Test - public void testGetTestsMatchingAll() throws InitializationError { + public void testGetTestsMatchingAll() { // when List> collectedTests = m_testSuite.getAllClassMatching(".*"); // then @@ -53,7 +52,7 @@ public class AbstractTestSuiteTest { } @Test - public void testGetTestsMatchingSample() throws InitializationError { + public void testGetTestsMatchingSample() { // when List> collectedTests = m_testSuite.getAllClassMatching(".*Sample.*"); // then @@ -61,7 +60,7 @@ public class AbstractTestSuiteTest { } @Test - public void testGetTestsMatchingUnusual() throws InitializationError { + public void testGetTestsMatchingUnusual() { // when List> collectedTests = m_testSuite.getAllClassMatching(".*Unusual.*"); // then @@ -70,7 +69,7 @@ public class AbstractTestSuiteTest { } @Test - public void testGetTestsFromSuiteMatchingAll() throws InitializationError { + public void testGetTestsFromSuiteMatchingAll() { // when List> collectedTests = m_testSuite.getSuiteOrTestMatchingRegex(".*"); // then @@ -78,7 +77,7 @@ public class AbstractTestSuiteTest { } @Test - public void testGetTestsFromSuiteMatchingTest() throws InitializationError { + public void testGetTestsFromSuiteMatchingTest() { // when List> collectedTests = m_testSuite.getSuiteOrTestMatchingRegex(".*Test.*"); // then 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 3286db3324..b8d6a6fc3b 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 @@ -80,7 +80,7 @@ public final class TestBench { * @return a freshly allocated Talon, Encoder pair */ public MotorEncoderFixture getTalonPair() { - MotorEncoderFixture talonPair = new MotorEncoderFixture() { + return new MotorEncoderFixture() { @Override protected Talon giveSpeedController() { return new Talon(kTalonChannel); @@ -101,7 +101,6 @@ public final class TestBench { return kTalonPDPChannel; } }; - return talonPair; } /** @@ -111,7 +110,7 @@ public final class TestBench { * @return a freshly allocated Victor, Encoder pair */ public MotorEncoderFixture getVictorPair() { - MotorEncoderFixture vicPair = new MotorEncoderFixture() { + return new MotorEncoderFixture() { @Override protected Victor giveSpeedController() { return new Victor(kVictorChannel); @@ -132,7 +131,6 @@ public final class TestBench { return kVictorPDPChannel; } }; - return vicPair; } /** @@ -142,7 +140,7 @@ public final class TestBench { * @return a freshly allocated Jaguar, Encoder pair */ public MotorEncoderFixture getJaguarPair() { - MotorEncoderFixture jagPair = new MotorEncoderFixture() { + return new MotorEncoderFixture() { @Override protected Jaguar giveSpeedController() { return new Jaguar(kJaguarChannel); @@ -163,7 +161,6 @@ public final class TestBench { return kJaguarPDPChannel; } }; - return jagPair; } /** @@ -172,7 +169,8 @@ public final class TestBench { * @return a freshly allocated Servo's and a freshly allocated Gyroscope */ public TiltPanCameraFixture getTiltPanCam() { - TiltPanCameraFixture tpcam = new TiltPanCameraFixture() { + + return new TiltPanCameraFixture() { @Override protected AnalogGyro giveGyro() { AnalogGyro gyro = new AnalogGyro(kGyroChannel); @@ -197,13 +195,10 @@ public final class TestBench { return new Servo(kPanServoChannel); } }; - - return tpcam; } public DIOCrossConnectFixture getDIOCrossConnectFixture(int inputPort, int outputPort) { - DIOCrossConnectFixture dio = new DIOCrossConnectFixture(inputPort, outputPort); - return dio; + return new DIOCrossConnectFixture(inputPort, outputPort); } /** @@ -228,7 +223,7 @@ public final class TestBench { @SuppressWarnings("JavadocMethod") public static AnalogCrossConnectFixture getAnalogCrossConnectFixture() { - AnalogCrossConnectFixture analogIO = new AnalogCrossConnectFixture() { + return new AnalogCrossConnectFixture() { @Override protected AnalogOutput giveAnalogOutput() { return new AnalogOutput(0); @@ -239,12 +234,11 @@ public final class TestBench { return new AnalogInput(2); } }; - return analogIO; } @SuppressWarnings("JavadocMethod") public static RelayCrossConnectFixture getRelayCrossConnectFixture() { - RelayCrossConnectFixture relay = new RelayCrossConnectFixture() { + return new RelayCrossConnectFixture() { @Override protected Relay giveRelay() { return new Relay(0); @@ -260,7 +254,6 @@ public final class TestBench { return new DigitalInput(19); } }; - return relay; } /** diff --git a/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java b/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java index bf3bce29fe..17070a6e4d 100644 --- a/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java +++ b/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeDetector.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -96,8 +96,7 @@ public final class RuntimeDetector { public static synchronized String getLibraryResource(String libName) { computePlatform(); - String toReturn = filePath + filePrefix + libName + fileExtension; - return toReturn; + return filePath + filePrefix + libName + fileExtension; } /** @@ -106,8 +105,7 @@ public final class RuntimeDetector { public static synchronized String getHashLibraryResource(String libName) { computePlatform(); - String toReturn = filePath + libName + ".hash"; - return toReturn; + return filePath + libName + ".hash"; } public static boolean isAthena() { diff --git a/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeLoader.java b/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeLoader.java index b209fe8831..3e5fea7e62 100644 --- a/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeLoader.java +++ b/wpiutil/src/main/java/edu/wpi/first/wpiutil/RuntimeLoader.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -69,7 +69,6 @@ public final class RuntimeLoader { try { // First, try loading path System.loadLibrary(m_libraryName); - return; } catch (UnsatisfiedLinkError ule) { // Then load the hash from the resources String hashName = RuntimeDetector.getHashLibraryResource(m_libraryName); @@ -115,7 +114,6 @@ public final class RuntimeLoader { try { // First, try loading path System.loadLibrary(m_libraryName); - return; } catch (UnsatisfiedLinkError ule) { // Then load the hash from the input file String resname = RuntimeDetector.getLibraryResource(m_libraryName);