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 UnitDimensionPseudo-dimension for dimensionless units.private static final longFor cross-version compatibility.(package private) final charIf thisUnitDimensionis 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.privateUnitDimension(Map<UnitDimension, Fraction> components) Creates a new derived dimension. -
Method Summary
Modifier and TypeMethodDescriptionprivate UnitDimensioncombine(javax.measure.Dimension other, boolean divide) Returns the product or the quotient of this dimension with the specified one.private static UnitDimensioncreate(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.booleanCompares 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.inthashCode()Returns a hash code value for this dimension.(package private) final booleanReturnstrueif thisUnitDimensionhas no components.(package private) static booleanisDimensionless(javax.measure.Dimension dim) Returnstrueif the given dimension has no components.multiply(javax.measure.Dimension multiplicand) Returns the product of this dimension with the one specified.(package private) final booleannumeratorIs(char s) Returnstrueif the numerator is the dimension identified by the given symbol.pow(int n) Returns this dimension raised to an exponent.private UnitDimensionReturns this dimension raised to an exponent.(package private) ObjectInvoked 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 thisUnitDimensionis itself a base dimension, then the map containsthisraised to power 1. The map shall never benull.- See Also:
-
symbol
final char symbolIf thisUnitDimensionis a base dimension, its symbol (not to be confused with unit symbol). Otherwise (i.e. if thisUnitDimensionis 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 ofUnitsconstants.- 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()Returnstrueif thisUnitDimensionhas no components. Many dimensionless units exist for different quantities as angles, parts per million, etc. -
isDimensionless
static boolean isDimensionless(javax.measure.Dimension dim) Returnstrueif the given dimension has no components. -
numeratorIs
final boolean numeratorIs(char s) Returnstrueif the numerator is the dimension identified by the given symbol. This method returnstrueonly 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:
getBaseDimensionsin 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 returnsthisraised to power 1. This method never returnsnull. -
multiply
Returns the product of this dimension with the one specified.- Specified by:
multiplyin 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:
dividein 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-falsefor a multiplication,truefor 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:
powin 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:
rootin interfacejavax.measure.Dimension- Parameters:
n- the root's order.- Returns:
thisraised 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.
-