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
This commit is contained in:
Austin Shalit
2019-08-01 01:19:48 -04:00
committed by Peter Johnson
parent 39561751fc
commit df12fc2a86
43 changed files with 129 additions and 180 deletions

View File

@@ -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).

View File

@@ -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;
}

View File

@@ -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<P extends VisionPipeline> {
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<P extends VisionPipeline> {
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");
}

View File

@@ -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<String> 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<String> 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;
}
}

View File

@@ -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);
}
}

View File

@@ -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<EntryNotification>() {
return m_inst.addEntryListener(m_pathWithSep, new Consumer<>() {
final Set<String> 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);

View File

@@ -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);

View File

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

View File

@@ -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<Arguments> 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/")
);

View File

@@ -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++) {

View File

@@ -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<WaitResult> handler) {
if (m_interrupt != 0) {

View File

@@ -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();

View File

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

View File

@@ -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;
}

View File

@@ -42,7 +42,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
boolean m_suppressTimeoutMessage;
static {
startDaemonThread(() -> schedulerFunc());
startDaemonThread(Watchdog::schedulerFunc);
}
private static final PriorityQueue<Watchdog> m_watchdogs = new PriorityQueue<>();
@@ -69,13 +69,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
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<Watchdog> {
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<Watchdog> {
}
@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) {

View File

@@ -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;

View File

@@ -148,12 +148,8 @@ public class SendableChooser<V> 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 {

View File

@@ -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;
}

View File

@@ -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<P extends VisionPipeline> {
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<P extends VisionPipeline> {
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");
}

View File

@@ -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;

View File

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

View File

@@ -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

View File

@@ -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 {

View File

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

View File

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

View File

@@ -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<Command>();
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();
}

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -75,7 +75,7 @@ public class MotorEncoderTest extends AbstractComsSetup {
}
@After
public void tearDown() throws Exception {
public void tearDown() {
me.reset();
encodersResetCheck(me);
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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)

View File

@@ -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();
}

View File

@@ -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<Class<?>> collectedTests = m_testSuite.getAllClassMatching(".*");
// then
@@ -53,7 +52,7 @@ public class AbstractTestSuiteTest {
}
@Test
public void testGetTestsMatchingSample() throws InitializationError {
public void testGetTestsMatchingSample() {
// when
List<Class<?>> collectedTests = m_testSuite.getAllClassMatching(".*Sample.*");
// then
@@ -61,7 +60,7 @@ public class AbstractTestSuiteTest {
}
@Test
public void testGetTestsMatchingUnusual() throws InitializationError {
public void testGetTestsMatchingUnusual() {
// when
List<Class<?>> collectedTests = m_testSuite.getAllClassMatching(".*Unusual.*");
// then
@@ -70,7 +69,7 @@ public class AbstractTestSuiteTest {
}
@Test
public void testGetTestsFromSuiteMatchingAll() throws InitializationError {
public void testGetTestsFromSuiteMatchingAll() {
// when
List<Class<?>> collectedTests = m_testSuite.getSuiteOrTestMatchingRegex(".*");
// then
@@ -78,7 +77,7 @@ public class AbstractTestSuiteTest {
}
@Test
public void testGetTestsFromSuiteMatchingTest() throws InitializationError {
public void testGetTestsFromSuiteMatchingTest() {
// when
List<Class<?>> collectedTests = m_testSuite.getSuiteOrTestMatchingRegex(".*Test.*");
// then

View File

@@ -80,7 +80,7 @@ public final class TestBench {
* @return a freshly allocated Talon, Encoder pair
*/
public MotorEncoderFixture<Talon> getTalonPair() {
MotorEncoderFixture<Talon> talonPair = new MotorEncoderFixture<Talon>() {
return new MotorEncoderFixture<Talon>() {
@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<Victor> getVictorPair() {
MotorEncoderFixture<Victor> vicPair = new MotorEncoderFixture<Victor>() {
return new MotorEncoderFixture<Victor>() {
@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<Jaguar> getJaguarPair() {
MotorEncoderFixture<Jaguar> jagPair = new MotorEncoderFixture<Jaguar>() {
return new MotorEncoderFixture<Jaguar>() {
@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;
}
/**

View File

@@ -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() {

View File

@@ -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<T> {
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<T> {
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);