Use Java 17 features (#6691)

Uses enhanced instanceof (and simplify equals methods)
Uses switch expressions and arrow labels
Seal and finalize some Shuffleboard classes

Co-authored-by: Sam Carlberg <sam@slfc.dev>
This commit is contained in:
Gold856
2024-06-05 00:09:10 -04:00
committed by GitHub
parent d6b66bfa55
commit b99d9c1710
95 changed files with 957 additions and 1594 deletions

View File

@@ -394,14 +394,8 @@ public class ChassisSpeeds implements ProtobufSerializable, StructSerializable {
if (o == this) {
return true;
}
if (!(o instanceof ChassisSpeeds)) {
return false;
}
ChassisSpeeds c = (ChassisSpeeds) o;
return vxMetersPerSecond == c.vxMetersPerSecond
return o instanceof ChassisSpeeds c
&& vxMetersPerSecond == c.vxMetersPerSecond
&& vyMetersPerSecond == c.vyMetersPerSecond
&& omegaRadiansPerSecond == c.omegaRadiansPerSecond;
}

View File

@@ -53,12 +53,9 @@ public class DifferentialDriveWheelPositions
@Override
public boolean equals(Object obj) {
if (obj instanceof DifferentialDriveWheelPositions) {
DifferentialDriveWheelPositions other = (DifferentialDriveWheelPositions) obj;
return Math.abs(other.leftMeters - leftMeters) < 1E-9
&& Math.abs(other.rightMeters - rightMeters) < 1E-9;
}
return false;
return obj instanceof DifferentialDriveWheelPositions other
&& Math.abs(other.leftMeters - leftMeters) < 1E-9
&& Math.abs(other.rightMeters - rightMeters) < 1E-9;
}
@Override

View File

@@ -79,14 +79,11 @@ public class MecanumDriveWheelPositions
@Override
public boolean equals(Object obj) {
if (obj instanceof MecanumDriveWheelPositions) {
MecanumDriveWheelPositions other = (MecanumDriveWheelPositions) obj;
return Math.abs(other.frontLeftMeters - frontLeftMeters) < 1E-9
&& Math.abs(other.frontRightMeters - frontRightMeters) < 1E-9
&& Math.abs(other.rearLeftMeters - rearLeftMeters) < 1E-9
&& Math.abs(other.rearRightMeters - rearRightMeters) < 1E-9;
}
return false;
return obj instanceof MecanumDriveWheelPositions other
&& Math.abs(other.frontLeftMeters - frontLeftMeters) < 1E-9
&& Math.abs(other.frontRightMeters - frontRightMeters) < 1E-9
&& Math.abs(other.rearLeftMeters - rearLeftMeters) < 1E-9
&& Math.abs(other.rearRightMeters - rearRightMeters) < 1E-9;
}
@Override

View File

@@ -61,11 +61,9 @@ public class SwerveModulePosition
@Override
public boolean equals(Object obj) {
if (obj instanceof SwerveModulePosition) {
SwerveModulePosition other = (SwerveModulePosition) obj;
return Math.abs(other.distanceMeters - distanceMeters) < 1E-9 && angle.equals(other.angle);
}
return false;
return obj instanceof SwerveModulePosition other
&& Math.abs(other.distanceMeters - distanceMeters) < 1E-9
&& angle.equals(other.angle);
}
@Override

View File

@@ -57,12 +57,9 @@ public class SwerveModuleState
@Override
public boolean equals(Object obj) {
if (obj instanceof SwerveModuleState) {
SwerveModuleState other = (SwerveModuleState) obj;
return Math.abs(other.speedMetersPerSecond - speedMetersPerSecond) < 1E-9
&& angle.equals(other.angle);
}
return false;
return obj instanceof SwerveModuleState other
&& Math.abs(other.speedMetersPerSecond - speedMetersPerSecond) < 1E-9
&& angle.equals(other.angle);
}
@Override