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

@@ -85,36 +85,29 @@ public interface Measure<U extends Unit<U>> extends Comparable<Measure<U>> {
* @param other the unit to multiply by
* @return the multiplicative unit
*/
@SuppressWarnings("unchecked")
default <U2 extends Unit<U2>> Measure<?> times(Measure<U2> other) {
if (other.unit() instanceof Dimensionless) {
// scalar multiplication
return times(other.baseUnitMagnitude());
}
if (unit() instanceof Per
&& other.unit().getBaseUnit().equals(((Per<?, ?>) unit()).denominator().getBaseUnit())) {
if (unit() instanceof Per<?, ?> per
&& other.unit().getBaseUnit().equals(per.denominator().getBaseUnit())) {
// denominator of the Per cancels out, return with just the units of the numerator
Unit<?> numerator = ((Per<?, ?>) unit()).numerator();
Unit<?> numerator = per.numerator();
return numerator.ofBaseUnits(baseUnitMagnitude() * other.baseUnitMagnitude());
} else if (unit() instanceof Velocity && other.unit().getBaseUnit().equals(Seconds)) {
} else if (unit() instanceof Velocity<?> v && other.unit().getBaseUnit().equals(Seconds)) {
// Multiplying a velocity by a time, return the scalar unit (eg Distance)
Unit<?> numerator = ((Velocity<?>) unit()).getUnit();
Unit<?> numerator = v.getUnit();
return numerator.ofBaseUnits(baseUnitMagnitude() * other.baseUnitMagnitude());
} else if (other.unit() instanceof Per
&& unit().getBaseUnit().equals(((Per<?, ?>) other.unit()).denominator().getBaseUnit())) {
Unit<?> numerator = ((Per<?, ?>) other.unit()).numerator();
} else if (other.unit() instanceof Per<?, ?> per
&& unit().getBaseUnit().equals(per.denominator().getBaseUnit())) {
Unit<?> numerator = per.numerator();
return numerator.ofBaseUnits(baseUnitMagnitude() * other.baseUnitMagnitude());
} else if (unit() instanceof Per
&& other.unit() instanceof Per
&& ((Per<?, ?>) unit())
.denominator()
.getBaseUnit()
.equals(((Per<?, U>) other.unit()).numerator().getBaseUnit())
&& ((Per<?, ?>) unit())
.numerator()
.getBaseUnit()
.equals(((Per<?, ?>) other.unit()).denominator().getBaseUnit())) {
} else if (unit() instanceof Per<?, ?> per
&& other.unit() instanceof Per<?, ?> otherPer
&& per.denominator().getBaseUnit().equals(otherPer.numerator().getBaseUnit())
&& per.numerator().getBaseUnit().equals(otherPer.denominator().getBaseUnit())) {
// multiplying eg meters per second * milliseconds per foot
// return a scalar
return Units.Value.of(baseUnitMagnitude() * other.baseUnitMagnitude());