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 byte
Identifies units defined outside the SI system but accepted for use with SI.(package private) static final byte
Identifies units defined by the centimeter–gram–second (CGS) system.(package private) static final byte
Identifies units defined for use in British imperial system.private final int
The bitmask for units to include.(package private) final String
Name of this system of units.(package private) static final byte
Identifies units defined in another system than the above.(package private) static final byte
A bitmask specifying that the unit symbol can be combined with a SI prefix.private static final long
For cross-version compatibility.(package private) static final byte
Identifies 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 void
alias
(javax.measure.Unit<?> unit, Comparable<?> alias) Adds an alias for the given unit.private static int
filter
(int existed, SystemUnit<?> unit, String s) Clears theexisted
bits for the cases where we allow dimension or quantity type collisions.(package private) static Object
Returns the value associated to the given key, ornull
if 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, ornull
if 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 void
init
(Map<UnitDimension, Fraction> components, UnitDimension dim) Adds the givencomponents
,dim
pair in the map of hard-coded values.(package private) static <Q extends javax.measure.Quantity<Q>>
ConventionalUnit<Q> init
(ConventionalUnit<Q> unit) Invoked byUnits
static class initializer for registering SI conventional units.(package private) static <Q extends javax.measure.Quantity<Q>>
SystemUnit<Q> init
(SystemUnit<Q> unit) Invoked byUnits
static class initializer for registering SI base and derived units.(package private) static Object
putIfAbsent
(Object key, Object value) Adds the givenkey
,value
pair 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
, notACCEPTED
except 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. AllSystemUnit
instances 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
,SystemUnit
orConventionalUnit
that are hard-coded in Apache SIS. This map is populated byUnits
static 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>
UnitDimension
Key is the base dimensions with their powers UnitDimension
SystemUnit
Key is the dimension of base or derived units. Class<Quantity>
SystemUnit
Key is the quantity type of base of derived units. String
AbstractUnit
Key is the unit symbol. Short
AbstractUnit
Key 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
,dim
pair in the map of hard-coded values. This method shall be invoked in a single thread by theUnits
class initializer only (indirectly). -
init
Invoked byUnits
static class initializer for registering SI base and derived units. This method shall be invoked in a single thread by theUnits
class initializer only. -
filter
Clears theexisted
bits for the cases where we allow dimension or quantity type collisions. This method is invoked for assertions only. -
init
Invoked byUnits
static class initializer for registering SI conventional units. This method shall be invoked in a single thread by theUnits
class initializer only. -
alias
-
putIfAbsent
Adds the givenkey
,value
pair 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 theUnits
class has been fully initialized. -
get
Returns the value associated to the given key, ornull
if none. This method can be invoked at anytime (atUnits
class initialization time or not). -
getName
Returns the name of this system of units.- Specified by:
getName
in interfacejavax.measure.spi.SystemOfUnits
-
getUnit
Returns the default unit for the specified quantity, ornull
if none.- Specified by:
getUnit
in 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:
getUnits
in interfacejavax.measure.spi.SystemOfUnits
-
getUnits
Returns the units defined in this system having the specified dimension, or an empty set if none.- Specified by:
getUnits
in interfacejavax.measure.spi.SystemOfUnits
-