Class UnitDimension

java.lang.Object
org.apache.sis.measure.UnitDimension
All Implemented Interfaces:
Serializable, javax.measure.Dimension

final class UnitDimension extends Object implements javax.measure.Dimension, Serializable
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.
The powers should be integers, but this implementation nevertheless accepts fractional power of dimensions. While quantities with dimension such as √M makes no sense physically, on a pragmatic point of view it is easier to write programs in which such units appear in intermediate calculations but become integers in the final result. Furthermore, some dimensions with fractional power actually exist. Examples: All UnitDimension instances are immutable and thus inherently thread-safe.
Since:
0.8
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (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 this UnitDimension is a base dimension, its symbol (not to be confused with unit symbol).
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    (package private)
    UnitDimension(char symbol)
    Creates a new base dimension with the given symbol, which shall not be zero.
    private
    Creates a new derived dimension.
  • Method Summary

    Modifier and Type
    Method
    Description
    combine(javax.measure.Dimension other, boolean divide)
    Returns the product or the quotient of this dimension with the specified one.
    private static UnitDimension
    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
    equals(Object other)
    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.
    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.
    int
    Returns a hash code value for this dimension.
    (package private) final boolean
    Returns true if this UnitDimension has no components.
    (package private) static boolean
    isDimensionless(javax.measure.Dimension dim)
    Returns true 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)
    Returns true if the numerator is the dimension identified by the given symbol.
    pow(int n)
    Returns this dimension raised to an exponent.
    Returns this dimension raised to an exponent.
    (package private) Object
    Invoked on deserialization for returning a unique instance of UnitDimension.
    root(int n)
    Returns the given root of this dimension.
    Returns a string representation of this dimension.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • NONE

      static final UnitDimension NONE
      Pseudo-dimension for dimensionless units.
    • components

      final Map<UnitDimension,Fraction> 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-zero symbol). If this UnitDimension is itself a base dimension, then the map contains this raised to power 1. The map shall never be null.
      See Also:
    • symbol

      final char symbol
      If this UnitDimension is a base dimension, its symbol (not to be confused with unit symbol). Otherwise (i.e. if this UnitDimension 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 of Units constants.
      Parameters:
      symbol - the symbol of this base dimension (not to be confused with unit symbol).
    • UnitDimension

      private UnitDimension(Map<UnitDimension,Fraction> components)
      Creates a new derived dimension. This constructor shall never be invoked directly (except for NONE); use create(Map) instead.
      Parameters:
      components - the product of base dimensions together with their power.
  • Method Details

    • create

      private static UnitDimension create(Map<UnitDimension,Fraction> components)
      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

      Object readResolve() throws ObjectStreamException
      Invoked on deserialization for returning a unique instance of UnitDimension.
      Throws:
      ObjectStreamException
    • isDimensionless

      final boolean isDimensionless()
      Returns true if this UnitDimension has no components. Many dimensionless units exist for different quantities as angles, parts per million, etc.
    • isDimensionless

      static boolean isDimensionless(javax.measure.Dimension dim)
      Returns true if the given dimension has no components.
    • numeratorIs

      final boolean numeratorIs(char s)
      Returns true if the numerator is the dimension identified by the given symbol. This method returns true 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

      public Map<UnitDimension,Integer> 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 interface javax.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 returns this raised to power 1. This method never returns null.
    • multiply

      public UnitDimension multiply(javax.measure.Dimension multiplicand)
      Returns the product of this dimension with the one specified.
      Specified by:
      multiply in interface javax.measure.Dimension
      Parameters:
      multiplicand - the dimension by which to multiply this dimension.
      Returns:
      this × multiplicand
    • divide

      public UnitDimension divide(javax.measure.Dimension divisor)
      Returns the quotient of this dimension with the one specified.
      Specified by:
      divide in interface javax.measure.Dimension
      Parameters:
      divisor - the dimension by which to divide this dimension.
      Returns:
      thisdivisor
    • combine

      private UnitDimension combine(javax.measure.Dimension other, boolean divide)
      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

      private UnitDimension pow(Fraction n)
      Returns this dimension raised to an exponent.
      Parameters:
      n - power to raise this dimension to (can be negative).
      Returns:
      this
    • pow

      public UnitDimension pow(int n)
      Returns this dimension raised to an exponent.
      Specified by:
      pow in interface javax.measure.Dimension
      Parameters:
      n - power to raise this dimension to (can be negative).
      Returns:
      this
    • root

      public UnitDimension root(int n)
      Returns the given root of this dimension.
      Specified by:
      root in interface javax.measure.Dimension
      Parameters:
      n - the root's order.
      Returns:
      this raised to power 1/n.
    • equals

      public boolean equals(Object other)
      Compares this dimension with the given object for equality.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hash code value for this dimension.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of this dimension.
      Overrides:
      toString in class Object