Package uk.me.nxg.unity
Class UnitDefinitionMap
- java.lang.Object
-
- uk.me.nxg.unity.UnitDefinitionMap
-
public abstract class UnitDefinitionMap extends java.lang.Object
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
Constructors Modifier Constructor Description protected
UnitDefinitionMap()
Constructs a new unit-definition map.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static UnitDefinitionMap
getInstance()
Obtain an instance of the unit-definition map.abstract UnitDefinition
lookupUnitDefinition(java.lang.String uri)
Obtain information about a unit, keyed by the unit's URI, represented as a string.UnitDefinition
lookupUnitDefinition(Syntax syntax, java.lang.String symbol)
Obtain unit-definition information for a symbol, as interpreted in a particular syntax.UnitRepresentation
lookupUnitRepresentation(Syntax syntax, UnitDefinition ud)
Obtain information about how a unit is represented in a particular syntax.
-
-
-
Constructor Detail
-
UnitDefinitionMap
protected UnitDefinitionMap()
Constructs a new unit-definition map. This is protected on purpose – instances should be retrieved using thegetInstance()
method.
-
-
Method Detail
-
getInstance
public static UnitDefinitionMap getInstance()
Obtain an instance of the unit-definition map.- Returns:
- the singleton UnitDefinitionMap
-
lookupUnitDefinition
public UnitDefinition lookupUnitDefinition(Syntax syntax, java.lang.String symbol)
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:
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.syntax
- one of the syntaxes ofSyntax
- Returns:
- a UnitDefinition instance, or null if this is not available
-
lookupUnitRepresentation
public UnitRepresentation lookupUnitRepresentation(Syntax syntax, UnitDefinition ud)
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
public abstract UnitDefinition lookupUnitDefinition(java.lang.String uri)
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
-
-