Package edu.wpi.first.units
Class ImmutableMeasure<U extends Unit<U>>
java.lang.Object
edu.wpi.first.units.ImmutableMeasure<U>
- Type Parameters:
U
- the unit type of the measure
- All Implemented Interfaces:
Measure<U>
,Comparable<Measure<U>>
public class ImmutableMeasure<U extends Unit<U>> extends Object implements Measure<U>
A measure holds the magnitude and unit of some dimension, such as distance, time, or speed. An
immutable measure is immutable and type safe, making it easy to use in concurrent
situations and gives compile-time safety. Two measures with the same unit and
magnitude are effectively equivalent objects.
-
Field Summary
-
Method Summary
Modifier and Type Method Description double
baseUnitMagnitude()
Gets the magnitude of this measure in terms of the base unit.Measure<U>
copy()
Returns an immutable copy of this measure.boolean
equals(Object o)
Checks for object equality.int
hashCode()
double
magnitude()
Gets the unitless magnitude of this measure.static <U extends Unit<U>>
ImmutableMeasure<U>ofBaseUnits(double baseUnitMagnitude, Unit<U> unit)
Creates a new measure in the given unit with a magnitude equal to the given one in base units.static <U extends Unit<U>>
ImmutableMeasure<U>ofRelativeUnits(double relativeMagnitude, Unit<U> unit)
Creates a new measure in the given unit with a magnitude in terms of that unit.String
toString()
U
unit()
Gets the units of this measure.
-
Method Details
-
ofBaseUnits
public static <U extends Unit<U>> ImmutableMeasure<U> ofBaseUnits(double baseUnitMagnitude, Unit<U> unit)Creates a new measure in the given unit with a magnitude equal to the given one in base units.- Type Parameters:
U
- the type of the units of measure- Parameters:
baseUnitMagnitude
- the magnitude of the measure, in terms of the base unit of measureunit
- the unit of measure- Returns:
- a new measure
-
ofRelativeUnits
public static <U extends Unit<U>> ImmutableMeasure<U> ofRelativeUnits(double relativeMagnitude, Unit<U> unit)Creates a new measure in the given unit with a magnitude in terms of that unit.- Type Parameters:
U
- the type of the units of measure- Parameters:
relativeMagnitude
- the magnitude of the measureunit
- the unit of measure- Returns:
- a new measure
-
magnitude
Gets the unitless magnitude of this measure. -
baseUnitMagnitude
Description copied from interface:Measure
Gets the magnitude of this measure in terms of the base unit. If the unit is the base unit for its system of measure, then the value will be equivalent toMeasure.magnitude()
.- Specified by:
baseUnitMagnitude
in interfaceMeasure<U extends Unit<U>>
- Returns:
- the magnitude in terms of the base unit
-
unit
Gets the units of this measure. -
equals
Checks for object equality. To check if two measures are equivalent, useisEquivalent
. -
hashCode
-
copy
Description copied from interface:Measure
Returns an immutable copy of this measure. The copy can be used freely and is guaranteed never to change. -
toString
-