Class Unit

java.lang.Object
de.turnertech.measures.Unit

public class Unit extends Object
A Unit is a single instance of a Measurement, such as a Metre or a Degree Celsius.
  • Field Details

    • KELVIN

      public static final Unit KELVIN
      K
    • DEGREES_CELSIUS

      public static final Unit DEGREES_CELSIUS
      Cel
    • DEGREES_FAHRENHEIT

      public static final Unit DEGREES_FAHRENHEIT
      degF
    • METRE

      public static final Unit METRE
      m
    • CENTIMETRE

      public static final Unit CENTIMETRE
      cm
    • INCH

      public static final Unit INCH
      in_i
    • YARD

      public static final Unit YARD
      yd_i
    • MILE

      public static final Unit MILE
      mi_i
    • KILOMETRE

      public static final Unit KILOMETRE
      km
    • NAUTICAL_MILE

      public static final Unit NAUTICAL_MILE
      nmi_i
    • SECOND

      public static final Unit SECOND
      s
    • GRAM

      public static final Unit GRAM
      g
    • POUND

      public static final Unit POUND
      lb_av
    • DEGREE

      public static final Unit DEGREE
      deg
    • MINUTE_ANGLE

      public static final Unit MINUTE_ANGLE
      '
    • SECOND_ANGLE

      public static final Unit SECOND_ANGLE
      "
    • RADIAN

      public static final Unit RADIAN
      rad
  • Constructor Details

    • Unit

      public Unit()
      Constructs a "Base Unit", where its own base unit is iteself, and conversions to and from its base unit will alway return the same value as input (DoubleUnaryOperator.identity()).
    • Unit

      public Unit(String symbol)
      Constructs a "Base Unit", where its own base unit is iteself, and conversions to and from its base unit will alway return the same value as input (DoubleUnaryOperator.identity()).
      Parameters:
      symbol - may not be null.
    • Unit

      public Unit(String symbol, Unit baseUnit, DoubleUnaryOperator toBaseUnitFunction, DoubleUnaryOperator fromBaseUnitFunction)
      Constructs a Unit with the supplied base unit and conversion functions too and from said Unit.
      Parameters:
      baseUnit - the unit to which the conversion functions will convert. Supplying null will make the base unit the unit itself (this).
      symbol - may not be null.
      toBaseUnitFunction - may not be null.
      fromBaseUnitFunction - may not be null.
  • Method Details

    • createMeasure

      public Measure createMeasure(double quantity)
      Helper function for creating measures with a Unit.
      Parameters:
      quantity - the quantity of this unit which should be in the Measure.
      Returns:
      a new Measure instance.
    • getBaseUnit

      public Unit getBaseUnit()
      Gets the common base unit for the family of units to which this Unit belongs. For example, Metres are the base Unit for all distance Units. Even Feet, Inches and Nautical Miles will share the same base unit of a Metre.
      Returns:
      the base unit for this Unit.
    • convertToBaseUnit

      public Measure convertToBaseUnit(double quantity)
      Converts a supplied quantity of this Unit to a quantity of its base unit. For example supplying a quantity of 1 to this function on an instance of KILOMETRE will return 1000 (metres).
      Parameters:
      quantity - of this Unit to convert to the base unit.
      Returns:
      the quantity of the Base Unit which the supplied quantity represents.
    • convertFromBaseUnit

      public Measure convertFromBaseUnit(double quantity)
      Converts a supplied quantity of this Units base unit to a quantity of itself.
      Parameters:
      quantity - of this Unit base unit to convert to this unit.
      Returns:
      a measure with this Unit.
    • toString

      public String toString()
      Overrides:
      toString in class Object