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.
  • 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 measure
      unit - 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 measure
      unit - the unit of measure
      Returns:
      a new measure
    • magnitude

      public double magnitude()
      Gets the unitless magnitude of this measure.
      Specified by:
      magnitude in interface Measure<U extends Unit<U>>
      Returns:
      the magnitude in terms of the unit.
    • baseUnitMagnitude

      public double 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 to Measure.magnitude().
      Specified by:
      baseUnitMagnitude in interface Measure<U extends Unit<U>>
      Returns:
      the magnitude in terms of the base unit
    • unit

      public U unit()
      Gets the units of this measure.
      Specified by:
      unit in interface Measure<U extends Unit<U>>
      Returns:
      the unit
    • equals

      public boolean equals​(Object o)
      Checks for object equality. To check if two measures are equivalent, use isEquivalent.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • copy

      public Measure<U> 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.
      Specified by:
      copy in interface Measure<U extends Unit<U>>
      Returns:
      the copied measure
    • toString

      public String toString()
      Overrides:
      toString in class Object