Package org.apache.sis.measure
Class UnitRegistry
java.lang.Object
org.apache.sis.measure.UnitRegistry
- All Implemented Interfaces:
Serializable,javax.measure.spi.SystemOfUnits
Lookup mechanism for finding a units from its quantity, dimension or symbol.
This class opportunistically implements
SystemOfUnits, but Apache SIS
rather uses the static methods directly since we define all units in terms of SI.- Since:
- 0.8
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final byteIdentifies units defined outside the SI system but accepted for use with SI.(package private) static final byteIdentifies units defined by the centimeter–gram–second (CGS) system.(package private) static final byteIdentifies units defined for use in British imperial system.private final intThe bitmask for units to include.(package private) final StringName of this system of units.(package private) static final byteIdentifies units defined in another system than the above.(package private) static final byteA bitmask specifying that the unit symbol can be combined with a SI prefix.private static final longFor cross-version compatibility.(package private) static final byteIdentifies units defined by the SI system.private Set<javax.measure.Unit<?>>The value returned bygetUnits(), created when first needed.private static final WeakValueHashMap<Object,Object> Units defined by the user. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static voidalias(javax.measure.Unit<?> unit, Comparable<?> alias) Adds an alias for the given unit.private static intfilter(int existed, SystemUnit<?> unit, String s) Clears theexistedbits for the cases where we allow dimension or quantity type collisions.(package private) static ObjectReturns the value associated to the given key, ornullif none.getName()Returns the name of this system of units.<Q extends javax.measure.Quantity<Q>>
javax.measure.Unit<Q>Returns the default unit for the specified quantity, ornullif none.Set<javax.measure.Unit<?>>getUnits()Returns a read only view over the units explicitly defined by this system.Set<javax.measure.Unit<?>>getUnits(javax.measure.Dimension dimension) Returns the units defined in this system having the specified dimension, or an empty set if none.(package private) static voidinit(Map<UnitDimension, Fraction> components, UnitDimension dim) Adds the givencomponents,dimpair in the map of hard-coded values.(package private) static <Q extends javax.measure.Quantity<Q>>
ConventionalUnit<Q>init(ConventionalUnit<Q> unit) Invoked byUnitsstatic class initializer for registering SI conventional units.(package private) static <Q extends javax.measure.Quantity<Q>>
SystemUnit<Q>init(SystemUnit<Q> unit) Invoked byUnitsstatic class initializer for registering SI base and derived units.(package private) static ObjectputIfAbsent(Object key, Object value) Adds the givenkey,valuepair in the map of user-defined values, provided that no value is currently associated to the given key.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
PREFIXABLE
static final byte PREFIXABLEA bitmask specifying that the unit symbol can be combined with a SI prefix. This is usually combined only withSI, notACCEPTEDexcept the litre unit (cL, mL, etc) and bel (for creating the decibel unit). The gal unit can also be prefixed, but this unit is deprecated by ISO 80000-3:2006.- See Also:
-
SI
static final byte SIIdentifies units defined by the SI system. AllSystemUnitinstances with this code can have a SI prefix.- See Also:
-
ACCEPTED
static final byte ACCEPTEDIdentifies units defined outside the SI system but accepted for use with SI.- See Also:
-
CGS
static final byte CGSIdentifies units defined by the centimeter–gram–second (CGS) system.- Since:
- 1.2
- See Also:
-
IMPERIAL
static final byte IMPERIALIdentifies units defined for use in British imperial system.- See Also:
-
OTHER
static final byte OTHERIdentifies units defined in another system than the above.- See Also:
-
HARD_CODED
AllUnitDimension,SystemUnitorConventionalUnitthat are hard-coded in Apache SIS. This map is populated byUnitsstatic initializer and shall not be modified after initialization, in order to avoid the need for synchronization. Key and value types are restricted to the following pairs:Key and value types Key type Value type Description Map<UnitDimension,Fraction>UnitDimensionKey is the base dimensions with their powers UnitDimensionSystemUnitKey is the dimension of base or derived units. Class<Quantity>SystemUnitKey is the quantity type of base of derived units. StringAbstractUnitKey is the unit symbol. ShortAbstractUnitKey is the EPSG code. -
USER_DEFINED
Units defined by the user. Accesses to this map implies synchronization. Values are stored by weak references and garbage collected when no longer used. Key and value types are the same than the one described inHARD_CODED.Implementation note: we separate hard-coded values from user-defined values because the amount of hard-coded values is relatively large, using weak references for them is useless, and most applications will not define any custom values. This map will typically stay empty. -
name
Name of this system of units. -
includes
private final int includes -
units
The value returned bygetUnits(), created when first needed.
-
-
Constructor Details
-
UnitRegistry
UnitRegistry(String name, int includes) Creates a new unit system.
-
-
Method Details
-
init
Adds the givencomponents,dimpair in the map of hard-coded values. This method shall be invoked in a single thread by theUnitsclass initializer only (indirectly). -
init
Invoked byUnitsstatic class initializer for registering SI base and derived units. This method shall be invoked in a single thread by theUnitsclass initializer only. -
filter
Clears theexistedbits for the cases where we allow dimension or quantity type collisions. This method is invoked for assertions only. -
init
Invoked byUnitsstatic class initializer for registering SI conventional units. This method shall be invoked in a single thread by theUnitsclass initializer only. -
alias
-
putIfAbsent
Adds the givenkey,valuepair in the map of user-defined values, provided that no value is currently associated to the given key. This method shall be invoked only after theUnitsclass has been fully initialized. -
get
Returns the value associated to the given key, ornullif none. This method can be invoked at anytime (atUnitsclass initialization time or not). -
getName
Returns the name of this system of units.- Specified by:
getNamein interfacejavax.measure.spi.SystemOfUnits
-
getUnit
Returns the default unit for the specified quantity, ornullif none.- Specified by:
getUnitin interfacejavax.measure.spi.SystemOfUnits
-
getUnits
Returns a read only view over the units explicitly defined by this system. This include the base and derived units which are assigned a special name and symbol. This set does not include new units created by arithmetic or other operations.- Specified by:
getUnitsin interfacejavax.measure.spi.SystemOfUnits
-
getUnits
Returns the units defined in this system having the specified dimension, or an empty set if none.- Specified by:
getUnitsin interfacejavax.measure.spi.SystemOfUnits
-