Package edu.wpi.first.units
Class MultUnit<A extends Unit,B extends Unit>
java.lang.Object
edu.wpi.first.units.Unit
edu.wpi.first.units.MultUnit<A,B>
- Type Parameters:
A
- the type of the first unit in the resultB
- the type of the second unit in the result
- Direct Known Subclasses:
AngularMomentumUnit
,ForceUnit
,LinearMomentumUnit
,TorqueUnit
A combinatory unit type that is equivalent to the product of two other others. Note that
algebraic reduction is not possible in Java's generic type system, so
MultUnit<A, B>
is
not type-compatible with MultUnit<B, A>
!-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncombine
(A a, B b) Creates a new MultUnit unit derived from two arbitrary units multiplied together.double
convertFrom
(double magnitude, MultUnit<A, B> otherUnit) Converts a measurement value in terms of another unit to this unit.boolean
Gets the base unit of measurement that this unit is derived from.int
hashCode()
MutableMeasure<? extends MultUnit<A,
B>, ?, ?> mutable
(double initialMagnitude) Creates a new mutable measurement that is initialized to the given magnitude in terms of this unit.of
(double magnitude) Creates a new immutable measurement of the given magnitude in terms of this unit.ofBaseUnits
(double baseUnitMagnitude) Creates a new immutable measurement of the given magnitude in terms of this unit's base unit.ofNative
(double magnitude) Creates a new immutable measurement of the given magnitude in terms of this unit.ofNativeBaseUnits
(double baseUnitMagnitude) Creates a new immutable measurement of the given magnitude in terms of the unit's base unit.one()
Gets a measure with a magnitude of 1.0 in terms of this unit.Combines this unit with a unit of time.toString()
unitA()
Gets the first unit of the product.unitB()
Gets the second unit of the product.zero()
Gets a measure of zero magnitude in terms of this unit.Methods inherited from class edu.wpi.first.units.Unit
equivalent, fromBaseUnits, getConverterFromBase, getConverterToBase, isBaseUnit, name, symbol, toBaseUnits
-
Constructor Details
-
MultUnit
Creates a new product unit. Subclasses ofMultUnit
should use this constructor.- Parameters:
baseUnit
- the base unit. Set this to null if the unit being constructed is its own base unita
- the first unit of the productb
- the second unit of the product
-
-
Method Details
-
combine
Creates a new MultUnit unit derived from two arbitrary units multiplied together.MultUnit.combine(Volts, Meters) // Volt-Meters
- Type Parameters:
A
- the type of the first unitB
- the type of the second unit- Parameters:
a
- the first unitb
- the second unit- Returns:
- the combined unit
-
of
Creates a new immutable measurement of the given magnitude in terms of this unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.Note: When called on an object of type
MultUnit
(and not a subclass!), this method will always return aMult
instance. If you want to avoid casting, useofNativeBaseUnits(double)
that returns aPer
instance directly. -
ofBaseUnits
Creates a new immutable measurement of the given magnitude in terms of this unit's base unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation.Note: When called on an object of type
MultUnit
(and not a subclass!), this method will always return aMult
instance. If you want to avoid casting, useofNativeBaseUnits(double)
that returns aPer
instance directly.- Specified by:
ofBaseUnits
in classUnit
- Parameters:
baseUnitMagnitude
- the magnitude of the measure in terms of its base units.- Returns:
- the measurement object
-
ofNative
Creates a new immutable measurement of the given magnitude in terms of this unit. This will always return aMult
object and cannot be overridden by subclasses.- Parameters:
magnitude
- the magnitude of the measurement.- Returns:
- the measurement object
- See Also:
-
ofNativeBaseUnits
Creates a new immutable measurement of the given magnitude in terms of the unit's base unit. This will always return aMult
object and cannot be overridden by subclasses.- Parameters:
baseUnitMagnitude
- the magnitude of the measure in terms of its base units.- Returns:
- the measurement object
- See Also:
-
zero
Description copied from class:Unit
Gets a measure of zero magnitude in terms of this unit. The returned object is guaranteed to be of the same type returned byUnit.of(double)
. Subclasses are encouraged to override this method to sharpen the return type. -
one
Description copied from class:Unit
Gets a measure with a magnitude of 1.0 in terms of this unit. The returned object is guaranteed to be of the same type returned byUnit.of(double)
. Subclasses are encouraged to override this method to sharpen the return type. -
mutable
Description copied from class:Unit
Creates a new mutable measurement that is initialized to the given magnitude in terms of this unit. Implementations are strongly recommended to sharpen the return type to a unit-specific measurement implementation. -
per
Description copied from class:Unit
Combines this unit with a unit of time. This often - but not always - results in a velocity. Subclasses should sharpen the return type to be unit-specific. -
convertFrom
Converts a measurement value in terms of another unit to this unit.- Parameters:
magnitude
- the magnitude of the measurement in terms of the other unitotherUnit
- the other unit- Returns:
- the value of the measurement in terms of this unit
-
getBaseUnit
Description copied from class:Unit
Gets the base unit of measurement that this unit is derived from. If the unit is the base unit, the unit will be returned.NOTE: Subclasses must override this method to provide the correct return type. Failing to do say will make unit combinations that use it break at runtime!
Unit baseUnit = new Unit(null, ...); baseUnit.getBaseUnit(); // returns baseUnit Unit derivedUnit = new Unit(baseUnit, ...); derivedUnit.getBaseUnit(); // returns baseUnit
- Overrides:
getBaseUnit
in classUnit
- Returns:
- the base unit
-
unitA
Gets the first unit of the product.- Returns:
- the first unit
-
unitB
Gets the second unit of the product.- Returns:
- the second unit
-
toString
-
equals
-
hashCode
-