public final class SymbolMap extends Object
This class provides a set of mappings between units
and symbols (both ways), between prefixes
and symbols
(both ways), and from unit converters
to MetricPrefix
(one way). No attempt is made to verify the
uniqueness of the mappings.
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 label
, otherwise if the trailing dot
and number are present, the value is treated as an alias
. Aliases map from String to Unit only,
whereas labels map in both directions. A given unit may have any number of aliases, but may have only one label.
Modifier and Type | Method and Description |
---|---|
void |
alias(javax.measure.Unit<?> unit,
String symbol)
Attaches an alias to the specified unit.
|
javax.measure.Prefix |
getPrefix(String symbol)
Returns the prefix (if any) for the specified symbol.
|
javax.measure.Prefix |
getPrefix(javax.measure.UnitConverter converter)
Returns the prefix for the specified converter.
|
String |
getSymbol(javax.measure.Prefix prefix)
Returns the symbol for the specified prefix.
|
String |
getSymbol(javax.measure.Unit<?> unit)
Returns the symbol (label) for the specified unit.
|
javax.measure.Unit<?> |
getUnit(String symbol)
Returns the unit for the specified symbol.
|
void |
label(javax.measure.Prefix prefix,
String symbol)
Attaches a label to the specified prefix.
|
void |
label(javax.measure.Unit<?> unit,
String symbol)
Attaches a label to the specified unit.
|
static SymbolMap |
of(ResourceBundle rb)
Creates a symbol map from the specified resource bundle,
|
String |
toString() |
public static SymbolMap of(ResourceBundle rb)
rb
- the resource bundle.public void label(javax.measure.Unit<?> unit, String symbol)
symbolMap.label(DAY.multiply(365), "year"); symbolMap.label(Units.OHM, "Ω");
unit
- the unit to label.symbol
- the new symbol for the unit.public void alias(javax.measure.Unit<?> unit, String symbol)
symbolMap.alias(Units.MONTH, "month"); symbolMap.alias(Units.MONTH, "months");
symbolMap.alias(Units.METER, "meter"); symbolMap.alias(Units.METER, "metre");
unit
- the unit to label.symbol
- the new symbol for the unit.public void label(javax.measure.Prefix prefix, String symbol)
symbolMap.label(MetricPrefix.GIGA, "G"); symbolMap.label(MetricPrefix.MICRO, "µ");
public javax.measure.Unit<?> getUnit(String symbol)
symbol
- the symbol.null
if none.public String getSymbol(javax.measure.Unit<?> unit)
unit
- the corresponding symbol.null
if none.public javax.measure.Prefix getPrefix(String symbol)
symbol
- the unit symbol.null
if none.public javax.measure.Prefix getPrefix(javax.measure.UnitConverter converter)
converter
- the unit converter.null
if none.public String getSymbol(javax.measure.Prefix prefix)
prefix
- the prefix.null
if none.Copyright © 2005–2021 Units of Measurement project. All rights reserved.