mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +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:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user