Class SingleUnitImpl

java.lang.Object
com.ibm.icu.impl.units.SingleUnitImpl

public class SingleUnitImpl extends Object
A class representing a single unit (optional SI or binary prefix, and dimensionality).
  • Field Details

    • index

      private int index
      Simple unit index, unique for every simple unit, -1 for the dimensionless unit. This is an index into a string list in unit.txt {ConversionUnits}.

      The default value is -1, meaning the dimensionless unit: isDimensionless() will return true, until index is changed.

    • simpleUnitID

      private String simpleUnitID
      SimpleUnit is the simplest form of a Unit. For example, for "square-millimeter", the simple unit would be "meter"Ò

      The default value is "", meaning the dimensionless unit: isDimensionless() will return true, until index is changed.

    • dimensionality

      private int dimensionality
      Determine the power of the SingleUnit. For example, for "square-meter", the dimensionality will be 2.

      NOTE: Default dimensionality is 1.

    • unitPrefix

      private MeasureUnit.MeasurePrefix unitPrefix
      SI or binary prefix.
  • Constructor Details

    • SingleUnitImpl

      public SingleUnitImpl()
  • Method Details

    • copy

      public SingleUnitImpl copy()
    • build

      public MeasureUnit build()
    • getNeutralIdentifier

      public String getNeutralIdentifier()
      Generates a neutral identifier string for a single unit which means we do not include the dimension signal.
    • compareTo

      int compareTo(SingleUnitImpl other)
      Compare this SingleUnitImpl to another SingleUnitImpl for the sake of sorting and coalescing.

      Sort order of units is specified by UTS #35 (https://unicode.org/reports/tr35/tr35-info.html#Unit_Identifier_Normalization).

      Takes the sign of dimensionality into account, but not the absolute value: per-meter is not considered the same as meter, but meter is considered the same as square-meter.

      The dimensionless unit generally does not get compared, but if it did, it would sort before other units by virtue of index being invalid input: '<' 0 and dimensionality not being negative.

    • isCompatibleWith

      boolean isCompatibleWith(SingleUnitImpl other)
      Checks whether this SingleUnitImpl is compatible with another for the purpose of coalescing.

      Units with the same base unit and SI or binary prefix should match, except that they must also have the same dimensionality sign, such that we don't merge numerator and denominator.

    • getSimpleUnitID

      public String getSimpleUnitID()
    • setSimpleUnit

      public void setSimpleUnit(int simpleUnitIndex, String[] simpleUnits)
    • getDimensionality

      public int getDimensionality()
    • setDimensionality

      public void setDimensionality(int dimensionality)
    • getPrefix

      public MeasureUnit.MeasurePrefix getPrefix()
    • setPrefix

      public void setPrefix(MeasureUnit.MeasurePrefix unitPrefix)
    • getIndex

      public int getIndex()