Class SymbolMap
This class provides a set of mappings between units
and symbols (both ways), between
invalid reference
prefixes
unit converters
to
invalid reference
prefixes
Mappings are read from a ResourceBundle
, the keys of which should consist of a fully-qualified class name, followed by a dot ('.'),
and then the name of a static field belonging to that class, followed optionally by another dot and a number. If the trailing dot and number are
not present, the value associated with the key is treated as a
invalid reference
label
invalid reference
alias
- Version:
- 1.7, February 25, 2017
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Creates an empty mapping.private
Creates a symbol map from the specified resource bundle, -
Method Summary
Modifier and TypeMethodDescriptionvoid
Attaches an alias to the specified unit.Returns the prefix (if any) for the specified symbol.getPrefix
(javax.measure.UnitConverter converter) Returns the prefix for the specified converter.getSymbol
(javax.measure.Unit<?> unit) Returns the symbol (label) for the specified unit.Returns the symbol for the specified prefix.javax.measure.Unit
<?> Returns the unit for the specified symbol.void
Attaches a label to the specified unit.void
Attaches a label to the specified prefix.static SymbolMap
of
(ResourceBundle rb) Creates a symbol map from the specified resource bundle,toString()
-
Field Details
-
logger
-
symbolToUnit
-
unitToSymbol
-
symbolToPrefix
-
prefixToSymbol
-
converterToPrefix
-
-
Constructor Details
-
SymbolMap
private SymbolMap()Creates an empty mapping. -
SymbolMap
Creates a symbol map from the specified resource bundle,- Parameters:
rb
- the resource bundle.
-
-
Method Details
-
of
Creates a symbol map from the specified resource bundle,- Parameters:
rb
- the resource bundle.
-
label
Attaches a label to the specified unit. For example:
symbolMap.label(DAY.multiply(365), "year"); symbolMap.label(US.FOOT, "ft");
- Parameters:
unit
- the unit to label.symbol
- the new symbol for the unit.
-
alias
Attaches an alias to the specified unit. Multiple aliases may be attached to the same unit. Aliases are used during parsing to recognize different variants of the same unit.symbolMap.alias(US.FOOT, "foot"); symbolMap.alias(US.FOOT, "feet"); symbolMap.alias(Units.METER, "meter"); symbolMap.alias(Units.METER, "metre");
- Parameters:
unit
- the unit to label.symbol
- the new symbol for the unit.
-
label
Attaches a label to the specified prefix. For example:
symbolMap.label(MetricPrefix.GIGA, "G"); symbolMap.label(MetricPrefix.MICRO, "ยต");
TODO should be able to do this with a generic Prefix -
getUnit
Returns the unit for the specified symbol.- Parameters:
symbol
- the symbol.- Returns:
- the corresponding unit or
null
if none.
-
getSymbol
Returns the symbol (label) for the specified unit.- Parameters:
unit
- the corresponding symbol.- Returns:
- the corresponding symbol or
null
if none.
-
getPrefix
Returns the prefix (if any) for the specified symbol.- Parameters:
symbol
- the unit symbol.- Returns:
- the corresponding prefix or
null
if none.
-
getPrefix
Returns the prefix for the specified converter.- Parameters:
converter
- the unit converter.- Returns:
- the corresponding prefix or
null
if none.
-
getSymbol
Returns the symbol for the specified prefix.- Parameters:
prefix
- the prefix.- Returns:
- the corresponding symbol or
null
if none.
-
toString
-