Package org.apache.sis.measure
Class UnitDimension
java.lang.Object
org.apache.sis.measure.UnitDimension
- All Implemented Interfaces:
Serializable
,javax.measure.Dimension
Dimension (length, mass, time, etc.) of a unit of measurement.
Only two kind of dimensions are defined in Apache SIS:
- Base dimensions are the 7 base dimensions specified by the SI system.
- Derived dimensions are products of base dimensions raised to some power.
- Voltage noise density measured per √(Hz).
- Specific detectivity as T^2.5 / (M⋅L) dimension.
UnitDimension
instances are immutable and thus inherently thread-safe.- Since:
- 0.8
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Map
<UnitDimension, Fraction> The product of base dimensions that make this dimension.(package private) static final UnitDimension
Pseudo-dimension for dimensionless units.private static final long
For cross-version compatibility.(package private) final char
If thisUnitDimension
is a base dimension, its symbol (not to be confused with unit symbol). -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
UnitDimension
(char symbol) Creates a new base dimension with the given symbol, which shall not be zero.private
UnitDimension
(Map<UnitDimension, Fraction> components) Creates a new derived dimension. -
Method Summary
Modifier and TypeMethodDescriptionprivate UnitDimension
combine
(javax.measure.Dimension other, boolean divide) Returns the product or the quotient of this dimension with the specified one.private static UnitDimension
create
(Map<UnitDimension, Fraction> components) Creates a new derived dimension from the given product of base dimensions with their power.divide
(javax.measure.Dimension divisor) Returns the quotient of this dimension with the one specified.boolean
Compares this dimension with the given object for equality.Returns the (fundamental) base dimensions and their exponent whose product is this dimension, or null if this dimension is a base dimension.getBaseDimensions
(javax.measure.Dimension dimension) Returns the base dimensions and their exponents whose product make the given dimension.int
hashCode()
Returns a hash code value for this dimension.(package private) final boolean
Returnstrue
if thisUnitDimension
has no components.(package private) static boolean
isDimensionless
(javax.measure.Dimension dim) Returnstrue
if the given dimension has no components.multiply
(javax.measure.Dimension multiplicand) Returns the product of this dimension with the one specified.(package private) final boolean
numeratorIs
(char s) Returnstrue
if the numerator is the dimension identified by the given symbol.pow
(int n) Returns this dimension raised to an exponent.private UnitDimension
Returns this dimension raised to an exponent.(package private) Object
Invoked on deserialization for returning a unique instance ofUnitDimension
.root
(int n) Returns the given root of this dimension.toString()
Returns a string representation of this dimension.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
NONE
Pseudo-dimension for dimensionless units. -
components
The product of base dimensions that make this dimension. All keys in this map shall be base dimensions (base dimensions are identified by non-zerosymbol
). If thisUnitDimension
is itself a base dimension, then the map containsthis
raised to power 1. The map shall never benull
.- See Also:
-
symbol
final char symbolIf thisUnitDimension
is a base dimension, its symbol (not to be confused with unit symbol). Otherwise (i.e. if thisUnitDimension
is a derived dimension), zero.
-
-
Constructor Details
-
UnitDimension
UnitDimension(char symbol) Creates a new base dimension with the given symbol, which shall not be zero. This constructor shall be invoked only during construction ofUnits
constants.- Parameters:
symbol
- the symbol of this base dimension (not to be confused with unit symbol).
-
UnitDimension
Creates a new derived dimension. This constructor shall never be invoked directly (except forNONE
); usecreate(Map)
instead.- Parameters:
components
- the product of base dimensions together with their power.
-
-
Method Details
-
create
Creates a new derived dimension from the given product of base dimensions with their power. This method returns a shared instance if possible.- Parameters:
components
- the product of base dimensions together with their power.
-
readResolve
Invoked on deserialization for returning a unique instance ofUnitDimension
.- Throws:
ObjectStreamException
-
isDimensionless
final boolean isDimensionless()Returnstrue
if thisUnitDimension
has no components. Many dimensionless units exist for different quantities as angles, parts per million, etc. -
isDimensionless
static boolean isDimensionless(javax.measure.Dimension dim) Returnstrue
if the given dimension has no components. -
numeratorIs
final boolean numeratorIs(char s) Returnstrue
if the numerator is the dimension identified by the given symbol. This method returnstrue
only if the numerator is not be raised to any exponent other than 1 and there is no other numerator. All denominator terms are ignored.This method is used for identifying units like "kg", "kg/s", etc for handling the "kg" prefix in a special way.
-
getBaseDimensions
Returns the (fundamental) base dimensions and their exponent whose product is this dimension, or null if this dimension is a base dimension.- Specified by:
getBaseDimensions
in interfacejavax.measure.Dimension
-
getBaseDimensions
private static Map<? extends javax.measure.Dimension,Fraction> getBaseDimensions(javax.measure.Dimension dimension) Returns the base dimensions and their exponents whose product make the given dimension. If the given dimension is a base dimension, then this method returnsthis
raised to power 1. This method never returnsnull
. -
multiply
Returns the product of this dimension with the one specified.- Specified by:
multiply
in interfacejavax.measure.Dimension
- Parameters:
multiplicand
- the dimension by which to multiply this dimension.- Returns:
this
×multiplicand
-
divide
Returns the quotient of this dimension with the one specified.- Specified by:
divide
in interfacejavax.measure.Dimension
- Parameters:
divisor
- the dimension by which to divide this dimension.- Returns:
this
∕divisor
-
combine
Returns the product or the quotient of this dimension with the specified one.- Parameters:
other
- the dimension by which to multiply or divide this dimension.divide
-false
for a multiplication,true
for a division.- Returns:
- the product or division of this dimension by the given dimension.
-
pow
Returns this dimension raised to an exponent.- Parameters:
n
- power to raise this dimension to (can be negative).- Returns:
this
ⁿ
-
pow
Returns this dimension raised to an exponent.- Specified by:
pow
in interfacejavax.measure.Dimension
- Parameters:
n
- power to raise this dimension to (can be negative).- Returns:
this
ⁿ
-
root
Returns the given root of this dimension.- Specified by:
root
in interfacejavax.measure.Dimension
- Parameters:
n
- the root's order.- Returns:
this
raised to power 1/n.
-
equals
Compares this dimension with the given object for equality. -
hashCode
public int hashCode()Returns a hash code value for this dimension. -
toString
Returns a string representation of this dimension.
-