Package com.tccc.kos.commons.util.units
Class UnitSystem
java.lang.Object
com.tccc.kos.commons.util.units.UnitSystem
- Direct Known Subclasses:
SiUnitSystem
,UsUnitSystem
This class contains a full description of a "unit system". A unit system contains
multiple
Unit
definitions, which provide a way to convert to/from the base
data within kOS, which is typically stored as SI units. Unit systems are also shared
with UI code for standardized type conversion as part of the kOS UI framework.
While kOS provides default base unit systems, applications can add units to existing
systems, replace existing systems, or add new systems, as needed.- Since:
- 1.0
- Version:
- 2023-02-28
-
Constructor Summary
ConstructorsConstructorDescriptionUnitSystem
(String id) Creates a new unit system with the specified identifier. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new unit to the system.boolean
getAliasUnit
(String measure, String alias) Returns the unit with the specified alias for the specified measure.getDefaultUnit
(String measure) Returns the default unit for the specified measure.getId()
Returns the unit with the specified name or alias.getUnits()
int
hashCode()
-
Constructor Details
-
UnitSystem
Creates a new unit system with the specified identifier.- Parameters:
id
- ID of the unit system
-
-
Method Details
-
add
Adds a new unit to the system. If the measure and unit name match an existing unit, the new unit replaces the existing unit.- Parameters:
unit
- the unit to add
-
getDefaultUnit
Returns the default unit for the specified measure.- Parameters:
measure
- the measure to match- Throws:
IllegalArgumentException
- if no default unit exists for the measure
-
getAliasUnit
Returns the unit with the specified alias for the specified measure. If the alias isn't found, the default unit is returned.- Parameters:
measure
- the measure to match (null for any)alias
- the alias to match
-
getUnit
Returns the unit with the specified name or alias. If no unit is found, returns null.- Parameters:
measure
- the measure to match (null for any)nameOrAlias
- the name / alias to match
-
getId
-
getUnits
-
equals
-
hashCode
public int hashCode()
-