Class GroupUnit

  • All Implemented Interfaces:
    Unit

    public class GroupUnit
    extends Object
    implements Unit
    A combined unit consisting of multiple simple (single) units
    Author:
    markr
    • Constructor Detail

      • GroupUnit

        protected GroupUnit​(SimpleUnit... numeratorUnits)
        Constructor
        Parameters:
        numeratorUnits - to use
      • GroupUnit

        protected GroupUnit​(GroupUnit other,
                            SimpleUnit... denominatorUnits)
        Constructor
        Parameters:
        other - to copy numerator units from
        denominatorUnits - to use
    • Method Detail

      • per

        public GroupUnit per​(SimpleUnit... denominatorUnits)
        Factory method to create a new groupUnit with this unit's numerator and additionally added denominator units, e.g., KM per Hour
        Parameters:
        denominatorUnits - to use
        Returns:
        newly combined group unit
      • isCombinedUnit

        public boolean isCombinedUnit()
        Is the unit a single or combined unit
        Specified by:
        isCombinedUnit in interface Unit
        Returns:
        false when single, true when combined
      • getNumeratorUnitTypes

        protected List<SimpleUnit> getNumeratorUnitTypes()
        All registered units in the numerator
        Returns:
        numerator units
      • getDenominatorUnitTypes

        protected List<SimpleUnit> getDenominatorUnitTypes()
        All registered units in the denominator
        Returns:
        numerator units
      • convertTo

        public double convertTo​(Unit to,
                                double value)
        Convert one unit to the other for a given value
        Specified by:
        convertTo in interface Unit
        Parameters:
        to - to unit
        value - value to convert
        Returns:
        converted value
      • canConvertTo

        public boolean canConvertTo​(Unit to)
        Verify if unit can be converted to the desired unit
        Specified by:
        canConvertTo in interface Unit
        Parameters:
        to - to unit
        Returns:
        true when compatible, false otherwise