Class SymbolMap
- java.lang.Object
-
- tech.units.indriya.format.SymbolMap
-
public final class SymbolMap extends Object
This class provides a set of mappings between
unitsand symbols (both ways), betweenprefixesand symbols (both ways), and fromunit converterstoMetricPrefix(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 alabel, otherwise if the trailing dot and number are present, the value is treated as analias. 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.- Version:
- 2.1, November 21, 2020
- Author:
- Eric Russell, Werner Keil
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidalias(Unit<?> unit, String symbol)Attaches an alias to the specified unit.PrefixgetPrefix(String symbol)Returns the prefix (if any) for the specified symbol.PrefixgetPrefix(UnitConverter converter)Returns the prefix for the specified converter.StringgetSymbol(Prefix prefix)Returns the symbol for the specified prefix.StringgetSymbol(Unit<?> unit)Returns the symbol (label) for the specified unit.Unit<?>getUnit(String symbol)Returns the unit for the specified symbol.voidlabel(Prefix prefix, String symbol)Attaches a label to the specified prefix.voidlabel(Unit<?> unit, String symbol)Attaches a label to the specified unit.static SymbolMapof(ResourceBundle rb)Creates a symbol map from the specified resource bundle,StringtoString()
-
-
-
Method Detail
-
of
public static SymbolMap of(ResourceBundle rb)
Creates a symbol map from the specified resource bundle,- Parameters:
rb- the resource bundle.
-
label
public void label(Unit<?> unit, String symbol)
Attaches a label to the specified unit. For example:
symbolMap.label(DAY.multiply(365), "year"); symbolMap.label(Units.OHM, "Ω");- Parameters:
unit- the unit to label.symbol- the new symbol for the unit.
-
alias
public void alias(Unit<?> unit, String symbol)
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(Units.MONTH, "month"); symbolMap.alias(Units.MONTH, "months"); symbolMap.alias(Units.METER, "meter"); symbolMap.alias(Units.METER, "metre");- Parameters:
unit- the unit to label.symbol- the new symbol for the unit.
-
label
public void label(Prefix prefix, String symbol)
Attaches a label to the specified prefix. For example:
symbolMap.label(MetricPrefix.GIGA, "G"); symbolMap.label(MetricPrefix.MICRO, "µ");
-
getUnit
public Unit<?> getUnit(String symbol)
Returns the unit for the specified symbol.- Parameters:
symbol- the symbol.- Returns:
- the corresponding unit or
nullif none.
-
getSymbol
public String getSymbol(Unit<?> unit)
Returns the symbol (label) for the specified unit.- Parameters:
unit- the corresponding symbol.- Returns:
- the corresponding symbol or
nullif none.
-
getPrefix
public Prefix getPrefix(String symbol)
Returns the prefix (if any) for the specified symbol.- Parameters:
symbol- the unit symbol.- Returns:
- the corresponding prefix or
nullif none.
-
getPrefix
public Prefix getPrefix(UnitConverter converter)
Returns the prefix for the specified converter.- Parameters:
converter- the unit converter.- Returns:
- the corresponding prefix or
nullif none.
-
getSymbol
public String getSymbol(Prefix prefix)
Returns the symbol for the specified prefix.- Parameters:
prefix- the prefix.- Returns:
- the corresponding symbol or
nullif none.
-
-