Package org.apache.sis.measure
Class Prefixes
java.lang.Object
org.apache.sis.measure.Prefixes
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
FieldsModifier and TypeFieldDescriptionprivate 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 theENUM
array.private static final byte[]
private static final char[]
The SI prefixes in increasing order. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static String
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, ornull
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> pseudoSystemUnit
(SystemUnit<Q> unit) 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.
-
Field Details
-
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[] PREFIXESThe 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 withNormalizer
). 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[] ENUMThe 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_POWERThe maximal power of 1000 for the prefixes in theENUM
array. Note that 1000⁸ = 1E+24.- See Also:
-
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
Returns the converter for the given SI prefix, ornull
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
Returns the concatenation of the given prefix with the given unit symbol. -
getUnit
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 thatUnits.get(String)
recognizes. This method does not perform any arithmetic operation onUnit
, except a check for the exponent.- Parameters:
uom
- a symbol compliant with the rules documented inAbstractUnit.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 returnsnull
. This method is for handling the Special case ofUnits.KILOGRAM
, to be replaced byUnits.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).
-