Class Prefixes

java.lang.Object
org.apache.sis.measure.Prefixes

final class Prefixes extends Object
Utility methods related to the management of prefixes. Current implementation handles only the International System of Unit (SI), but this may be improved in future version.
Since:
1.0
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final LinearConverter[]
    The converters for SI prefixes, created when first needed.
    private static final String
    The SI “deca” prefix.
    private static final char[]
    The SI prefixes from smallest to largest.
    (package private) static final int
    The maximal power of 1000 for the prefixes in the ENUM array.
    private static final byte[]
     
    private static final char[]
    The SI prefixes in increasing order.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Do not allow instantiation of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static String
    concat(char prefix, String unit)
    Returns the concatenation of the given prefix with the given unit symbol.
    (package private) static LinearConverter
    converter(char prefix)
    Returns the converter for the given SI prefix, or null if none.
    (package private) static javax.measure.Unit<?>
    Returns the unit for the given symbol, taking the SI prefix in account.
    (package private) static <Q extends javax.measure.Quantity<Q>>
    ConventionalUnit<Q>
    If the given system unit should be replaced by pseudo-unit for the purpose of formatting, returns that pseudo-unit.
    (package private) static char
    symbol(double scale, int power)
    Returns the SI prefix symbol for the given scale factor, or 0 if none.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DECA

      private static final String DECA
      The SI “deca” prefix. This is the only SI prefix encoded on two letters instead of one. It can be represented by the CJK compatibility character “㍲”, but use of those characters is generally not recommended outside of Chinese, Japanese or Korean texts.
      See Also:
    • PREFIXES

      private static final char[] PREFIXES
      The SI prefixes in increasing order. The only two-letters prefix – “da” – is encoded using the JCK compatibility character “㍲”. The Greek letter μ is repeated twice: the U+00B5 character for micro sign (this is the character that Apache SIS uses in unit symbols) and the U+03BC character for the Greek small letter “mu” (the latter is the character that appears when decomposing JCK compatibility characters with Normalizer). Both characters have same appearance but different values.

      For each prefix at index i, the multiplication factor is given by 10 raised to power POWERS[i].

    • POWERS

      private static final byte[] POWERS
    • ENUM

      private static final char[] ENUM
      The SI prefixes from smallest to largest. Power of tens go from -24 to +24 inclusive with a step of 3, except for the addition of -2, -1, +1, +2 and the omission of 0.
      See Also:
    • MAX_POWER

      static final int MAX_POWER
      The maximal power of 1000 for the prefixes in the ENUM array. Note that 1000⁸ = 1E+24.
      See Also:
    • CONVERTERS

      private static final LinearConverter[] CONVERTERS
      The converters for SI prefixes, created when first needed.
      See Also:
  • Constructor Details

    • Prefixes

      private Prefixes()
      Do not allow instantiation of this class.
  • Method Details

    • converter

      static LinearConverter converter(char prefix)
      Returns the converter for the given SI prefix, or null if none. Those converters are created when first needed and cached for reuse.
    • symbol

      static char symbol(double scale, int power)
      Returns the SI prefix symbol for the given scale factor, or 0 if none.
      Parameters:
      scale - the scale factor.
      power - the unit power. For example if we are scaling m², then this is 2.
      Returns:
      the prefix, or 0 if none.
    • concat

      static String concat(char prefix, String unit)
      Returns the concatenation of the given prefix with the given unit symbol.
    • getUnit

      static javax.measure.Unit<?> getUnit(String uom)
      Returns the unit for the given symbol, taking the SI prefix in account. The given string is usually a single symbol like "km", but may be an expression like "m³" or "m/s" if the given symbol is explicitly registered as an item that Units.get(String) recognizes. This method does not perform any arithmetic operation on Unit, except a check for the exponent.
      Parameters:
      uom - a symbol compliant with the rules documented in AbstractUnit.symbol.
      Returns:
      the unit for the given symbol, or null if no unit is found.
    • pseudoSystemUnit

      static <Q extends javax.measure.Quantity<Q>> ConventionalUnit<Q> pseudoSystemUnit(SystemUnit<Q> unit)
      If the given system unit should be replaced by pseudo-unit for the purpose of formatting, returns that pseudo-unit. Otherwise returns null. This method is for handling the Special case of Units.KILOGRAM, to be replaced by Units.GRAM so a prefix can be computed. The kilogram may appear in an expression like "kg/m", which we want to replace by "g/m". We do that by dividing the unit by 1000 (the converter for "milli" prefix).