Class AlternateUnit<Q extends javax.measure.Quantity<Q>>

  • All Implemented Interfaces:
    Serializable, Comparable<javax.measure.Unit<Q>>, javax.measure.Unit<Q>, ComparableUnit<Q>, tech.uom.lib.common.function.Nameable, tech.uom.lib.common.function.PrefixOperator<Q>, tech.uom.lib.common.function.SymbolSupplier

    public final class AlternateUnit<Q extends javax.measure.Quantity<Q>>
    extends AbstractUnit<Q>

    This class represents units used in expressions to distinguish between quantities of a different nature but of the same dimensions.

    Examples of alternate units:

    Unit<Angle> RADIAN = AlternateUnit.of(ONE, "rad").asType(Angle.class);
    Unit<Force> NEWTON = AlternateUnit.of(METRE.multiply(KILOGRAM).divide(SECOND.pow(2)), "N").asType(Force.class);
    Unit<Pressure> PASCAL = AlternateUnit.of(NEWTON.divide(METRE.pow(2), "Pa").asType(Pressure.class);
    Since:
    1.0
    Version:
    2.0, February 08, 2020
    Author:
    Jean-Marie Dautelle, Werner Keil
    See Also:
    Serialized Form
    • Constructor Detail

      • AlternateUnit

        public AlternateUnit​(javax.measure.Unit<?> parentUnit,
                             String symbol)
        Creates an alternate unit for the specified system unit identified by the specified name and symbol.
        Parameters:
        parentUnit - the system unit from which this alternate unit is derived.
        symbol - the symbol for this alternate unit.
        Throws:
        IllegalArgumentException - if the specified parent unit is not an system unit
    • Method Detail

      • getParentUnit

        public javax.measure.Unit<?> getParentUnit()
        Returns the parent unit of this alternate unit, always a system unit and never an alternate unit.
        Returns:
        the parent unit.
      • getDimension

        public javax.measure.Dimension getDimension()
        Specified by:
        getDimension in interface javax.measure.Unit<Q extends javax.measure.Quantity<Q>>
        Specified by:
        getDimension in class AbstractUnit<Q extends javax.measure.Quantity<Q>>
      • getSystemConverter

        public javax.measure.UnitConverter getSystemConverter()
        Description copied from interface: ComparableUnit
        Returns the converter from this unit to its unscaled System Unit unit.
        Returns:
        getConverterTo(this.toSystemUnit())
        See Also:
        #toSystemUnit
      • toSystemUnit

        public javax.measure.Unit<Q> toSystemUnit()
        Description copied from class: AbstractUnit
        Returns the unscaled SI unit from which this unit is derived. The SI unit can be be used to identify a quantity given the unit. For example: static boolean isAngularVelocity(AbstractUnit unit) { return unit.toSystemUnit().equals(RADIAN.divide(SECOND)); } assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.
        Specified by:
        toSystemUnit in class AbstractUnit<Q extends javax.measure.Quantity<Q>>
        Returns:
        the unscaled metric unit from which this unit is derived.
      • getBaseUnits

        public Map<? extends javax.measure.Unit<?>,​Integer> getBaseUnits()
        Specified by:
        getBaseUnits in interface javax.measure.Unit<Q extends javax.measure.Quantity<Q>>
        Specified by:
        getBaseUnits in class AbstractUnit<Q extends javax.measure.Quantity<Q>>
      • of

        public static <Q extends javax.measure.Quantity<Q>> AlternateUnit<Q> of​(javax.measure.Unit<?> parent,
                                                                                String symbol)
        Creates an alternate unit for the specified system unit identified by the specified name and symbol.
        Parameters:
        parent - the system unit from which this alternate unit is derived.
        symbol - the symbol for this alternate unit.
        Throws:
        IllegalArgumentException - if the specified parent unit is not an unscaled standard system unit.
        MeasurementException - if the specified symbol is not valid or is already associated to a different unit.
      • of

        public static <Q extends javax.measure.Quantity<Q>> AlternateUnit<Q> of​(javax.measure.Unit<?> parent,
                                                                                String symbol,
                                                                                String name)
        Creates an alternate unit for the specified system unit identified by the specified name and symbol.
        Parameters:
        parent - the system unit from which this alternate unit is derived.
        symbol - the symbol for this alternate unit.
        name - the name for this alternate unit.
        Throws:
        IllegalArgumentException - if the specified parent unit is not an unscaled standard system unit.
        MeasurementException - if the specified symbol is not valid or is already associated to a different unit.
        Since:
        2.0