Skip to content

Commit

Permalink
chore: Fix or suppress new PMD warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
msoucy committed Dec 8, 2024
1 parent 99eace9 commit c465568
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 98 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"addDeprecated",
"addOverride",
"invertEquals",
"qualifyMembers",
"stringConcatToTextBlock"
],
"java.completion.favoriteStaticMembers": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ java {
}

pmd {
toolVersion = "6.54.0"
toolVersion = "7.2.0"
ruleSets = []
ruleSetFiles = files("$rootProject.projectDir/config/pmd-ruleset.xml")
}
4 changes: 2 additions & 2 deletions config/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<exclude name="ShortMethodName"/>
<exclude name="ShortVariable"/>
<exclude name="UseUnderscoresInNumericLiterals"/>
<exclude name="VariableNamingConventions"/>
<exclude name="UselessParentheses"/>
<exclude name="UseExplicitTypes"/>
</rule>
<rule ref="category/java/design.xml">
<exclude name="AbstractClassWithoutAnyMethod"/>
Expand All @@ -40,7 +41,6 @@
<rule ref="category/java/errorprone.xml">
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="CloseResource"/>
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="NonSerializableClass"/>
<exclude name="NonStaticInitializer"/>
</rule>
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/chopshop166/chopshoplib/ColorMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private static double scalarLerp(final double start, final double end, final dou
* @return a blend of the two colors based on the factor
*/
public static Color lerp(final Color start, final Color end, final double factor) {
return new Color(ColorMath.scalarLerp(start.red, end.red, factor),
ColorMath.scalarLerp(start.green, end.green, factor),
ColorMath.scalarLerp(start.blue, end.blue, factor));
return new Color(scalarLerp(start.red, end.red, factor),
scalarLerp(start.green, end.green, factor),
scalarLerp(start.blue, end.blue, factor));
}
}
22 changes: 11 additions & 11 deletions core/src/main/java/com/chopshop166/chopshoplib/RobotUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* Utilities that are related to overall robot functionality.
*/
public final class RobotUtils {
private RobotUtils() {
}
private RobotUtils() {}

/**
* Get a value if it exists, or a default value if it's null.
*
* @param <T> The type to get.
* @param value The value to test.
* @param <T> The type to get.
* @param value The value to test.
* @param defaultValue The default value for if value is null.
* @return A null safe value
*/
Expand Down Expand Up @@ -55,7 +54,7 @@ public static Double[] toBoxed(final double... args) {
*
* @param minBound The lowest possible value.
* @param maxBound The highest possible value.
* @param value The value to clamp.
* @param value The value to clamp.
* @return The provided value, clamped between minBound and maxBound.
*/
public static double clamp(final double minBound, final double maxBound, final double value) {
Expand All @@ -67,7 +66,7 @@ public static double clamp(final double minBound, final double maxBound, final d
*
* @param minBound The lowest possible value.
* @param maxBound The highest possible value.
* @param value The value to clamp.
* @param value The value to clamp.
* @return The provided value, clamped between minBound and maxBound.
*/
public static float clamp(final float minBound, final float maxBound, final float value) {
Expand All @@ -79,7 +78,7 @@ public static float clamp(final float minBound, final float maxBound, final floa
*
* @param minBound The lowest possible value.
* @param maxBound The highest possible value.
* @param value The value to clamp.
* @param value The value to clamp.
* @return The provided value, clamped between minBound and maxBound.
*/
public static int clamp(final int minBound, final int maxBound, final int value) {
Expand All @@ -91,7 +90,7 @@ public static int clamp(final int minBound, final int maxBound, final int value)
*
* @param minBound The lowest possible value.
* @param maxBound The highest possible value.
* @param value The value to clamp.
* @param value The value to clamp.
* @return The provided value, clamped between minBound and maxBound.
*/
public static long clamp(final long minBound, final long maxBound, final long value) {
Expand All @@ -112,7 +111,7 @@ public static double sps(final double value) {
* Sign Preserving Power
*
* @param value The value to multiply.
* @param exp The value to exponentiate by.
* @param exp The value to exponentiate by.
* @return The square of the given value, preserving sign.
*/
public static double sppow(final double value, final double exp) {
Expand All @@ -123,7 +122,7 @@ public static double sppow(final double value, final double exp) {
* Apply a deadband to an axis, elongating the remaining space.
*
* @param range The range to deaden.
* @param axis The axis to pull from.
* @param axis The axis to pull from.
* @return The new axis to use.
*/
public static DoubleSupplier deadbandAxis(final double range, final DoubleSupplier axis) {
Expand All @@ -146,6 +145,7 @@ public static BooleanSupplier not(final BooleanSupplier func) {
*
* @return The MAC address as a standardized string.
*/
@SuppressWarnings("PMD.ExceptionAsFlowControl")
public static String getMACAddress() {
try {
final NetworkInterface iface = NetworkInterface.getByName("eth0");
Expand All @@ -161,7 +161,7 @@ public static String getMACAddress() {
sb.add(String.format("%02X", octet));
}
return sb.toString();
} catch (SocketException ex) {
} catch (final SocketException ex) {
return "SocketException";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Command safeStateSubsystems(final SmartSubsystem... subsystems) {
* @return An instance of the given type, or null.
*/
public static <T> T getRobotMap(final Class<T> rootClass, final String pkg) {
return CommandRobot.getRobotMap(rootClass, pkg, null);
return getRobotMap(rootClass, pkg, null);
}

/**
Expand All @@ -187,7 +187,7 @@ public static <T> T getRobotMap(final Class<T> rootClass, final String pkg) {
public <T> T getRobotMap(final Class<T> rootClass, final T defaultValue) {
final Class<? extends CommandRobot> clazz = this.getClass();
final String pkg = clazz.getPackage().getName();
return CommandRobot.getRobotMap(rootClass, pkg, defaultValue);
return getRobotMap(rootClass, pkg, defaultValue);
}

/**
Expand All @@ -201,7 +201,7 @@ public <T> T getRobotMap(final Class<T> rootClass, final T defaultValue) {
*/
public static <T> T getRobotMap(final Class<T> rootClass, final String pkg,
final T defaultValue) {
return CommandRobot.getMapForName(RobotUtils.getMACAddress(), rootClass, pkg, defaultValue);
return getMapForName(RobotUtils.getMACAddress(), rootClass, pkg, defaultValue);
}

/**
Expand All @@ -215,7 +215,7 @@ public static <T> T getRobotMap(final Class<T> rootClass, final String pkg,
*/
public static <T> T getMapForName(final String name, final Class<T> rootClass,
final String pkg) {
return CommandRobot.getMapForName(name, rootClass, pkg, null);
return getMapForName(name, rootClass, pkg, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ public class RepeatWhileCommand extends Command {
/** The command to repeat. */
private final Command cmd;

/**
* Create a command that repeats a command while a condition is true.
*
* @param name The name of the command.
* @param cmd The command to repeat.
* @param cond The condition to test.
*/
public RepeatWhileCommand(final String name, final Command cmd, final BooleanSupplier cond) {
this(cmd, cond);
this.setName(name);
}

/**
* Create a command that repeats a command while a condition is true.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum POVDirection {
UP_LEFT(315);

/** The angle of the direction enum. */
private int dPadRotation;
private final int dPadRotation;

// Returns an integer representing the angle on the POV.
private int getAngle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class DiffDriveSubsystem
*
* @param map The object mapping hardware to software objects.
*/
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
public DiffDriveSubsystem(final DifferentialDriveMap map) {
super(new DifferentialDriveData(), map);
this.odometry = new DifferentialDriveOdometry(this.getRotation(), 0.0, 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public SDSSwerveModule(final Translation2d moduleLocation, final CtreEncoder ste
this.location = moduleLocation;
this.steeringEncoder = steeringEncoder;
this.steeringController = steeringController;
this.driveController = SDSSwerveModule.configureDriveMotor(driveController, conf);
this.driveController = configureDriveMotor(driveController, conf);
this.steeringPID = pid;
this.steeringPID.enableContinuousInput(-180, 180);
this.steeringErrorDriveRatio = steeringErrorDriveRatio;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public SegmentConfig mirrorSegment(final SegmentConfig origConfig, final ColorFo
* @param config The segment.
* @param tags The string tags.
*/
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops"})
public void addTags(final SegmentConfig config, final String... tags) {
for (final String tag : tags) {
this.segmentTagMap.putIfAbsent(tag, new HashSet<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected Color heatToColor(final byte h) {
private void calculateFire(final int sparks) {
// Cool down each cell a little
for (int i = 1; i < this.heat.length; i++) {
final int cooldown = this.rand.nextInt((this.heat.length * 10) / this.heat.length + 2);
final int cooldown = this.rand.nextInt(12);

if (cooldown > this.heat[i]) {
this.heat[i] = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LoggedSubsystem(final D ioData, final M map) {
*
* @return The data object.
*/
public D getData() {
public final D getData() {
return this.ioData;
}

Expand All @@ -44,7 +44,7 @@ public D getData() {
*
* @return The data object.
*/
public M getMap() {
public final M getMap() {
return this.map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.function.BooleanSupplier;
import java.util.function.DoublePredicate;
import java.util.function.DoubleUnaryOperator;

import com.chopshop166.chopshoplib.SampleBuffer;
import com.google.common.math.Stats;

Expand All @@ -20,7 +19,7 @@ public interface Modifier extends DoubleUnaryOperator {
* @return The new speed.
*/
static Modifier upperLimit(final BooleanSupplier limit) {
return Modifier.speedFilter(speed -> speed > 0.0 && limit.getAsBoolean());
return speedFilter(speed -> speed > 0.0 && limit.getAsBoolean());
}

/**
Expand All @@ -30,7 +29,7 @@ static Modifier upperLimit(final BooleanSupplier limit) {
* @return The new speed.
*/
static Modifier lowerLimit(final BooleanSupplier limit) {
return Modifier.speedFilter(speed -> speed < 0.0 && limit.getAsBoolean());
return speedFilter(speed -> speed < 0.0 && limit.getAsBoolean());
}

/**
Expand All @@ -40,7 +39,7 @@ static Modifier lowerLimit(final BooleanSupplier limit) {
* @return The new speed.
*/
static Modifier deadband(final double band) {
return Modifier.speedFilter(speed -> Math.abs(speed) < band);
return speedFilter(speed -> Math.abs(speed) < band);
}

/**
Expand Down Expand Up @@ -69,7 +68,7 @@ static Modifier scalingDeadband(final double range) {
*/
static Modifier rollingAverage(final int numSamples) {
/** The samples to average. */
final SampleBuffer<Double> buffer = new SampleBuffer<>(numSamples);
final var buffer = new SampleBuffer<Double>(numSamples);
return speed -> {
buffer.add(speed);
return Stats.of(buffer).mean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public class ModifierGroup extends ArrayList<DoubleUnaryOperator> implements Dou
* @param ms Modifiers to start with.
*/
public ModifierGroup(final DoubleUnaryOperator... ms) {
super();
this.addAll(Arrays.asList(ms));
super(Arrays.asList(ms));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static SwPIDMotorController position(final MotorController motor,
*/
public static SwPIDMotorController position(final SmartMotorController motor,
final PIDController pid) {
return SwPIDMotorController.position(motor, pid, motor.getEncoder());
return position(motor, pid, motor.getEncoder());
}

/**
Expand All @@ -77,7 +77,7 @@ public static SwPIDMotorController velocity(final MotorController motor,
*/
public static SwPIDMotorController velocity(final SmartMotorController motor,
final PIDController pid) {
return SwPIDMotorController.velocity(motor, pid, motor.getEncoder());
return velocity(motor, pid, motor.getEncoder());
}

/**
Expand Down
Loading

0 comments on commit c465568

Please sign in to comment.