Top Description Fields Constructors Methods
tech.units.indriya.format

public final Class SymbolMap

extends Object
Class Inheritance
Annotations
@SuppressWarnings:rawtypes
Imports
javax.measure.Prefix, .Unit, .UnitConverter, tech.units.indriya.AbstractUnit, tech.units.indriya.function.AbstractConverter, .MultiplyConverter, java.lang.reflect.Field, java.util.Collections, .Comparator, .Enumeration, .HashMap, .List, .Map, .ResourceBundle, .TreeMap, java.util.logging.Level, java.util.logging.Logger, java.util.stream.Collectors

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.

Authors
Eric Russell, Werner Keil
Version
2.1, November 21, 2020

Field Summary

Modifier and TypeField and Description
private final Map<UnitConverter, Prefix>
private static final java.util.logging.Logger
private final Map<Object, String>
private final Map<String, Object>
private final Map<String, Unit<?>>
private final Map<Unit<?>, String>

Constructor Summary

AccessConstructor and Description
private
SymbolMap()

Creates an empty mapping.

private
SymbolMap(ResourceBundle
the resource bundle.
rb
)

Creates a symbol map from the specified resource bundle,

Method Summary

Modifier and TypeMethod and Description
public void
alias(Unit<?>
the unit to label.
unit
,
String
the new symbol for the unit.
symbol
)

Attaches an alias to the specified unit.

public Prefix

Returns:

the corresponding prefix or null if none.
getPrefix
(String
the unit symbol.
symbol
)

Returns the prefix (if any) for the specified symbol.

public Prefix

Returns:

the corresponding prefix or null if none.
getPrefix
(UnitConverter
the unit converter.
converter
)

Returns the prefix for the specified converter.

public String

Returns:

the corresponding symbol or null if none.
getSymbol
(Unit<?>
the corresponding symbol.
unit
)

Returns the symbol (label) for the specified unit.

public String

Returns:

the corresponding symbol or null if none.
getSymbol
(Prefix
the prefix.
prefix
)

Returns the symbol for the specified prefix.

public Unit<?>

Returns:

the corresponding unit or null if none.
getUnit
(String
the symbol.
symbol
)

Returns the unit for the specified symbol.

public void
label(Unit<?>
the unit to label.
unit
,
String
the new symbol for the unit.
symbol
)

Attaches a label to the specified unit.

public void
label(Prefix prefix, String symbol)

Attaches a label to the specified prefix.

public static SymbolMap
of(ResourceBundle
the resource bundle.
rb
)

Creates a symbol map from the specified resource bundle,

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

converterToPrefixback to summary
private final Map<UnitConverter, Prefix> converterToPrefix
loggerback to summary
private static final java.util.logging.Logger logger
prefixToSymbolback to summary
private final Map<Object, String> prefixToSymbol
symbolToPrefixback to summary
private final Map<String, Object> symbolToPrefix
symbolToUnitback to summary
private final Map<String, Unit<?>> symbolToUnit
unitToSymbolback to summary
private final Map<Unit<?>, String> unitToSymbol

Constructor Detail

SymbolMapback to summary
private SymbolMap()

Creates an empty mapping.

SymbolMapback to summary
private SymbolMap(ResourceBundle rb)

Creates a symbol map from the specified resource bundle,

Parameters
rb:ResourceBundle

the resource bundle.

Method Detail

aliasback to summary
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:Unit<?>

the unit to label.

symbol:String

the new symbol for the unit.

getPrefixback to summary
public Prefix getPrefix(String symbol)

Returns the prefix (if any) for the specified symbol.

Parameters
symbol:String

the unit symbol.

Returns:Prefix

the corresponding prefix or null if none.

getPrefixback to summary
public Prefix getPrefix(UnitConverter converter)

Returns the prefix for the specified converter.

Parameters
converter:UnitConverter

the unit converter.

Returns:Prefix

the corresponding prefix or null if none.

getSymbolback to summary
public String getSymbol(Unit<?> unit)

Returns the symbol (label) for the specified unit.

Parameters
unit:Unit<?>

the corresponding symbol.

Returns:String

the corresponding symbol or null if none.

getSymbolback to summary
public String getSymbol(Prefix prefix)

Returns the symbol for the specified prefix.

Parameters
prefix:Prefix

the prefix.

Returns:String

the corresponding symbol or null if none.

getUnitback to summary
public Unit<?> getUnit(String symbol)

Returns the unit for the specified symbol.

Parameters
symbol:String

the symbol.

Returns:Unit<?>

the corresponding unit or null if none.

labelback to summary
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:Unit<?>

the unit to label.

symbol:String

the new symbol for the unit.

labelback to summary
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, "µ");

ofback to summary
public static SymbolMap of(ResourceBundle rb)

Creates a symbol map from the specified resource bundle,

Parameters
rb:ResourceBundle

the resource bundle.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override