mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
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:
committed by
Peter Johnson
parent
39561751fc
commit
df12fc2a86
@@ -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++) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user