Package edu.wpi.first.units
Record Class ImmutableMeasure<U extends Unit>
java.lang.Object
java.lang.Record
edu.wpi.first.units.ImmutableMeasure<U>
- Type Parameters:
U
- the unit type of the measure- Record Components:
magnitude
- the magnitude of the measure in terms of its unitbaseUnitMagnitude
- the magnitude of the measure in terms of its base unitunit
- the unit of the measurement
- All Implemented Interfaces:
Measure<U>
,Comparable<Measure<U>>
public record ImmutableMeasure<U extends Unit>(double magnitude, double baseUnitMagnitude, U extends Unit unit)
extends Record
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
Fields inherited from interface edu.wpi.first.units.Measure
EQUIVALENCE_THRESHOLD
-
Constructor Summary
ConstructorDescriptionImmutableMeasure
(double magnitude, double baseUnitMagnitude, U unit) Creates an instance of aImmutableMeasure
record class. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Returns the value of thebaseUnitMagnitude
record component.copy()
Returns an immutable copy of this measure.div
(double divisor) Divides this measure by a unitless scalar and returns the result.div
(Dimensionless divisor) Divides this measure by a dimensionless scalar and returns the result.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.double
Returns the value of themagnitude
record component.Subtracts another measure of the same unit type from this one.MutableMeasure<U,
?, ?> Returns a mutable copy of this measure.static <U extends Unit>
ImmutableMeasure<U>ofBaseUnits
(double baseUnitMagnitude, 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>
ImmutableMeasure<U>ofRelativeUnits
(double relativeMagnitude, U unit) Creates a new measure in the given unit with a magnitude in terms of that unit.Adds another measure of the same unit type to this one.times
(double multiplier) Multiplies this measure by a scalar unitless multiplier.times
(Dimensionless multiplier) Multiplies this measure by a scalar dimensionless multiplier.final String
toString()
Returns a string representation of this record class.Returns a measure equivalent to this one equal to zero minus its current value.unit()
Returns the value of theunit
record component.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface edu.wpi.first.units.Measure
abs, baseUnit, compareTo, copySign, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, div, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divide, divideRatio, gt, gte, in, isEquivalent, isNear, isNear, lt, lte, negate, per, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, times, timesConversionFactor, timesInverse, timesRatio, toLongString, toShortString
-
Constructor Details
-
ImmutableMeasure
Creates an instance of aImmutableMeasure
record class.- Parameters:
magnitude
- the value for themagnitude
record componentbaseUnitMagnitude
- the value for thebaseUnitMagnitude
record componentunit
- the value for theunit
record component
-
-
Method Details
-
ofBaseUnits
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> ImmutableMeasure<U> ofRelativeUnits(double relativeMagnitude, 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
-
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. -
mutableCopy
Description copied from interface:Measure
Returns a mutable copy of this measure. It will be initialized to the current state of this measure, but can be changed over time without needing to allocate new measurement objects.- Specified by:
mutableCopy
in interfaceMeasure<U extends Unit>
- Returns:
- the copied measure
-
unaryMinus
Description copied from interface:Measure
Returns a measure equivalent to this one equal to zero minus its current value. For non-linear unit types like temperature, the zero point is treated as the zero value of the base unit (eg Kelvin). In effect, this means code likeCelsius.of(10).unaryMinus()
returns a value equivalent to -10 Kelvin, and not -10° Celsius.- Specified by:
unaryMinus
in interfaceMeasure<U extends Unit>
- Returns:
- a measure equal to zero minus this measure
-
plus
Description copied from interface:Measure
Adds another measure of the same unit type to this one. -
minus
Description copied from interface:Measure
Subtracts another measure of the same unit type from this one. -
times
Description copied from interface:Measure
Multiplies this measure by a scalar unitless multiplier. -
times
Description copied from interface:Measure
Multiplies this measure by a scalar dimensionless multiplier. -
div
Description copied from interface:Measure
Divides this measure by a unitless scalar and returns the result. -
div
Description copied from interface:Measure
Divides this measure by a dimensionless scalar and returns the result. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
magnitude
Returns the value of themagnitude
record component. -
baseUnitMagnitude
Returns the value of thebaseUnitMagnitude
record component.- Specified by:
baseUnitMagnitude
in interfaceMeasure<U extends Unit>
- Returns:
- the value of the
baseUnitMagnitude
record component
-
unit
Returns the value of theunit
record component.
-