Package org.goplanit.utils.unit
Class GroupUnit
- java.lang.Object
-
- org.goplanit.utils.unit.GroupUnit
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedGroupUnit(GroupUnit other, SimpleUnit... denominatorUnits)ConstructorprotectedGroupUnit(SimpleUnit... numeratorUnits)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanConvertTo(Unit to)Verify if unit can be converted to the desired unitdoubleconvertTo(Unit to, double value)Convert one unit to the other for a given valuebooleanequals(Object o)protected List<SimpleUnit>getDenominatorUnitTypes()All registered units in the denominatorprotected List<SimpleUnit>getNumeratorUnitTypes()All registered units in the numeratorbooleanisCombinedUnit()Is the unit a single or combined unitGroupUnitper(SimpleUnit... denominatorUnits)Factory method to create a new groupUnit with this unit's numerator and additionally added denominator units, e.g., KM per HourStringtoString()
-
-
-
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 fromdenominatorUnits- 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:
isCombinedUnitin interfaceUnit- 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) throws PlanItException
Convert one unit to the other for a given value- Specified by:
convertToin interfaceUnit- Parameters:
to- to unitvalue- value to convert- Returns:
- converted value
- Throws:
PlanItException- thrown if not possible to perform conversion
-
canConvertTo
public boolean canConvertTo(Unit to)
Verify if unit can be converted to the desired unit- Specified by:
canConvertToin interfaceUnit- Parameters:
to- to unit- Returns:
- true when compatible, false otherwise
-
-