mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
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:
@@ -730,15 +730,9 @@ public class Matrix<R extends Num, C extends Num> {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof Matrix)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Matrix<?, ?> matrix = (Matrix<?, ?>) other;
|
||||
if (MatrixFeatures_DDRM.hasUncountable(matrix.m_storage.getDDRM())) {
|
||||
return false;
|
||||
}
|
||||
return MatrixFeatures_DDRM.isEquals(this.m_storage.getDDRM(), matrix.m_storage.getDDRM());
|
||||
return other instanceof Matrix<?, ?> matrix
|
||||
&& !MatrixFeatures_DDRM.hasUncountable(matrix.m_storage.getDDRM())
|
||||
&& MatrixFeatures_DDRM.isEquals(this.m_storage.getDDRM(), matrix.m_storage.getDDRM());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,11 +74,9 @@ public class Pair<A, B> {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof Pair) {
|
||||
return Objects.equals(m_first, ((Pair) obj).getFirst())
|
||||
&& Objects.equals(m_second, ((Pair) obj).getSecond());
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Pair<?, ?> other
|
||||
&& Objects.equals(m_first, other.getFirst())
|
||||
&& Objects.equals(m_second, other.getSecond());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -328,11 +328,8 @@ public class PoseEstimator<T> {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof PoseEstimator.InterpolationRecord)) {
|
||||
return false;
|
||||
}
|
||||
var record = (PoseEstimator<?>.InterpolationRecord) obj;
|
||||
return Objects.equals(gyroAngle, record.gyroAngle)
|
||||
return obj instanceof PoseEstimator<?>.InterpolationRecord record
|
||||
&& Objects.equals(gyroAngle, record.gyroAngle)
|
||||
&& Objects.equals(wheelPositions, record.wheelPositions)
|
||||
&& Objects.equals(poseMeters, record.poseMeters);
|
||||
}
|
||||
|
||||
@@ -40,17 +40,11 @@ public class Debouncer {
|
||||
|
||||
resetTimer();
|
||||
|
||||
switch (m_debounceType) {
|
||||
case kBoth: // fall-through
|
||||
case kRising:
|
||||
m_baseline = false;
|
||||
break;
|
||||
case kFalling:
|
||||
m_baseline = true;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid debounce type!");
|
||||
}
|
||||
m_baseline =
|
||||
switch (m_debounceType) {
|
||||
case kBoth, kRising -> false;
|
||||
case kFalling -> true;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -308,11 +308,9 @@ public class Pose2d implements Interpolatable<Pose2d>, ProtobufSerializable, Str
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Pose2d) {
|
||||
return ((Pose2d) obj).m_translation.equals(m_translation)
|
||||
&& ((Pose2d) obj).m_rotation.equals(m_rotation);
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Pose2d pose
|
||||
&& m_translation.equals(pose.m_translation)
|
||||
&& m_rotation.equals(pose.m_rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -303,11 +303,9 @@ public class Pose3d implements Interpolatable<Pose3d>, ProtobufSerializable, Str
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Pose3d) {
|
||||
return ((Pose3d) obj).m_translation.equals(m_translation)
|
||||
&& ((Pose3d) obj).m_rotation.equals(m_rotation);
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Pose3d pose
|
||||
&& m_translation.equals(pose.m_translation)
|
||||
&& m_rotation.equals(pose.m_rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -140,13 +140,9 @@ public class Quaternion implements ProtobufSerializable, StructSerializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Quaternion) {
|
||||
var other = (Quaternion) obj;
|
||||
|
||||
return Math.abs(dot(other) - norm() * other.norm()) < 1e-9
|
||||
&& Math.abs(norm() - other.norm()) < 1e-9;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Quaternion other
|
||||
&& Math.abs(dot(other) - norm() * other.norm()) < 1e-9
|
||||
&& Math.abs(norm() - other.norm()) < 1e-9;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -316,11 +316,8 @@ public class Rotation2d
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Rotation2d) {
|
||||
var other = (Rotation2d) obj;
|
||||
return Math.hypot(m_cos - other.m_cos, m_sin - other.m_sin) < 1E-9;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Rotation2d other
|
||||
&& Math.hypot(m_cos - other.m_cos, m_sin - other.m_sin) < 1E-9;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -422,11 +422,8 @@ public class Rotation3d
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Rotation3d) {
|
||||
var other = (Rotation3d) obj;
|
||||
return Math.abs(Math.abs(m_q.dot(other.m_q)) - m_q.norm() * other.m_q.norm()) < 1e-9;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Rotation3d other
|
||||
&& Math.abs(Math.abs(m_q.dot(other.m_q)) - m_q.norm() * other.m_q.norm()) < 1e-9;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -179,11 +179,9 @@ public class Transform2d implements ProtobufSerializable, StructSerializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Transform2d) {
|
||||
return ((Transform2d) obj).m_translation.equals(m_translation)
|
||||
&& ((Transform2d) obj).m_rotation.equals(m_rotation);
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Transform2d other
|
||||
&& other.m_translation.equals(m_translation)
|
||||
&& other.m_rotation.equals(m_rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -173,11 +173,9 @@ public class Transform3d implements ProtobufSerializable, StructSerializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Transform3d) {
|
||||
return ((Transform3d) obj).m_translation.equals(m_translation)
|
||||
&& ((Transform3d) obj).m_rotation.equals(m_rotation);
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Transform3d other
|
||||
&& other.m_translation.equals(m_translation)
|
||||
&& other.m_rotation.equals(m_rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -278,11 +278,9 @@ public class Translation2d
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Translation2d) {
|
||||
return Math.abs(((Translation2d) obj).m_x - m_x) < 1E-9
|
||||
&& Math.abs(((Translation2d) obj).m_y - m_y) < 1E-9;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Translation2d other
|
||||
&& Math.abs(other.m_x - m_x) < 1E-9
|
||||
&& Math.abs(other.m_y - m_y) < 1E-9;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -261,12 +261,10 @@ public class Translation3d
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Translation3d) {
|
||||
return Math.abs(((Translation3d) obj).m_x - m_x) < 1E-9
|
||||
&& Math.abs(((Translation3d) obj).m_y - m_y) < 1E-9
|
||||
&& Math.abs(((Translation3d) obj).m_z - m_z) < 1E-9;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Translation3d other
|
||||
&& Math.abs(other.m_x - m_x) < 1E-9
|
||||
&& Math.abs(other.m_y - m_y) < 1E-9
|
||||
&& Math.abs(other.m_z - m_z) < 1E-9;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,12 +55,10 @@ public class Twist2d implements ProtobufSerializable, StructSerializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Twist2d) {
|
||||
return Math.abs(((Twist2d) obj).dx - dx) < 1E-9
|
||||
&& Math.abs(((Twist2d) obj).dy - dy) < 1E-9
|
||||
&& Math.abs(((Twist2d) obj).dtheta - dtheta) < 1E-9;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Twist2d other
|
||||
&& Math.abs(other.dx - dx) < 1E-9
|
||||
&& Math.abs(other.dy - dy) < 1E-9
|
||||
&& Math.abs(other.dtheta - dtheta) < 1E-9;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,15 +72,13 @@ public class Twist3d implements ProtobufSerializable, StructSerializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Twist3d) {
|
||||
return Math.abs(((Twist3d) obj).dx - dx) < 1E-9
|
||||
&& Math.abs(((Twist3d) obj).dy - dy) < 1E-9
|
||||
&& Math.abs(((Twist3d) obj).dz - dz) < 1E-9
|
||||
&& Math.abs(((Twist3d) obj).rx - rx) < 1E-9
|
||||
&& Math.abs(((Twist3d) obj).ry - ry) < 1E-9
|
||||
&& Math.abs(((Twist3d) obj).rz - rz) < 1E-9;
|
||||
}
|
||||
return false;
|
||||
return obj instanceof Twist3d other
|
||||
&& Math.abs(other.dx - dx) < 1E-9
|
||||
&& Math.abs(other.dy - dy) < 1E-9
|
||||
&& Math.abs(other.dz - dz) < 1E-9
|
||||
&& Math.abs(other.rx - rx) < 1E-9
|
||||
&& Math.abs(other.ry - ry) < 1E-9
|
||||
&& Math.abs(other.rz - rz) < 1E-9;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -151,12 +151,9 @@ public class ExponentialProfile {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof State) {
|
||||
State rhs = (State) other;
|
||||
return this.position == rhs.position && this.velocity == rhs.velocity;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return other instanceof State rhs
|
||||
&& this.position == rhs.position
|
||||
&& this.velocity == rhs.velocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -383,14 +383,8 @@ public class Trajectory implements ProtobufSerializable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof State)) {
|
||||
return false;
|
||||
}
|
||||
State state = (State) obj;
|
||||
return Double.compare(state.timeSeconds, timeSeconds) == 0
|
||||
return obj instanceof State state
|
||||
&& Double.compare(state.timeSeconds, timeSeconds) == 0
|
||||
&& Double.compare(state.velocityMetersPerSecond, velocityMetersPerSecond) == 0
|
||||
&& Double.compare(state.accelerationMetersPerSecondSq, accelerationMetersPerSecondSq) == 0
|
||||
&& Double.compare(state.curvatureRadPerMeter, curvatureRadPerMeter) == 0
|
||||
@@ -421,6 +415,6 @@ public class Trajectory implements ProtobufSerializable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Trajectory && m_states.equals(((Trajectory) obj).getStates());
|
||||
return obj instanceof Trajectory other && m_states.equals(other.getStates());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,12 +120,9 @@ public class TrapezoidProfile {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof State) {
|
||||
State rhs = (State) other;
|
||||
return this.position == rhs.position && this.velocity == rhs.velocity;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return other instanceof State rhs
|
||||
&& this.position == rhs.position
|
||||
&& this.velocity == rhs.velocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user