Package org.apache.sis.measure
Class SystemUnit<Q extends javax.measure.Quantity<Q>>
java.lang.Object
org.apache.sis.measure.AbstractUnit<Q>
org.apache.sis.measure.SystemUnit<Q>
- Type Parameters:
Q
- the kind of quantity to be measured using this units.
- All Implemented Interfaces:
Serializable
,javax.measure.spi.QuantityFactory<Q>
,javax.measure.Unit<Q>
,LenientComparable
final class SystemUnit<Q extends javax.measure.Quantity<Q>>
extends AbstractUnit<Q>
implements javax.measure.spi.QuantityFactory<Q>
Implementation of base, alternate and derived units (see
AbstractUnit
for a description of unit kinds).
A SystemUnit
is a base or alternate unit if associated to a base UnitDimension
, or is a derived
units otherwise. No other type is allowed since SystemUnit
is always a combination of fundamental units
without scale factor or offset.- Since:
- 0.8
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
The converter for replacing the keys in thegetBaseUnits()
map fromUnitDimension
instances toSystemUnit
instances. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final UnitDimension
The dimension of this unit of measurement.(package private) final ScalarFactory<Q>
The factory to use for creating quantities, ornull
if none.(package private) static final String
The non-empty symbol forUnits.UNITY
.The type of quantity that uses this unit, ornull
if unknown.private ConventionalUnit<Q>[]
Units for the same quantity but with scale factors that are not the SI one.private static final long
For cross-version compatibility.Fields inherited from class org.apache.sis.measure.AbstractUnit
DIVIDE, epsg, MULTIPLY, scope
-
Constructor Summary
ConstructorsConstructorDescriptionSystemUnit
(Class<Q> quantity, UnitDimension dimension, String symbol, byte scope, short epsg, ScalarFactory<Q> factory) Creates a new unit having the given symbol and EPSG code. -
Method Summary
Modifier and TypeMethodDescriptionjavax.measure.Unit<Q>
Returns a system unit equivalent to this unscaled standard unit but used in expressions to distinguish between quantities of a different nature but of the same dimensions.<T extends javax.measure.Quantity<T>>
javax.measure.Unit<T>Casts this unit to a parameterized unit of specified nature or throw aClassCastException
if the dimension of the specified quantity and this unit's dimension do not match.javax.measure.Quantity<Q>
Creates a quantity for the given value and unit of measurement.private SystemUnit<?>
create
(UnitDimension newDimension, char operation, javax.measure.Unit<?> other) Returns a unit of the given dimension with default name and symbol.javax.measure.Unit<?>
divide
(javax.measure.Unit<?> divisor) Returns the quotient of this unit with the one specified.boolean
equals
(Object other, ComparisonMode mode) Compares this unit with the given object for equality, optionally ignoring metadata and rounding errors.(package private) final boolean
equalsIgnoreMetadata
(javax.measure.Unit<Q> other) Returnstrue
if this unit is equal to the given unit ignoring name, symbol and EPSG code.(package private) final Map<SystemUnit<?>,
Fraction> Returns the base units used by Apache SIS implementations.Map<SystemUnit<?>,
Integer> Returns the base units and their exponent whose product is this unit, ornull
if this unit is a base unit (not a product of existing units).javax.measure.UnitConverter
getConverterTo
(javax.measure.Unit<Q> unit) Returns a converter of numeric values from this unit to another unit of same type.javax.measure.UnitConverter
getConverterToAny
(javax.measure.Unit<?> unit) Returns a converter from this unit to the specified unit of unknown type.javax.measure.Dimension
Returns the dimension of this unit.Returns the unscaled system unit from which this unit is derived.int
hashCode()
Returns a hash code value for this unit.javax.measure.Unit<?>
multiply
(javax.measure.Unit<?> multiplier) Returns the product of this unit with the one specified.javax.measure.Unit<?>
pow
(int n) Returns a unit equals to this unit raised to an exponent.private <T extends javax.measure.Quantity<T>>
javax.measure.Unit<?>product
(javax.measure.Unit<T> other, boolean inverse) Implementation ofmultiply(Unit)
anddivide(Unit)
methods.(package private) final ConventionalUnit<Q>[]
related()
Returns units for the same quantity but with scale factors that are not the SI one, ornull
if none.(package private) final void
related
(int n) javax.measure.Unit<?>
root
(int n) Returns a unit equals to the given root of this unit.private boolean
sameSymbol
(String symbol) Returnstrue
if the given symbol is null or equals to the symbol of this unit.javax.measure.Unit<Q>
transform
(javax.measure.UnitConverter operation) Returns the unit derived from this unit using the specified converter.Methods inherited from class org.apache.sis.measure.AbstractUnit
divide, equals, getName, getSymbol, incompatible, inferSymbol, inferSymbol, invalidCharForSymbol, inverse, isCompatible, isPrefixable, isPrefixable, isSymbolChar, multiply, readResolve, shift, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
ONE
The non-empty symbol forUnits.UNITY
.- See Also:
-
quantity
The type of quantity that uses this unit, ornull
if unknown. This field should be null only when this unit is the result of an arithmetic operation and that result cannot be mapped to a knownQuantity
subtype. -
dimension
The dimension of this unit of measurement. Cannot be null. -
factory
The factory to use for creating quantities, ornull
if none. This field does not need to be serialized becauseAbstractUnit.readResolve()
replaces deserialized instances by correspondingUnits
hard-coded instances.
-
-
Constructor Details
-
SystemUnit
SystemUnit(Class<Q> quantity, UnitDimension dimension, String symbol, byte scope, short epsg, ScalarFactory<Q> factory) Creates a new unit having the given symbol and EPSG code.- Parameters:
quantity
- the type of quantity that uses this unit, ornull
if unknown.dimension
- the unit dimension.symbol
- the unit symbol, ornull
if this unit has no specific symbol.scope
-UnitRegistry.SI
,UnitRegistry.ACCEPTED
, other constants or 0 if unknown.epsg
- the EPSG code, or 0 if this unit has no EPSG code.factory
- the factory to use for creating quantities, ornull
if none.
-
-
Method Details
-
create
private SystemUnit<?> create(UnitDimension newDimension, char operation, javax.measure.Unit<?> other) Returns a unit of the given dimension with default name and symbol. This method is invoked for creating the result of arithmetic operations. If there is no predefined unit for the given dimension, then the new unit may be allocated a symbol derived from this unit's symbol. A new symbol is created only if this unit symbol and theother
unit symbol are simple (for example "m" but not "m²", or "N" but not "N/m").- Parameters:
operation
- symbol to write after the symbol of this unit for generating the new unit symbol, or 0 for not inferring new symbol. Ignored if the condition documented in javadoc does not hold.other
- other units to append after the operation symbol, ornull
if none or should be ignored. Ignored if the condition documented in javadoc does not hold.
-
sameSymbol
Returnstrue
if the given symbol is null or equals to the symbol of this unit. -
getDimension
public javax.measure.Dimension getDimension()Returns the dimension of this unit. Two unitsu1
andu2
are compatible if and only ifu1.getDimension().equals(u2.getDimension())
. -
getSystemUnit
Returns the unscaled system unit from which this unit is derived. Since this unit is already a base, alternate or derived unit, this method returnstrue
.- Specified by:
getSystemUnit
in interfacejavax.measure.spi.QuantityFactory<Q extends javax.measure.Quantity<Q>>
- Specified by:
getSystemUnit
in interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>
- Specified by:
getSystemUnit
in classAbstractUnit<Q extends javax.measure.Quantity<Q>>
- Returns:
this
-
getBaseUnits
Returns the base units and their exponent whose product is this unit, ornull
if this unit is a base unit (not a product of existing units).- Specified by:
getBaseUnits
in interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>
- Specified by:
getBaseUnits
in classAbstractUnit<Q extends javax.measure.Quantity<Q>>
- Returns:
- the base units and their exponent making up this unit.
-
getBaseSystemUnits
Returns the base units used by Apache SIS implementations. Contrarily togetBaseUnits()
, this method never returnsnull
.- Specified by:
getBaseSystemUnits
in classAbstractUnit<Q extends javax.measure.Quantity<Q>>
-
asType
public <T extends javax.measure.Quantity<T>> javax.measure.Unit<T> asType(Class<T> type) throws ClassCastException Casts this unit to a parameterized unit of specified nature or throw aClassCastException
if the dimension of the specified quantity and this unit's dimension do not match.- Specified by:
asType
in interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>
- Type Parameters:
T
- the type of the quantity measured by the unit.- Parameters:
type
- the quantity class identifying the nature of the unit.- Returns:
- this unit parameterized with the specified type.
- Throws:
ClassCastException
- if the dimension of this unit is different from the specified quantity dimension.
-
equalsIgnoreMetadata
Returnstrue
if this unit is equal to the given unit ignoring name, symbol and EPSG code. This method should always returnstrue
if parameterized type has not been compromised with raw types or unchecked casts.- Parameters:
other
- the other unit, which must be a system unit.
-
getConverterTo
public javax.measure.UnitConverter getConverterTo(javax.measure.Unit<Q> unit) throws javax.measure.UnconvertibleException Returns a converter of numeric values from this unit to another unit of same type.- Specified by:
getConverterTo
in interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>
- Parameters:
unit
- the unit of same type to which to convert the numeric values.- Returns:
- the converter from this unit to
that
unit. - Throws:
javax.measure.UnconvertibleException
- if the converter cannot be constructed.
-
getConverterToAny
public javax.measure.UnitConverter getConverterToAny(javax.measure.Unit<?> unit) throws javax.measure.IncommensurableException Returns a converter from this unit to the specified unit of unknown type. This method can be used when the quantity type of the specified unit is unknown at compile-time or when dimensional analysis allows for conversion between units of different type.- Specified by:
getConverterToAny
in interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>
- Parameters:
unit
- the unit to which to convert the numeric values.- Returns:
- the converter from this unit to
that
unit. - Throws:
javax.measure.IncommensurableException
- if this unit is not compatible withthat
unit.- See Also:
-
alternate
Returns a system unit equivalent to this unscaled standard unit but used in expressions to distinguish between quantities of a different nature but of the same dimensions.The most important alternate unit in Apache SIS is
Units.RADIAN
, defined as below:- Specified by:
alternate
in interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>
- Parameters:
symbol
- the new symbol for the alternate unit.- Returns:
- the alternate unit.
- Throws:
IllegalArgumentException
- if the specified symbol is already associated to a different unit.
-
multiply
public javax.measure.Unit<?> multiply(javax.measure.Unit<?> multiplier) Returns the product of this unit with the one specified. -
divide
public javax.measure.Unit<?> divide(javax.measure.Unit<?> divisor) Returns the quotient of this unit with the one specified. -
product
private <T extends javax.measure.Quantity<T>> javax.measure.Unit<?> product(javax.measure.Unit<T> other, boolean inverse) Implementation ofmultiply(Unit)
anddivide(Unit)
methods.- Parameters:
inverse
- wether to use the inverse ofother
.
-
pow
public javax.measure.Unit<?> pow(int n) Returns a unit equals to this unit raised to an exponent. -
root
public javax.measure.Unit<?> root(int n) Returns a unit equals to the given root of this unit.- Specified by:
root
in interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>
- Parameters:
n
- the root's order.- Returns:
- the result of taking the given root of this unit.
- Throws:
ArithmeticException
- ifn == 0
.
-
transform
Returns the unit derived from this unit using the specified converter. -
equals
Compares this unit with the given object for equality, optionally ignoring metadata and rounding errors.- Specified by:
equals
in interfaceLenientComparable
- Overrides:
equals
in classAbstractUnit<Q extends javax.measure.Quantity<Q>>
- Parameters:
other
- the other object to compare with this unit, ornull
.mode
- the strictness level of the comparison.- Returns:
true
if the given object is equal to this unit.- See Also:
-
hashCode
public int hashCode()Returns a hash code value for this unit.- Overrides:
hashCode
in classAbstractUnit<Q extends javax.measure.Quantity<Q>>
-
create
Creates a quantity for the given value and unit of measurement.
-