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 classThe converter for replacing the keys in thegetBaseUnits()map fromUnitDimensioninstances toSystemUnitinstances. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final UnitDimensionThe dimension of this unit of measurement.(package private) final ScalarFactory<Q>The factory to use for creating quantities, ornullif none.(package private) static final StringThe non-empty symbol forUnits.UNITY.The type of quantity that uses this unit, ornullif unknown.private ConventionalUnit<Q>[]Units for the same quantity but with scale factors that are not the SI one.private static final longFor 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 aClassCastExceptionif 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.booleanequals(Object other, ComparisonMode mode) Compares this unit with the given object for equality, optionally ignoring metadata and rounding errors.(package private) final booleanequalsIgnoreMetadata(javax.measure.Unit<Q> other) Returnstrueif 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, ornullif this unit is a base unit (not a product of existing units).javax.measure.UnitConvertergetConverterTo(javax.measure.Unit<Q> unit) Returns a converter of numeric values from this unit to another unit of same type.javax.measure.UnitConvertergetConverterToAny(javax.measure.Unit<?> unit) Returns a converter from this unit to the specified unit of unknown type.javax.measure.DimensionReturns the dimension of this unit.Returns the unscaled system unit from which this unit is derived.inthashCode()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, ornullif none.(package private) final voidrelated(int n) javax.measure.Unit<?>root(int n) Returns a unit equals to the given root of this unit.private booleansameSymbol(String symbol) Returnstrueif 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, ornullif 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 knownQuantitysubtype. -
dimension
The dimension of this unit of measurement. Cannot be null. -
factory
The factory to use for creating quantities, ornullif none. This field does not need to be serialized becauseAbstractUnit.readResolve()replaces deserialized instances by correspondingUnitshard-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, ornullif unknown.dimension- the unit dimension.symbol- the unit symbol, ornullif 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, ornullif 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 theotherunit 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, ornullif none or should be ignored. Ignored if the condition documented in javadoc does not hold.
-
sameSymbol
Returnstrueif 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 unitsu1andu2are 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:
getSystemUnitin interfacejavax.measure.spi.QuantityFactory<Q extends javax.measure.Quantity<Q>>- Specified by:
getSystemUnitin interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>- Specified by:
getSystemUnitin classAbstractUnit<Q extends javax.measure.Quantity<Q>>- Returns:
this
-
getBaseUnits
Returns the base units and their exponent whose product is this unit, ornullif this unit is a base unit (not a product of existing units).- Specified by:
getBaseUnitsin interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>- Specified by:
getBaseUnitsin 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:
getBaseSystemUnitsin 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 aClassCastExceptionif the dimension of the specified quantity and this unit's dimension do not match.- Specified by:
asTypein 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
Returnstrueif this unit is equal to the given unit ignoring name, symbol and EPSG code. This method should always returnstrueif 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:
getConverterToin 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
thatunit. - 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:
getConverterToAnyin 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
thatunit. - Throws:
javax.measure.IncommensurableException- if this unit is not compatible withthatunit.- 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:
alternatein 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:
rootin 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:
equalsin interfaceLenientComparable- Overrides:
equalsin 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:
trueif the given object is equal to this unit.- See Also:
-
hashCode
public int hashCode()Returns a hash code value for this unit.- Overrides:
hashCodein classAbstractUnit<Q extends javax.measure.Quantity<Q>>
-
create
Creates a quantity for the given value and unit of measurement.
-