Package uk.me.nxg.unity
Class UnitDefinitionMap
java.lang.Object
uk.me.nxg.unity.UnitDefinitionMap
Provides a mapping from unit abbreviations to unit definitions.
This is a singleton class, so clients must first obtain the
instance of the class using getInstance()
.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Constructs a new unit-definition map. -
Method Summary
Modifier and TypeMethodDescriptionstatic UnitDefinitionMap
Obtain an instance of the unit-definition map.abstract UnitDefinition
Obtain information about a unit, keyed by the unit's URI, represented as a string.lookupUnitDefinition
(Syntax syntax, String symbol) Obtain unit-definition information for a symbol, as interpreted in a particular syntax.lookupUnitRepresentation
(Syntax syntax, UnitDefinition ud) Obtain information about how a unit is represented in a particular syntax.
-
Constructor Details
-
UnitDefinitionMap
protected UnitDefinitionMap()Constructs a new unit-definition map. This is protected on purpose – instances should be retrieved using thegetInstance()
method.
-
-
Method Details
-
getInstance
Obtain an instance of the unit-definition map.- Returns:
- the singleton UnitDefinitionMap
-
lookupUnitDefinition
Obtain unit-definition information for a symbol, as interpreted in a particular syntax. Return null if the syntax is unrecognised, or if the symbol is not recognised within that syntax- Parameters:
syntax
- one of the syntaxes ofSyntax
symbol
- a symbol for a unit, without prefix (eg 'm' for metre, not 'mm') If the syntax is passed as Syntax.ALL, then look up the definition in all of the available readable syntaxes. This may be of use when dealing with a ‘guessed’ unit.- Returns:
- a UnitDefinition instance, or null if this is not available
-
lookupUnitRepresentation
Obtain information about how a unit is represented in a particular syntax. Return null if the syntax is unrecognised, or if the unit has no representation within the given syntax. If the syntax is passed as Syntax.ALL, then look up the definition in all of the available readable syntaxes. This may be of use when dealing with a ‘guessed’ unit.- Parameters:
syntax
- one of the known syntaxesud
- a UnitDefinition instance- Returns:
- representation information, or null if this is not available
-
lookupUnitDefinition
Obtain information about a unit, keyed by the unit's URI, represented as a string.- Parameters:
uri
- the string representation of a unit' URI- Returns:
- a UnitDefinition instance, or null if this is not available
-