Class SingleUnitImpl


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

      • 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 java.lang.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.

    • Constructor Detail

      • SingleUnitImpl

        public SingleUnitImpl()
    • Method Detail

      • getNeutralIdentifier

        public java.lang.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 < 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 java.lang.String getSimpleUnitID()
      • setSimpleUnit

        public void setSimpleUnit​(int simpleUnitIndex,
                                  java.lang.String[] simpleUnits)
      • getDimensionality

        public int getDimensionality()
      • setDimensionality

        public void setDimensionality​(int dimensionality)
      • getIndex

        public int getIndex()