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
ConstructorsConstructorDescriptionImmutableMeasure(double magnitude, double baseUnitMagnitude, U unit) Creates an instance of aImmutableMeasurerecord class. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the value of thebaseUnitMagnituderecord 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 booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doubleReturns the value of themagnituderecord 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 StringtoString()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 theunitrecord component.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, per, 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 aImmutableMeasurerecord class.- Parameters:
magnitude- the value for themagnituderecord componentbaseUnitMagnitude- the value for thebaseUnitMagnituderecord componentunit- the value for theunitrecord 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:MeasureReturns an immutable copy of this measure. The copy can be used freely and is guaranteed never to change. -
mutableCopy
Description copied from interface:MeasureReturns 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:
mutableCopyin interfaceMeasure<U extends Unit>- Returns:
- the copied measure
-
unaryMinus
Description copied from interface:MeasureReturns 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:
unaryMinusin interfaceMeasure<U extends Unit>- Returns:
- a measure equal to zero minus this measure
-
plus
Description copied from interface:MeasureAdds another measure of the same unit type to this one. -
minus
Description copied from interface:MeasureSubtracts another measure of the same unit type from this one. -
times
Description copied from interface:MeasureMultiplies this measure by a scalar unitless multiplier. -
times
Description copied from interface:MeasureMultiplies this measure by a scalar dimensionless multiplier. -
div
Description copied from interface:MeasureDivides this measure by a unitless scalar and returns the result. -
div
Description copied from interface:MeasureDivides 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 themagnituderecord component. -
baseUnitMagnitude
Returns the value of thebaseUnitMagnituderecord component.- Specified by:
baseUnitMagnitudein interfaceMeasure<U extends Unit>- Returns:
- the value of the
baseUnitMagnituderecord component
-
unit
Returns the value of theunitrecord component.
-