Update and enable PMD 6.3.0 (#1107)

This commit is contained in:
Austin Shalit
2018-06-03 10:00:53 -07:00
committed by Peter Johnson
parent 8eafe7f325
commit e548a5f705
156 changed files with 619 additions and 325 deletions

View File

@@ -22,7 +22,7 @@ public class AnalogAccelerometer extends SendableBase implements PIDSource {
private AnalogInput m_analogChannel;
private double m_voltsPerG = 1.0;
private double m_zeroGVoltage = 2.5;
private boolean m_allocatedChannel;
private final boolean m_allocatedChannel;
protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
/**
@@ -42,8 +42,7 @@ public class AnalogAccelerometer extends SendableBase implements PIDSource {
* @param channel The channel number for the analog input the accelerometer is connected to
*/
public AnalogAccelerometer(final int channel) {
this(new AnalogInput(channel));
m_allocatedChannel = true;
this(new AnalogInput(channel), true);
addChild(m_analogChannel);
}
@@ -55,10 +54,13 @@ public class AnalogAccelerometer extends SendableBase implements PIDSource {
* @param channel The existing AnalogInput object for the analog input the accelerometer is
* connected to
*/
public AnalogAccelerometer(AnalogInput channel) {
requireNonNull(channel, "Analog Channel given was null");
public AnalogAccelerometer(final AnalogInput channel) {
this(channel, false);
}
m_allocatedChannel = false;
private AnalogAccelerometer(final AnalogInput channel, final boolean allocatedChannel) {
requireNonNull(channel, "Analog Channel given was null");
m_allocatedChannel = allocatedChannel;
m_analogChannel = channel;
initAccelerometer();
}

View File

@@ -26,9 +26,9 @@ import static java.util.Objects.requireNonNull;
public class AnalogGyro extends GyroBase implements Gyro, PIDSource, Sendable {
private static final double kDefaultVoltsPerDegreePerSecond = 0.007;
protected AnalogInput m_analog;
private boolean m_channelAllocated = false;
private boolean m_channelAllocated;
private int m_gyroHandle = 0;
private int m_gyroHandle;
/**
* Initialize the gyro. Calibration is handled by calibrate().

View File

@@ -41,8 +41,8 @@ public class AnalogTrigger extends SendableBase {
*/
protected int m_port;
protected int m_index;
protected AnalogInput m_analogInput = null;
protected boolean m_ownsAnalog = false;
protected AnalogInput m_analogInput;
protected boolean m_ownsAnalog;
/**
* Constructor for an analog trigger given a channel number.

View File

@@ -26,7 +26,7 @@ public class CAN implements Closeable {
public static final int kTeamManufacturer = 8;
public static final int kTeamDeviceType = 10;
private int m_handle;
private final int m_handle;
/**
* Create a new CAN communication interface with the specific device ID.

View File

@@ -14,10 +14,10 @@ public class CircularBuffer {
private double[] m_data;
// Index of element at front of buffer
private int m_front = 0;
private int m_front;
// Number of elements used in buffer
private int m_length = 0;
private int m_length;
/**
* Create a CircularBuffer with the provided size.

View File

@@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.hal.PowerJNI;
* @deprecated Use RobotController class instead
*/
@Deprecated
public class ControllerPower {
public final class ControllerPower {
/**
* Get the input voltage to the robot controller.
*
@@ -157,4 +157,7 @@ public class ControllerPower {
public static int getFaultCount6V() {
return PowerJNI.getUserCurrentFaults6V();
}
private ControllerPower() {
}
}

View File

@@ -146,7 +146,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
requireNonNull(downSource, "Down Source given was null");
if (encodingType != EncodingType.k1X && encodingType != EncodingType.k2X) {
throw new RuntimeException("Counters only support 1X and 2X quadrature decoding!");
throw new IllegalArgumentException("Counters only support 1X and 2X quadrature decoding!");
}
setUpSource(upSource);
@@ -253,7 +253,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
*/
public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) {
if (m_upSource == null) {
throw new RuntimeException("Up Source must be set before setting the edge!");
throw new IllegalStateException("Up Source must be set before setting the edge!");
}
CounterJNI.setCounterUpSourceEdge(m_counter, risingEdge, fallingEdge);
}
@@ -528,6 +528,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
*
* @param pidSource An enum to select the parameter.
*/
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
requireNonNull(pidSource, "PID Source Parameter given was null");
if (pidSource != PIDSourceType.kDisplacement && pidSource != PIDSourceType.kRate) {
@@ -537,6 +538,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
m_pidSource = pidSource;
}
@Override
public PIDSourceType getPIDSourceType() {
return m_pidSource;
}

View File

@@ -170,6 +170,7 @@ public class DigitalGlitchFilter extends SendableBase {
/ (long) (SensorUtil.kSystemClockTicksPerMicrosecond / 4);
}
@Override
@SuppressWarnings("PMD.UnusedFormalParameter")
public void initSendable(SendableBuilder builder) {
}

View File

@@ -19,8 +19,8 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
* for devices like switches etc. that aren't implemented anywhere else.
*/
public class DigitalInput extends DigitalSource {
private int m_channel = 0;
private int m_handle = 0;
private final int m_channel;
private int m_handle;
/**
* Create an instance of a Digital Input class. Creates a digital input given a channel.
@@ -43,8 +43,8 @@ public class DigitalInput extends DigitalSource {
if (m_interrupt != 0) {
cancelInterrupts();
}
DIOJNI.freeDIOPort(m_handle);
m_handle = 0;
}
/**

View File

@@ -20,8 +20,8 @@ public class DigitalOutput extends SendableBase {
private static final int invalidPwmGenerator = 0;
private int m_pwmGenerator = invalidPwmGenerator;
private int m_channel = 0;
private int m_handle = 0;
private final int m_channel;
private int m_handle;
/**
* Create an instance of a digital output. Create an instance of a digital output given a

View File

@@ -31,8 +31,8 @@ public class DoubleSolenoid extends SolenoidBase {
private byte m_forwardMask; // The mask for the forward channel.
private byte m_reverseMask; // The mask for the reverse channel.
private int m_forwardHandle = 0;
private int m_reverseHandle = 0;
private int m_forwardHandle;
private int m_reverseHandle;
/**
* Constructor. Uses the default PCM ID (defaults to 0).

View File

@@ -25,6 +25,9 @@ import edu.wpi.first.wpilibj.hal.PowerJNI;
/**
* Provide access to the network communication data to / from the Driver Station.
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.ExcessiveClassLength",
"PMD.ExcessivePublicCount", "PMD.GodClass", "PMD.TooManyFields",
"PMD.TooManyMethods"})
public class DriverStation implements RobotState.Interface {
/**
* Number of Joystick Ports.
@@ -66,15 +69,16 @@ public class DriverStation implements RobotState.Interface {
}
private static final double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0;
private double m_nextMessageTime = 0.0;
private double m_nextMessageTime;
private static class DriverStationTask implements Runnable {
private DriverStation m_ds;
private final DriverStation m_ds;
DriverStationTask(DriverStation ds) {
m_ds = ds;
}
@Override
public void run() {
m_ds.run();
}
@@ -144,12 +148,13 @@ public class DriverStation implements RobotState.Interface {
private int[] m_joystickButtonsReleased = new int[kJoystickPorts];
// preallocated byte buffer for button count
private ByteBuffer m_buttonCountBuffer = ByteBuffer.allocateDirect(1);
private final ByteBuffer m_buttonCountBuffer = ByteBuffer.allocateDirect(1);
private MatchDataSender m_matchDataSender;
private final MatchDataSender m_matchDataSender;
// Internal Driver Station thread
private Thread m_thread;
@SuppressWarnings("PMD.SingularField")
private final Thread m_thread;
private volatile boolean m_threadKeepAlive = true;
private final ReentrantLock m_cacheDataMutex = new ReentrantLock();
@@ -159,14 +164,14 @@ public class DriverStation implements RobotState.Interface {
private int m_waitForDataCount;
// Robot state status variables
private boolean m_userInDisabled = false;
private boolean m_userInAutonomous = false;
private boolean m_userInTeleop = false;
private boolean m_userInTest = false;
private boolean m_userInDisabled;
private boolean m_userInAutonomous;
private boolean m_userInTeleop;
private boolean m_userInTest;
// Control word variables
private final Object m_controlWordMutex;
private ControlWord m_controlWordCache;
private final ControlWord m_controlWordCache;
private long m_lastControlWordUpdate;
/**
@@ -184,6 +189,7 @@ public class DriverStation implements RobotState.Interface {
* <p>The single DriverStation instance is created statically with the instance static member
* variable.
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private DriverStation() {
HAL.initialize(500, 0);
m_waitForDataCount = 0;
@@ -277,12 +283,12 @@ public class DriverStation implements RobotState.Interface {
} else {
locString = "";
}
String traceString = "";
StringBuilder traceString = new StringBuilder("");
if (printTrace) {
boolean haveLoc = false;
for (int i = stackTraceFirst; i < stackTrace.length; i++) {
String loc = stackTrace[i].toString();
traceString += "\tat " + loc + "\n";
traceString.append("\tat ").append(loc).append('\n');
// get first user function
if (!haveLoc && !loc.startsWith("edu.wpi.first")) {
locString = loc;
@@ -290,7 +296,7 @@ public class DriverStation implements RobotState.Interface {
}
}
}
HAL.sendError(isError, code, false, error, locString, traceString, true);
HAL.sendError(isError, code, false, error, locString, traceString.toString(), true);
}
/**
@@ -302,7 +308,7 @@ public class DriverStation implements RobotState.Interface {
*/
public boolean getStickButton(final int stick, final int button) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
}
if (button <= 0) {
reportJoystickUnpluggedError("Button indexes begin at 1 in WPILib for C++ and Java\n");
@@ -338,7 +344,7 @@ public class DriverStation implements RobotState.Interface {
return false;
}
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
}
boolean error = false;
boolean retVal = false;
@@ -377,7 +383,7 @@ public class DriverStation implements RobotState.Interface {
return false;
}
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
}
boolean error = false;
boolean retVal = false;
@@ -412,10 +418,10 @@ public class DriverStation implements RobotState.Interface {
*/
public double getStickAxis(int stick, int axis) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (axis >= HAL.kMaxJoystickAxes) {
throw new RuntimeException("Joystick axis is out of range");
throw new IllegalArgumentException("Joystick axis is out of range");
}
m_cacheDataMutex.lock();
@@ -443,10 +449,10 @@ public class DriverStation implements RobotState.Interface {
*/
public int getStickPOV(int stick, int pov) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
if (pov >= HAL.kMaxJoystickPOVs) {
throw new RuntimeException("Joystick POV is out of range");
throw new IllegalArgumentException("Joystick POV is out of range");
}
m_cacheDataMutex.lock();
@@ -474,7 +480,7 @@ public class DriverStation implements RobotState.Interface {
*/
public int getStickButtons(final int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-3");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
}
m_cacheDataMutex.lock();
@@ -493,7 +499,7 @@ public class DriverStation implements RobotState.Interface {
*/
public int getStickAxisCount(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
m_cacheDataMutex.lock();
@@ -512,7 +518,7 @@ public class DriverStation implements RobotState.Interface {
*/
public int getStickPOVCount(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
m_cacheDataMutex.lock();
@@ -531,7 +537,7 @@ public class DriverStation implements RobotState.Interface {
*/
public int getStickButtonCount(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
m_cacheDataMutex.lock();
@@ -550,7 +556,7 @@ public class DriverStation implements RobotState.Interface {
*/
public boolean getJoystickIsXbox(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
m_cacheDataMutex.lock();
@@ -569,7 +575,7 @@ public class DriverStation implements RobotState.Interface {
*/
public int getJoystickType(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
m_cacheDataMutex.lock();
@@ -588,7 +594,7 @@ public class DriverStation implements RobotState.Interface {
*/
public String getJoystickName(int stick) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
m_cacheDataMutex.lock();
@@ -608,7 +614,7 @@ public class DriverStation implements RobotState.Interface {
*/
public int getJoystickAxisType(int stick, int axis) {
if (stick < 0 || stick >= kJoystickPorts) {
throw new RuntimeException("Joystick index is out of range, should be 0-5");
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
}
m_cacheDataMutex.lock();
@@ -624,6 +630,7 @@ public class DriverStation implements RobotState.Interface {
*
* @return True if the robot is enabled, false otherwise.
*/
@Override
public boolean isEnabled() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
@@ -636,6 +643,7 @@ public class DriverStation implements RobotState.Interface {
*
* @return True if the robot should be disabled, false otherwise.
*/
@Override
public boolean isDisabled() {
return !isEnabled();
}
@@ -646,6 +654,7 @@ public class DriverStation implements RobotState.Interface {
*
* @return True if autonomous mode should be enabled, false otherwise.
*/
@Override
public boolean isAutonomous() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
@@ -659,6 +668,7 @@ public class DriverStation implements RobotState.Interface {
*
* @return True if operator-controlled mode should be enabled, false otherwise.
*/
@Override
public boolean isOperatorControl() {
return !(isAutonomous() || isTest());
}
@@ -669,6 +679,7 @@ public class DriverStation implements RobotState.Interface {
*
* @return True if test mode should be enabled, false otherwise.
*/
@Override
public boolean isTest() {
synchronized (m_controlWordMutex) {
updateControlWord(false);
@@ -1139,7 +1150,8 @@ public class DriverStation implements RobotState.Interface {
safetyCounter = 0;
}
if (++safetyCounter >= 4) {
safetyCounter++;
if (safetyCounter >= 4) {
MotorSafetyHelper.checkMotors();
safetyCounter = 0;
}

View File

@@ -53,7 +53,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
/**
* The index source.
*/
protected DigitalSource m_indexSource = null; // Index on some encoders
protected DigitalSource m_indexSource; // Index on some encoders
private boolean m_allocatedA;
private boolean m_allocatedB;
private boolean m_allocatedI;
@@ -329,6 +329,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
*
* @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale factor.
*/
@Override
public int get() {
return EncoderJNI.getEncoder(m_encoder);
}
@@ -336,6 +337,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
/**
* Reset the Encoder distance to zero. Resets the current count to zero on the encoder.
*/
@Override
public void reset() {
EncoderJNI.resetEncoder(m_encoder);
}
@@ -350,6 +352,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
* @return Period in seconds of the most recent pulse.
* @deprecated Use getRate() in favor of this method.
*/
@Override
@Deprecated
public double getPeriod() {
return EncoderJNI.getEncoderPeriod(m_encoder);
@@ -364,6 +367,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
* @param maxPeriod The maximum time between rising and falling edges before the FPGA will report
* the device stopped. This is expressed in seconds.
*/
@Override
public void setMaxPeriod(double maxPeriod) {
EncoderJNI.setEncoderMaxPeriod(m_encoder, maxPeriod);
}
@@ -375,6 +379,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
*
* @return True if the encoder is considered stopped.
*/
@Override
public boolean getStopped() {
return EncoderJNI.getEncoderStopped(m_encoder);
}
@@ -384,6 +389,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
*
* @return The last direction the encoder value changed.
*/
@Override
public boolean getDirection() {
return EncoderJNI.getEncoderDirection(m_encoder);
}
@@ -478,6 +484,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
*
* @param pidSource An enum to select the parameter.
*/
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
m_pidSource = pidSource;
}
@@ -492,6 +499,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
*
* @return The current value of the selected source parameter.
*/
@Override
public double pidGet() {
switch (m_pidSource) {
case kDisplacement:

View File

@@ -18,6 +18,7 @@ public abstract class GamepadBase extends GenericHID {
super(port);
}
@Override
public abstract double getRawAxis(int axis);
/**
@@ -43,19 +44,27 @@ public abstract class GamepadBase extends GenericHID {
return getStickButton(Hand.kRight);
}
@Override
public abstract boolean getRawButton(int button);
@Override
public abstract int getPOV(int pov);
@Override
public abstract int getPOVCount();
@Override
public abstract HIDType getType();
@Override
public abstract String getName();
@Override
public abstract void setOutput(int outputNumber, boolean value);
@Override
public abstract void setOutputs(int value);
@Override
public abstract void setRumble(RumbleType type, double value);
}

View File

@@ -44,6 +44,7 @@ public abstract class GenericHID {
@SuppressWarnings("MemberName")
public final int value;
@SuppressWarnings("PMD.UseConcurrentHashMap")
private static final Map<Integer, HIDType> map = new HashMap<>();
HIDType(int value) {
@@ -57,7 +58,7 @@ public abstract class GenericHID {
}
public static HIDType of(int value) {
return (HIDType) map.get(value);
return map.get(value);
}
}

View File

@@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException;
* Support for high level usage reporting.
*/
@SuppressWarnings("JavadocMethod")
public class HLUsageReporting {
public final class HLUsageReporting {
private static Interface impl;
@SuppressWarnings("MethodName")
@@ -54,14 +54,20 @@ public class HLUsageReporting {
}
public static class Null implements Interface {
@Override
public void reportScheduler() {
}
@Override
@SuppressWarnings("PMD.UnusedFormalParameter")
public void reportPIDController(int num) {
}
@Override
public void reportSmartDashboard() {
}
}
private HLUsageReporting() {
}
}

View File

@@ -22,6 +22,7 @@ import static java.util.Objects.requireNonNull;
* <p>This class is intended to be used by sensor (and other I2C device) drivers. It probably should
* not be used directly.
*/
@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"})
public class I2C implements AutoCloseable {
public enum Port {
kOnboard(0), kMXP(1);
@@ -99,6 +100,7 @@ public class I2C implements AutoCloseable {
* @param receiveSize Number of bytes to read from the device.
* @return Transfer Aborted... false for success, true for aborted.
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
public synchronized boolean transaction(ByteBuffer dataToSend, int sendSize,
ByteBuffer dataReceived, int receiveSize) {
if (dataToSend.hasArray() && dataReceived.hasArray()) {
@@ -231,7 +233,7 @@ public class I2C implements AutoCloseable {
return transaction(registerAddressArray, registerAddressArray.length, buffer, count);
}
private ByteBuffer m_readDataToSendBuffer = null;
private ByteBuffer m_readDataToSendBuffer;
/**
* Execute a read transaction with the device.
@@ -352,12 +354,11 @@ public class I2C implements AutoCloseable {
byte[] dataToSend = new byte[1];
byte[] deviceData = new byte[4];
for (int i = 0, curRegisterAddress = registerAddress;
i < count; i += 4, curRegisterAddress += 4) {
for (int i = 0; i < count; i += 4) {
int toRead = count - i < 4 ? count - i : 4;
// Read the chunk of data. Return false if the sensor does not
// respond.
dataToSend[0] = (byte) curRegisterAddress;
dataToSend[0] = (byte) (registerAddress + i);
if (transaction(dataToSend, 1, deviceData, toRead)) {
return false;
}

View File

@@ -14,6 +14,7 @@ import edu.wpi.first.wpilibj.util.AllocationException;
/**
* Base for sensors to be used with interrupts.
*/
@SuppressWarnings("PMD.TooManyMethods")
public abstract class InterruptableSensorBase extends SendableBase {
@SuppressWarnings("JavadocMethod")
public enum WaitResult {
@@ -35,7 +36,7 @@ public abstract class InterruptableSensorBase extends SendableBase {
/**
* Flags if the interrupt being allocated is synchronous.
*/
protected boolean m_isSynchronousInterrupt = false;
protected boolean m_isSynchronousInterrupt;
/**
* Create a new InterrupatableSensorBase.

View File

@@ -27,6 +27,7 @@ public class IterativeRobot extends IterativeRobotBase {
/**
* Provide an alternate "main loop" via startCompetition().
*/
@Override
public void startCompetition() {
robotInit();

View File

@@ -40,6 +40,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
* - teleopPeriodic()
* - testPeriodic()
*/
@SuppressWarnings("PMD.TooManyMethods")
public abstract class IterativeRobotBase extends RobotBase {
private enum Mode {
kNone,
@@ -54,6 +55,7 @@ public abstract class IterativeRobotBase extends RobotBase {
/**
* Provide an alternate "main loop" via startCompetition().
*/
@Override
public abstract void startCompetition();
/* ----------- Overridable initialization code ----------------- */

View File

@@ -21,6 +21,7 @@ public interface NamedSendable extends Sendable {
*
* @return the name of the subtable of SmartDashboard that the Sendable object will use.
*/
@Override
String getName();
@Override

View File

@@ -16,11 +16,11 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
*/
public class NidecBrushless extends SendableBase implements SpeedController, MotorSafety, Sendable {
private final MotorSafetyHelper m_safetyHelper;
private boolean m_isInverted = false;
private DigitalOutput m_dio;
private PWM m_pwm;
private volatile double m_speed = 0.0;
private volatile boolean m_disabled = false;
private boolean m_isInverted;
private final DigitalOutput m_dio;
private final PWM m_pwm;
private volatile double m_speed;
private volatile boolean m_disabled;
/**
* Constructor.

View File

@@ -22,15 +22,15 @@ public class Notifier implements AutoCloseable {
private final AtomicInteger m_notifier = new AtomicInteger();
// The time, in microseconds, at which the corresponding handler should be
// called. Has the same zero as Utility.getFPGATime().
private double m_expirationTime = 0;
private double m_expirationTime;
// The handler passed in by the user which should be called at the
// appropriate interval.
private Runnable m_handler;
// Whether we are calling the handler just once or periodically.
private boolean m_periodic = false;
private boolean m_periodic;
// If periodic, the period of the calling; if just once, stores how long it
// is until we call the handler.
private double m_period = 0;
private double m_period;
@Override
@SuppressWarnings("NoFinalizer")

View File

@@ -25,9 +25,10 @@ import static java.util.Objects.requireNonNull;
* and derivative calculations. Therefore, the sample rate affects the controller's behavior for a
* given set of PID constants.
*/
@SuppressWarnings("PMD.TooManyFields")
public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
public static final double kDefaultPeriod = 0.05;
private static int instances = 0;
private static int instances;
// Factor for "proportional" control
@SuppressWarnings("MemberName")
@@ -52,34 +53,34 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
private double m_minimumOutput = -1.0;
// Maximum input - limit setpoint to this
private double m_maximumInput = 0.0;
private double m_maximumInput;
// Minimum input - limit setpoint to this
private double m_minimumInput = 0.0;
private double m_minimumInput;
// Input range - difference between maximum and minimum
private double m_inputRange = 0.0;
private double m_inputRange;
// Do the endpoints wrap around? (e.g., absolute encoder)
private boolean m_continuous = false;
private boolean m_continuous;
// Is the PID controller enabled
protected boolean m_enabled = false;
protected boolean m_enabled;
// The prior error (used to compute velocity)
private double m_prevError = 0.0;
private double m_prevError;
// The sum of the errors for use in the integral calc
private double m_totalError = 0.0;
private double m_totalError;
// The tolerance object used to check if on target
private Tolerance m_tolerance;
private double m_setpoint = 0.0;
private double m_prevSetpoint = 0.0;
private double m_setpoint;
private double m_prevSetpoint;
@SuppressWarnings("PMD.UnusedPrivateField")
private double m_error = 0.0;
private double m_result = 0.0;
private double m_error;
private double m_result;
private PIDSource m_origSource;
private LinearDigitalFilter m_filter;
@@ -110,7 +111,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
public class NullTolerance implements Tolerance {
@Override
public boolean onTarget() {
throw new RuntimeException("No tolerance value set when calling onTarget().");
throw new IllegalStateException("No tolerance value set when calling onTarget().");
}
}
@@ -198,7 +199,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
* Read the input, calculate the output accordingly, and write to the output. This should only be
* called by the PIDTask and is created during initialization.
*/
@SuppressWarnings("LocalVariableName")
@SuppressWarnings({"LocalVariableName", "PMD.ExcessiveMethodLength", "PMD.NPathComplexity"})
protected void calculate() {
if (m_origSource == null || m_pidOutput == null) {
return;
@@ -334,6 +335,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
* @param i Integral coefficient
* @param d Differential coefficient
*/
@Override
@SuppressWarnings("ParameterName")
public void setPID(double p, double i, double d) {
m_thisMutex.lock();
@@ -433,6 +435,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
*
* @return proportional coefficient
*/
@Override
public double getP() {
m_thisMutex.lock();
try {
@@ -447,6 +450,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
*
* @return integral coefficient
*/
@Override
public double getI() {
m_thisMutex.lock();
try {
@@ -461,6 +465,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
*
* @return differential coefficient
*/
@Override
public double getD() {
m_thisMutex.lock();
try {
@@ -508,7 +513,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
*/
public void setContinuous(boolean continuous) {
if (continuous && m_inputRange <= 0) {
throw new RuntimeException("No input range set when calling setContinuous().");
throw new IllegalStateException("No input range set when calling setContinuous().");
}
m_thisMutex.lock();
try {
@@ -573,6 +578,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
*
* @param setpoint the desired setpoint
*/
@Override
public void setSetpoint(double setpoint) {
m_thisMutex.lock();
try {
@@ -597,6 +603,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
*
* @return the current setpoint
*/
@Override
public double getSetpoint() {
m_thisMutex.lock();
try {
@@ -625,6 +632,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
*
* @return the current error
*/
@Override
public double getError() {
m_thisMutex.lock();
try {

View File

@@ -43,7 +43,7 @@ public class PWM extends SendableBase {
k4X
}
private int m_channel;
private final int m_channel;
private int m_handle;
/**

View File

@@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
* Common base class for all PWM Speed Controllers.
*/
public abstract class PWMSpeedController extends SafePWM implements SpeedController {
private boolean m_isInverted = false;
private boolean m_isInverted;
/**
* Constructor.

View File

@@ -31,7 +31,7 @@ import static java.util.Objects.requireNonNull;
* <p> This will also interact with {@link NetworkTable} by creating a table called "Preferences"
* with all the key-value pairs. </p>
*/
public class Preferences {
public final class Preferences {
/**
* The Preferences table name.
*/
@@ -75,6 +75,7 @@ public class Preferences {
* Gets the vector of keys.
* @return a vector of the keys
*/
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
public Vector<String> getKeys() {
return new Vector<>(m_table.getKeys());
}

View File

@@ -90,8 +90,8 @@ public class Relay extends SendableBase implements MotorSafety {
private final int m_channel;
private int m_forwardHandle = 0;
private int m_reverseHandle = 0;
private int m_forwardHandle;
private int m_reverseHandle;
private Direction m_direction;
@@ -150,12 +150,12 @@ public class Relay extends SendableBase implements MotorSafety {
private void freeRelay() {
try {
RelayJNI.setRelay(m_forwardHandle, false);
} catch (UncleanStatusException ex) {
} catch (UncleanStatusException ignored) {
// do nothing. Ignore
}
try {
RelayJNI.setRelay(m_reverseHandle, false);
} catch (UncleanStatusException ex) {
} catch (UncleanStatusException ignored) {
// do nothing. Ignore
}
@@ -179,6 +179,7 @@ public class Relay extends SendableBase implements MotorSafety {
*
* @param value The state to set the relay.
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
public void set(Value value) {
switch (value) {
case kOff:

View File

@@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
* unload/reload.
*/
public final class Resource {
private static Resource resourceList = null;
private static Resource resourceList;
private final boolean[] m_numAllocated;
private final int m_size;
private final Resource m_nextResource;

View File

@@ -8,9 +8,10 @@
package edu.wpi.first.wpilibj;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.util.Enumeration;
import java.util.jar.Manifest;
@@ -188,9 +189,9 @@ public abstract class RobotBase implements AutoCloseable {
if (propVal == null) {
return defaultValue;
}
if (propVal.equalsIgnoreCase("false")) {
if ("false".equalsIgnoreCase(propVal)) {
return false;
} else if (propVal.equalsIgnoreCase("true")) {
} else if ("true".equalsIgnoreCase(propVal)) {
return true;
} else {
throw new IllegalStateException(propVal);
@@ -218,7 +219,8 @@ public abstract class RobotBase implements AutoCloseable {
/**
* Starting point for the applications.
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidCatchingThrowable",
"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public static void main(String... args) {
if (!HAL.initialize(500, 0)) {
throw new IllegalStateException("Failed to initialize. Terminating");
@@ -232,7 +234,8 @@ public abstract class RobotBase implements AutoCloseable {
} else {
Enumeration<URL> resources = null;
try {
resources = RobotBase.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
resources = Thread.currentThread()
.getContextClassLoader().getResources("META-INF/MANIFEST.MF");
} catch (IOException ex) {
ex.printStackTrace();
}
@@ -273,7 +276,7 @@ public abstract class RobotBase implements AutoCloseable {
file.createNewFile();
try (FileOutputStream output = new FileOutputStream(file)) {
try (OutputStream output = Files.newOutputStream(file.toPath())) {
output.write("Java ".getBytes());
output.write(WPILibVersion.Version.getBytes());
}

View File

@@ -25,6 +25,7 @@ import static java.util.Objects.requireNonNull;
* or {@link edu.wpi.first.wpilibj.drive.MecanumDrive} classes instead.
*/
@Deprecated
@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"})
public class RobotDrive implements MotorSafety, AutoCloseable {
protected MotorSafetyHelper m_safetyHelper;
@@ -53,11 +54,11 @@ public class RobotDrive implements MotorSafety, AutoCloseable {
protected SpeedController m_rearLeftMotor;
protected SpeedController m_rearRightMotor;
protected boolean m_allocatedSpeedControllers;
protected static boolean kArcadeRatioCurve_Reported = false;
protected static boolean kTank_Reported = false;
protected static boolean kArcadeStandard_Reported = false;
protected static boolean kMecanumCartesian_Reported = false;
protected static boolean kMecanumPolar_Reported = false;
protected static boolean kArcadeRatioCurve_Reported;
protected static boolean kTank_Reported;
protected static boolean kArcadeStandard_Reported;
protected static boolean kMecanumCartesian_Reported;
protected static boolean kMecanumPolar_Reported;
/**
* Constructor for RobotDrive with 2 motors specified with channel numbers. Set up parameters for

View File

@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException;
@SuppressWarnings("JavadocMethod")
public class RobotState {
public final class RobotState {
private static Interface m_impl;
@SuppressWarnings("MethodName")
@@ -69,4 +69,7 @@ public class RobotState {
boolean isTest();
}
private RobotState() {
}
}

View File

@@ -16,6 +16,7 @@ import edu.wpi.first.wpilibj.hal.SPIJNI;
/**
* Represents a SPI bus port.
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.TooManyMethods"})
public class SPI implements AutoCloseable {
public enum Port {
kOnboardCS0(0), kOnboardCS1(1), kOnboardCS2(2), kOnboardCS3(3), kMXP(4);
@@ -28,7 +29,7 @@ public class SPI implements AutoCloseable {
}
}
private static int devices = 0;
private static int devices;
private int m_port;
private int m_bitOrder;
@@ -268,6 +269,7 @@ public class SPI implements AutoCloseable {
* @param dataReceived Buffer to receive data from the device.
* @param size The length of the transaction, in bytes
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
public int transaction(ByteBuffer dataToSend, ByteBuffer dataReceived, int size) {
if (dataToSend.hasArray() && dataReceived.hasArray()) {
return transaction(dataToSend.array(), dataReceived.array(), size);
@@ -420,6 +422,7 @@ public class SPI implements AutoCloseable {
private static final int kAccumulateDepth = 2048;
@SuppressWarnings("PMD.TooManyFields")
private static class Accumulator implements AutoCloseable {
Accumulator(int port, int xferSize, int validMask, int validValue, int dataShift,
int dataSize, boolean isSigned, boolean bigEndian) {
@@ -462,6 +465,7 @@ public class SPI implements AutoCloseable {
final boolean m_bigEndian; // is response big endian?
final int m_port;
@SuppressWarnings("PMD.CyclomaticComplexity")
void update() {
synchronized (m_mutex) {
boolean done = false;
@@ -527,7 +531,7 @@ public class SPI implements AutoCloseable {
}
}
private Accumulator m_accum = null;
private Accumulator m_accum;
/**
* Initialize the accumulator.

View File

@@ -32,6 +32,7 @@ public class SafePWM extends PWM implements MotorSafety {
*
* @param timeout The timeout (in seconds) for this motor object
*/
@Override
public void setExpiration(double timeout) {
m_safetyHelper.setExpiration(timeout);
}
@@ -41,6 +42,7 @@ public class SafePWM extends PWM implements MotorSafety {
*
* @return The expiration time value.
*/
@Override
public double getExpiration() {
return m_safetyHelper.getExpiration();
}
@@ -50,6 +52,7 @@ public class SafePWM extends PWM implements MotorSafety {
*
* @return a bool value that is true if the motor has NOT timed out and should still be running.
*/
@Override
public boolean isAlive() {
return m_safetyHelper.isAlive();
}
@@ -58,6 +61,7 @@ public class SafePWM extends PWM implements MotorSafety {
* Stop the motor associated with this PWM object. This is called by the MotorSafetyHelper object
* when it has a timeout for this PWM and needs to stop it from running.
*/
@Override
public void stopMotor() {
disable();
}
@@ -67,6 +71,7 @@ public class SafePWM extends PWM implements MotorSafety {
*
* @return True if motor safety is enforced for this object
*/
@Override
public boolean isSafetyEnabled() {
return m_safetyHelper.isSafetyEnabled();
}
@@ -91,10 +96,12 @@ public class SafePWM extends PWM implements MotorSafety {
m_safetyHelper.feed();
}
@Override
public void setSafetyEnabled(boolean enabled) {
m_safetyHelper.setSafetyEnabled(enabled);
}
@Override
public String getDescription() {
return "PWM " + getChannel();
}

View File

@@ -114,6 +114,8 @@ public class SampleRobot extends RobotBase {
* state to change, either the other mode starts or the robot is disabled. Then go back and wait
* for the robot to be enabled again.
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
@Override
public void startCompetition() {
robotInit();

View File

@@ -24,6 +24,7 @@ import edu.wpi.first.wpilibj.hal.SerialPortJNI;
* .com/pdf/manuals/370423a.pdf and the NI-VISA Programmer's Reference Manual here:
* http://www.ni.com/pdf/manuals/370132c.pdf
*/
@SuppressWarnings("PMD.TooManyMethods")
public class SerialPort implements AutoCloseable {
private byte m_port;

View File

@@ -13,15 +13,16 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
* Allows multiple {@link SpeedController} objects to be linked together.
*/
public class SpeedControllerGroup extends SendableBase implements SpeedController {
private boolean m_isInverted = false;
private boolean m_isInverted;
private final SpeedController[] m_speedControllers;
private static int instances = 0;
private static int instances;
/**
* Create a new SpeedControllerGroup with the provided SpeedControllers.
*
* @param speedControllers The SpeedControllers to add
*/
@SuppressWarnings("PMD.AvoidArrayLoops")
public SpeedControllerGroup(SpeedController speedController,
SpeedController... speedControllers) {
m_speedControllers = new SpeedController[speedControllers.length + 1];

View File

@@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.hal.ThreadsJNI;
public class Threads {
public final class Threads {
/**
* Get the thread priority for the current thread.
* @return The current thread priority. Scaled 1-99.
@@ -39,4 +39,7 @@ public class Threads {
public static boolean setCurrentThreadPriority(boolean realTime, int priority) {
return ThreadsJNI.setCurrentThreadPriority(realTime, priority);
}
private Threads() {
}
}

View File

@@ -23,14 +23,14 @@ public class TimedRobot extends IterativeRobotBase {
public static final double kDefaultPeriod = 0.02;
// Prevents loop from starting if user calls setPeriod() in robotInit()
private boolean m_startLoop = false;
private boolean m_startLoop;
// The C pointer to the notifier object. We don't use it directly, it is
// just passed to the JNI bindings.
private final int m_notifier = NotifierJNI.initializeNotifier();
// The absolute expiration time
private double m_expirationTime = 0;
private double m_expirationTime;
private double m_period = kDefaultPeriod;
@@ -49,6 +49,7 @@ public class TimedRobot extends IterativeRobotBase {
/**
* Provide an alternate "main loop" via startCompetition().
*/
@Override
public void startCompetition() {
robotInit();

View File

@@ -41,19 +41,19 @@ public class Ultrasonic extends SendableBase implements PIDSource {
private static final double kPingTime = 10 * 1e-6;
private static final double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0;
// head of the ultrasonic sensor list
private static Ultrasonic m_firstSensor = null;
private static Ultrasonic m_firstSensor;
// automatic round robin mode
private static boolean m_automaticEnabled = false;
private static boolean m_automaticEnabled;
private DigitalInput m_echoChannel;
private DigitalOutput m_pingChannel = null;
private DigitalOutput m_pingChannel;
private boolean m_allocatedChannels;
private boolean m_enabled = false;
private Counter m_counter = null;
private Ultrasonic m_nextSensor = null;
private boolean m_enabled;
private Counter m_counter;
private Ultrasonic m_nextSensor;
// task doing the round-robin automatic sensing
private static Thread m_task = null;
private static Thread m_task;
private Unit m_units;
private static int m_instances = 0;
private static int m_instances;
protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
/**
@@ -190,6 +190,7 @@ public class Ultrasonic extends SendableBase implements PIDSource {
* stopped, then started again after this sensor is removed (provided this wasn't the last
* sensor).
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
@Override
public synchronized void close() {
super.close();

View File

@@ -33,7 +33,7 @@ public class XboxController extends GenericHID {
kBack(7),
kStart(8);
@SuppressWarnings("MemberName")
@SuppressWarnings({"MemberName", "PMD.SingularField"})
private int value;
Button(int value) {

View File

@@ -40,6 +40,7 @@ public class InternalButton extends Button {
m_pressed = pressed;
}
@Override
public boolean get() {
return m_pressed ^ m_inverted;
}

View File

@@ -33,6 +33,7 @@ public class JoystickButton extends Button {
*
* @return The value of the joystick button
*/
@Override
public boolean get() {
return m_joystick.getRawButton(m_buttonNumber);
}

View File

@@ -25,6 +25,7 @@ public class NetworkButton extends Button {
m_entry = table.getEntry(field);
}
@Override
public boolean get() {
return m_entry.getInstance().isConnected() && m_entry.getBoolean(false);
}

View File

@@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
* the full functionality of the Trigger class.
*/
public abstract class Trigger extends SendableBase {
private volatile boolean m_sendablePressed = false;
private volatile boolean m_sendablePressed;
/**
* Returns whether or not the trigger is active.

View File

@@ -39,6 +39,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
* @see CommandGroup
* @see IllegalUseOfCommandException
*/
@SuppressWarnings("PMD.TooManyMethods")
public abstract class Command extends SendableBase {
/**
* The time since this command was initialized.
@@ -53,7 +54,7 @@ public abstract class Command extends SendableBase {
/**
* Whether or not this command has been initialized.
*/
private boolean m_initialized = false;
private boolean m_initialized;
/**
* The required subsystems.
@@ -63,7 +64,7 @@ public abstract class Command extends SendableBase {
/**
* Whether or not it is running.
*/
private boolean m_running = false;
private boolean m_running;
/**
* Whether or not it is interruptible.
@@ -73,22 +74,22 @@ public abstract class Command extends SendableBase {
/**
* Whether or not it has been canceled.
*/
private boolean m_canceled = false;
private boolean m_canceled;
/**
* Whether or not it has been locked.
*/
private boolean m_locked = false;
private boolean m_locked;
/**
* Whether this command should run when the robot is disabled.
*/
private boolean m_runWhenDisabled = false;
private boolean m_runWhenDisabled;
/**
* Whether or not this command has completed running.
*/
private boolean m_completed = false;
private boolean m_completed;
/**
* The {@link CommandGroup} this is in.

View File

@@ -31,10 +31,12 @@ import static java.util.Objects.requireNonNull;
* @see Subsystem
* @see IllegalUseOfCommandException
*/
@SuppressWarnings("PMD.TooManyMethods")
public class CommandGroup extends Command {
/**
* The commands in this group (stored in entries).
*/
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
private final Vector<Entry> m_commands = new Vector<>();
/*
* Intentionally package private
@@ -42,6 +44,7 @@ public class CommandGroup extends Command {
/**
* The active children in this group (stored in entries).
*/
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
final Vector<Entry> m_children = new Vector<>();
/**
* The current command, -1 signifies that none have been run.
@@ -206,12 +209,14 @@ public class CommandGroup extends Command {
}
}
@Override
@SuppressWarnings("MethodName")
void _initialize() {
m_currentCommandIndex = -1;
}
@SuppressWarnings("MethodName")
@Override
@SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
void _execute() {
Entry entry = null;
Command cmd = null;
@@ -278,6 +283,7 @@ public class CommandGroup extends Command {
}
}
@Override
@SuppressWarnings("MethodName")
void _end() {
// Theoretically, we don't have to check this, but we do if teams override
@@ -297,6 +303,7 @@ public class CommandGroup extends Command {
m_children.removeAllElements();
}
@Override
@SuppressWarnings("MethodName")
void _interrupted() {
_end();
@@ -311,23 +318,28 @@ public class CommandGroup extends Command {
*
* @return whether this {@link CommandGroup} is finished
*/
@Override
protected boolean isFinished() {
return m_currentCommandIndex >= m_commands.size() && m_children.isEmpty();
}
// Can be overwritten by teams
@Override
protected void initialize() {
}
// Can be overwritten by teams
@Override
protected void execute() {
}
// Can be overwritten by teams
@Override
protected void end() {
}
// Can be overwritten by teams
@Override
protected void interrupted() {
}
@@ -338,6 +350,7 @@ public class CommandGroup extends Command {
*
* @return whether or not this {@link CommandGroup} is interruptible.
*/
@Override
public synchronized boolean isInterruptible() {
if (!super.isInterruptible()) {
return false;

View File

@@ -45,7 +45,7 @@ public abstract class ConditionalCommand extends Command {
/**
* Stores command chosen by condition.
*/
private Command m_chosenCommand = null;
private Command m_chosenCommand;
private void requireAll() {
if (m_onTrue != null) {

View File

@@ -25,6 +25,7 @@ public class InstantCommand extends Command {
super(name);
}
@Override
protected boolean isFinished() {
return true;
}

View File

@@ -33,13 +33,16 @@ public abstract class PIDCommand extends Command {
* A source which calls {@link PIDCommand#returnPIDInput()}.
*/
private final PIDSource m_source = new PIDSource() {
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
}
@Override
public PIDSourceType getPIDSourceType() {
return PIDSourceType.kDisplacement;
}
@Override
public double pidGet() {
return returnPIDInput();
}

View File

@@ -35,13 +35,16 @@ public abstract class PIDSubsystem extends Subsystem {
* A source which calls {@link PIDCommand#returnPIDInput()}.
*/
private final PIDSource m_source = new PIDSource() {
@Override
public void setPIDSourceType(PIDSourceType pidSource) {
}
@Override
public PIDSourceType getPIDSourceType() {
return PIDSourceType.kDisplacement;
}
@Override
public double pidGet() {
return returnPIDInput();
}

View File

@@ -16,7 +16,7 @@ public class PrintCommand extends InstantCommand {
/**
* The message to print out.
*/
private String m_message;
private final String m_message;
/**
* Instantiates a {@link PrintCommand} which will print the given message when it is run.
@@ -28,6 +28,7 @@ public class PrintCommand extends InstantCommand {
m_message = message;
}
@Override
protected void initialize() {
System.out.println(m_message);
}

View File

@@ -29,7 +29,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
*
* @see Command
*/
public class Scheduler extends SendableBase {
public final class Scheduler extends SendableBase {
/**
* The Singleton Instance.
*/
@@ -50,11 +50,12 @@ public class Scheduler extends SendableBase {
/**
* A hashtable of active {@link Command Commands} to their {@link LinkedListElement}.
*/
private Hashtable<Command, LinkedListElement> m_commandTable = new Hashtable<>();
@SuppressWarnings("PMD.LooseCoupling")
private final Hashtable<Command, LinkedListElement> m_commandTable = new Hashtable<>();
/**
* The {@link Set} of all {@link Subsystem Subsystems}.
*/
private Set m_subsystems = new Set();
private final Set m_subsystems = new Set();
/**
* The first {@link Command} in the list.
*/
@@ -66,15 +67,16 @@ public class Scheduler extends SendableBase {
/**
* Whether or not we are currently adding a command.
*/
private boolean m_adding = false;
private boolean m_adding;
/**
* Whether or not we are currently disabled.
*/
private boolean m_disabled = false;
private boolean m_disabled;
/**
* A list of all {@link Command Commands} which need to be added.
*/
private Vector<Command> m_additions = new Vector<>();
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
private final Vector<Command> m_additions = new Vector<>();
private NetworkTableEntry m_namesEntry;
private NetworkTableEntry m_idsEntry;
private NetworkTableEntry m_cancelEntry;
@@ -82,6 +84,7 @@ public class Scheduler extends SendableBase {
* A list of all {@link edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler Buttons}. It is
* created lazily.
*/
@SuppressWarnings("PMD.LooseCoupling")
private Vector<ButtonScheduler> m_buttons;
private boolean m_runningCommandsChanged;
@@ -115,6 +118,7 @@ public class Scheduler extends SendableBase {
*
* @param button the button to add
*/
@SuppressWarnings("PMD.UseArrayListInsteadOfVector")
public void addButton(ButtonScheduler button) {
if (m_buttons == null) {
m_buttons = new Vector<>();
@@ -129,7 +133,7 @@ public class Scheduler extends SendableBase {
*
* @param command the {@link Command} to add
*/
@SuppressWarnings("MethodName")
@SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity"})
private void _add(Command command) {
if (command == null) {
return;
@@ -189,6 +193,7 @@ public class Scheduler extends SendableBase {
* <ol> <li>Poll the Buttons</li> <li>Execute/Remove the Commands</li> <li>Send values to
* SmartDashboard</li> <li>Add Commands</li> <li>Add Defaults</li> </ol>
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public void run() {
m_runningCommandsChanged = false;

View File

@@ -15,7 +15,7 @@ public class StartCommand extends InstantCommand {
/**
* The command to fork.
*/
private Command m_commandToFork;
private final Command m_commandToFork;
/**
* Instantiates a {@link StartCommand} which will start the given command whenever its {@link
@@ -28,6 +28,7 @@ public class StartCommand extends InstantCommand {
m_commandToFork = commandToStart;
}
@Override
protected void initialize() {
m_commandToFork.start();
}

View File

@@ -32,7 +32,7 @@ public abstract class Subsystem extends SendableBase {
/**
* Whether or not getDefaultCommand() was called.
*/
private boolean m_initializedDefaultCommand = false;
private boolean m_initializedDefaultCommand;
/**
* The current command.
*/

View File

@@ -34,6 +34,7 @@ public class TimedCommand extends Command {
/**
* Ends command when timed out.
*/
@Override
protected boolean isFinished() {
return isTimedOut();
}

View File

@@ -16,6 +16,7 @@ package edu.wpi.first.wpilibj.command;
* to finish, before continuing in the main {@link CommandGroup} sequence.
*/
public class WaitForChildren extends Command {
@Override
protected boolean isFinished() {
return getGroup() == null || getGroup().m_children.isEmpty();
}

View File

@@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.Timer;
* some value, then continue to the next command.
*/
public class WaitUntilCommand extends Command {
private double m_time;
private final double m_time;
public WaitUntilCommand(double time) {
super("WaitUntil(" + time + ")");
@@ -24,6 +24,7 @@ public class WaitUntilCommand extends Command {
/**
* Check if we've reached the actual finish time.
*/
@Override
public boolean isFinished() {
return Timer.getMatchTime() >= m_time;
}

View File

@@ -95,16 +95,16 @@ public class DifferentialDrive extends RobotDriveBase {
public static final double kDefaultQuickStopThreshold = 0.2;
public static final double kDefaultQuickStopAlpha = 0.1;
private static int instances = 0;
private static int instances;
private SpeedController m_leftMotor;
private SpeedController m_rightMotor;
private final SpeedController m_leftMotor;
private final SpeedController m_rightMotor;
private double m_quickStopThreshold = kDefaultQuickStopThreshold;
private double m_quickStopAlpha = kDefaultQuickStopAlpha;
private double m_quickStopAccumulator = 0.0;
private double m_quickStopAccumulator;
private double m_rightSideInvertMultiplier = -1.0;
private boolean m_reported = false;
private boolean m_reported;
/**
* Construct a DifferentialDrive.
@@ -207,7 +207,7 @@ public class DifferentialDrive extends RobotDriveBase {
* @param isQuickTurn If set, overrides constant-curvature turning for
* turn-in-place maneuvers.
*/
@SuppressWarnings("ParameterName")
@SuppressWarnings({"ParameterName", "PMD.CyclomaticComplexity"})
public void curvatureDrive(double xSpeed, double zRotation, boolean isQuickTurn) {
if (!m_reported) {
// HAL.report(tResourceType.kResourceType_RobotDrive, 2, tInstances.kRobotDrive_Curvature);

View File

@@ -42,7 +42,7 @@ public class KilloughDrive extends RobotDriveBase {
public static final double kDefaultRightMotorAngle = 120.0;
public static final double kDefaultBackMotorAngle = 270.0;
private static int instances = 0;
private static int instances;
private SpeedController m_leftMotor;
private SpeedController m_rightMotor;
@@ -52,7 +52,7 @@ public class KilloughDrive extends RobotDriveBase {
private Vector2d m_rightVec;
private Vector2d m_backVec;
private boolean m_reported = false;
private boolean m_reported;
/**
* Construct a Killough drive with the given motors and default motor angles.

View File

@@ -57,15 +57,15 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
* deadband of 0 is used.
*/
public class MecanumDrive extends RobotDriveBase {
private static int instances = 0;
private static int instances;
private SpeedController m_frontLeftMotor;
private SpeedController m_rearLeftMotor;
private SpeedController m_frontRightMotor;
private SpeedController m_rearRightMotor;
private final SpeedController m_frontLeftMotor;
private final SpeedController m_rearLeftMotor;
private final SpeedController m_frontRightMotor;
private final SpeedController m_rearRightMotor;
private double m_rightSideInvertMultiplier = -1.0;
private boolean m_reported = false;
private boolean m_reported;
/**
* Construct a MecanumDrive.

View File

@@ -12,8 +12,8 @@ package edu.wpi.first.wpilibj.drive;
*/
@SuppressWarnings("MemberName")
public class Vector2d {
public double x = 0.0;
public double y = 0.0;
public double x;
public double y;
public Vector2d() {}

View File

@@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.PIDSourceType;
* Superclass for filters.
*/
public abstract class Filter implements PIDSource {
private PIDSource m_source;
private final PIDSource m_source;
public Filter(PIDSource source) {
m_source = source;

View File

@@ -50,10 +50,10 @@ import edu.wpi.first.wpilibj.PIDSource;
* to make sure PIDGet() gets called at the desired, constant frequency!
*/
public class LinearDigitalFilter extends Filter {
private CircularBuffer m_inputs;
private CircularBuffer m_outputs;
private double[] m_inputGains;
private double[] m_outputGains;
private final CircularBuffer m_inputs;
private final CircularBuffer m_outputs;
private final double[] m_inputGains;
private final double[] m_outputGains;
/**
* Create a linear FIR or IIR filter.
@@ -62,8 +62,8 @@ public class LinearDigitalFilter extends Filter {
* @param ffGains The "feed forward" or FIR gains
* @param fbGains The "feed back" or IIR gains
*/
public LinearDigitalFilter(PIDSource source, double[] ffGains,
double[] fbGains) {
public LinearDigitalFilter(PIDSource source, double[] ffGains, //NOPMD - PR1105 will fix this
double[] fbGains) { //NOPMD - PR1105 will fix this
super(source);
m_inputs = new CircularBuffer(ffGains.length);
m_outputs = new CircularBuffer(fbGains.length);

View File

@@ -80,6 +80,7 @@ public class HardwareTimer implements Timer.StaticInterface {
*
* @return Current time value for this timer in seconds
*/
@Override
public synchronized double get() {
if (m_running) {
return ((getMsClock() - m_startTime) + m_accumulatedTime) / 1000.0;
@@ -92,6 +93,7 @@ public class HardwareTimer implements Timer.StaticInterface {
* Reset the timer by setting the time to 0. Make the timer start time the current time so new
* requests will be relative now
*/
@Override
public synchronized void reset() {
m_accumulatedTime = 0;
m_startTime = getMsClock();
@@ -101,6 +103,7 @@ public class HardwareTimer implements Timer.StaticInterface {
* Start the timer running. Just set the running flag to true indicating that all time
* requests should be relative to the system clock.
*/
@Override
public synchronized void start() {
m_startTime = getMsClock();
m_running = true;
@@ -111,6 +114,7 @@ public class HardwareTimer implements Timer.StaticInterface {
* subsequent time requests to be read from the accumulated time rather than looking at the
* system clock.
*/
@Override
public synchronized void stop() {
final double temp = get();
m_accumulatedTime = temp;
@@ -125,6 +129,7 @@ public class HardwareTimer implements Timer.StaticInterface {
* @param period The period to check for (in seconds).
* @return If the period has passed.
*/
@Override
public synchronized boolean hasPeriodPassed(double period) {
if (get() > period) {
// Advance the start time by the period.

View File

@@ -22,6 +22,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
* The LiveWindow class is the public interface for putting sensors and actuators on the
* LiveWindow.
*/
@SuppressWarnings("PMD.TooManyMethods")
public class LiveWindow {
private static class Component {
Component(Sendable sendable, Sendable parent) {
@@ -36,13 +37,14 @@ public class LiveWindow {
boolean m_telemetryEnabled = true;
}
@SuppressWarnings("PMD.UseConcurrentHashMap")
private static final Map<Object, Component> components = new HashMap<>();
private static final NetworkTable liveWindowTable =
NetworkTableInstance.getDefault().getTable("LiveWindow");
private static final NetworkTable statusTable = liveWindowTable.getSubTable(".status");
private static final NetworkTableEntry enabledEntry = statusTable.getEntry("LW Enabled");
private static boolean startLiveWindow = false;
private static boolean liveWindowEnabled = false;
private static boolean startLiveWindow;
private static boolean liveWindowEnabled;
private static boolean telemetryEnabled = true;
private LiveWindow() {
@@ -245,6 +247,7 @@ public class LiveWindow {
* <p>Actuators are handled through callbacks on their value changing from the
* SmartDashboard widgets.
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
public static synchronized void updateValues() {
// Only do this if either LiveWindow mode or telemetry is enabled.
if (!liveWindowEnabled && !telemetryEnabled) {

View File

@@ -21,6 +21,7 @@ import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableValue;
@SuppressWarnings("PMD.TooManyMethods")
public class SendableBuilderImpl implements SendableBuilder {
private static class Property {
Property(NetworkTable table, String key) {
@@ -29,7 +30,7 @@ public class SendableBuilderImpl implements SendableBuilder {
@Override
@SuppressWarnings("NoFinalizer")
public synchronized void finalize() {
protected synchronized void finalize() {
stopListener();
}
@@ -47,7 +48,7 @@ public class SendableBuilderImpl implements SendableBuilder {
}
final NetworkTableEntry m_entry;
int m_listener = 0;
int m_listener;
Consumer<NetworkTableEntry> m_update;
Function<NetworkTableEntry, Integer> m_createListener;
}

View File

@@ -43,6 +43,7 @@ public class SendableChooser<V> extends SendableBase {
/**
* A map linking strings to the objects the represent.
*/
@SuppressWarnings("PMD.LooseCoupling")
private final LinkedHashMap<String, V> m_map = new LinkedHashMap<>();
private String m_defaultChoice = "";

View File

@@ -25,6 +25,7 @@ import edu.wpi.first.wpilibj.Sendable;
* <p>When a value is put into the SmartDashboard here, it pops up on the SmartDashboard on the
* laptop. Users can put values into and get values from the SmartDashboard.
*/
@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"})
public class SmartDashboard {
/**
* The {@link NetworkTable} used by {@link SmartDashboard}.
@@ -45,6 +46,7 @@ public class SmartDashboard {
* A table linking tables in the SmartDashboard to the {@link Sendable} objects they
* came from.
*/
@SuppressWarnings("PMD.UseConcurrentHashMap")
private static final Map<String, Data> tablesToData = new HashMap<>();
static {

View File

@@ -47,6 +47,7 @@ public class SortedVector<E> extends Vector<E> {
*
* @param element The element to add to the Vector
*/
@Override
public void addElement(E element) {
int highBound = size();
int lowBound = 0;