javax.measure.MetricPrefix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unit-api Show documentation
Show all versions of unit-api Show documentation
Units of Measurement Standard - This JSR specifies Java packages for modeling and working with measurement values, quantities and their corresponding units.
The newest version!
/*
* Units of Measurement API
* Copyright (c) 2014-2023, Jean-Marie Dautelle, Werner Keil, Otavio Santana.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385 nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package javax.measure;
/**
* Provides support for the 24 prefixes used in the metric system (decimal multiples and submultiples of units). For example:
*
*
* {@code import static tech.units.indriya.unit.Units.*; // Static import (from the RI).
* import static javax.measure.MetricPrefix.*; // Static import.
* import javax.measure.*;
* import javax.measure.quantity.*;
* ...
* Unit HECTOPASCAL = HECTO(PASCAL);
* Unit KILOMETRE = KILO(METRE);}
*
* You could also apply Unit.prefix
:
*
* {@code ...
* Unit HECTOPASCAL = PASCAL.prefix(HECTO);
* Unit KILOMETRE = METRE.prefix(KILO);}
*
*
*
* Do not use ordinal() to obtain the numeric representation of MetricPrefix. Use getValue() and getExponent() instead.
*
*
*
* - Implementation Requirements
- This is an immutable and thread-safe enum.
*
*
* @see Wikipedia: Metric Prefix
* @author Jean-Marie Dautelle
* @author Werner Keil
* @version 2.3, May 20, 2023
* @since 2.0
*/
public enum MetricPrefix implements Prefix {
/** Prefix for 1030. */
QUETTA("Q", 30),
/** Prefix for 1027. */
RONNA("R", 27),
/** Prefix for 1024. */
YOTTA("Y", 24),
/** Prefix for 1021. */
ZETTA("Z", 21),
/** Prefix for 1018. */
EXA("E", 18),
/** Prefix for 1015. */
PETA("P", 15),
/** Prefix for 1012. */
TERA("T", 12),
/** Prefix for 109.
* @see Wikipedia: Giga
*/
GIGA("G", 9),
/** Prefix for 106.
* @see Wikipedia: Mega */
MEGA("M", 6),
/** Prefix for 103.
* @see Wikipedia: Kilo
*/
KILO("k", 3),
/** Prefix for 102.
* @see Wikipedia: Hecto */
HECTO("h", 2),
/** Prefix for 101.
* @see Wikipedia: Deca */
DECA("da", 1),
/** Prefix for 10-1.
* @see Wikipedia: Deci */
DECI("d", -1),
/** Prefix for 10-2.
* @see Wikipedia: Centi */
CENTI("c", -2),
/** Prefix for 10-3.
* @see Wikipedia: Milli */
MILLI("m", -3),
/** Prefix for 10-6.
* @see Wikipedia: Micro */
MICRO("\u00b5", -6),
/** Prefix for 10-9.
* @see Wikipedia: Nano */
NANO("n", -9),
/** Prefix for 10-12. */
PICO("p", -12),
/** Prefix for 10-15. */
FEMTO("f", -15),
/** Prefix for 10-18. */
ATTO("a", -18),
/** Prefix for 10-21. */
ZEPTO("z", -21),
/** Prefix for 10-24. */
YOCTO("y", -24),
/** Prefix for 10-27. */
RONTO("r", -27),
/** Prefix for 10-30. */
QUECTO("q", -30);
/**
* The symbol of this prefix, as returned by {@link #getSymbol}.
*
* @serial
* @see #getSymbol()
*/
private final String symbol;
/**
* Exponent part of the associated factor in base^exponent representation.
*/
private final int exponent;
/**
* Creates a new prefix.
*
* @param symbol
* the symbol of this prefix.
* @param exponent
* part of the associated factor in base^exponent representation.
*/
private MetricPrefix(String symbol, int exponent) {
this.symbol = symbol;
this.exponent = exponent;
}
/**
* Returns the specified unit multiplied by the factor 1030
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e30)
.
* @see #QUETTA
*/
public static > Unit QUETTA(Unit unit) {
return unit.prefix(QUETTA);
}
/**
* Returns the specified unit multiplied by the factor 1027
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e27)
.
* @see #RONNA
*/
public static > Unit RONNA(Unit unit) {
return unit.prefix(RONNA);
}
/**
* Returns the specified unit multiplied by the factor 1024
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e24)
.
* @see #YOTTA
*/
public static > Unit YOTTA(Unit unit) {
return unit.prefix(YOTTA);
}
/**
* Returns the specified unit multiplied by the factor 1021
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e21)
.
* @see #ZETTA
*/
public static > Unit ZETTA(Unit unit) {
return unit.prefix(ZETTA);
}
/**
* Returns the specified unit multiplied by the factor 1018
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e18)
.
* @see #EXA
*/
public static > Unit EXA(Unit unit) {
return unit.prefix(EXA);
}
/**
* Returns the specified unit multiplied by the factor 1015
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e15)
.
* @see #PETA
*/
public static > Unit PETA(Unit unit) {
return unit.prefix(PETA);
}
/**
* Returns the specified unit multiplied by the factor 1012
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e12)
.
* @see #TERA
*/
public static > Unit TERA(Unit unit) {
return unit.prefix(TERA);
}
/**
* Returns the specified unit multiplied by the factor 109
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e9)
.
* @see #GIGA
*/
public static > Unit GIGA(Unit unit) {
return unit.prefix(GIGA);
}
/**
* Returns the specified unit multiplied by the factor 106
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e6)
.
* @see #MEGA
*/
public static > Unit MEGA(Unit unit) {
return unit.prefix(MEGA);
}
/**
* Returns the specified unit multiplied by the factor 103
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e3)
.
* @see #KILO
*/
public static > Unit KILO(Unit unit) {
return unit.prefix(KILO);
}
/**
* Returns the specified unit multiplied by the factor 102
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e2)
.
* @see #HECTO
*/
public static > Unit HECTO(Unit unit) {
return unit.prefix(HECTO);
}
/**
* Returns the specified unit multiplied by the factor 101
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e1)
.
* @see #DECA
*/
public static > Unit DECA(Unit unit) {
return unit.prefix(DECA);
}
/**
* US alias for DECA
.
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e1)
.
* @see #DECA
*/
public static > Unit DEKA(Unit unit) {
return unit.prefix(DECA);
}
/**
* Returns the specified unit multiplied by the factor 10-1
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-1)
.
* @see #DECI
*/
public static > Unit DECI(Unit unit) {
return unit.prefix(DECI);
}
/**
* Returns the specified unit multiplied by the factor 10-2
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-2)
.
* @see #CENTI
*/
public static > Unit CENTI(Unit unit) {
return unit.prefix(CENTI);
}
/**
* Returns the specified unit multiplied by the factor 10-3
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-3)
.
* @see #MILLI
*/
public static > Unit MILLI(Unit unit) {
return unit.prefix(MILLI);
}
/**
* Returns the specified unit multiplied by the factor 10-6
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-6)
.
* @see #MICRO
*/
public static > Unit MICRO(Unit unit) {
return unit.prefix(MICRO);
}
/**
* Returns the specified unit multiplied by the factor 10-9
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-9)
.
* @see #NANO
*/
public static > Unit NANO(Unit unit) {
return unit.prefix(NANO);
}
/**
* Returns the specified unit multiplied by the factor 10-12
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-12)
.
* @see #PICO
*/
public static > Unit PICO(Unit unit) {
return unit.prefix(PICO);
}
/**
* Returns the specified unit multiplied by the factor 10-15
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-15)
.
* @see #FEMTO
*/
public static > Unit FEMTO(Unit unit) {
return unit.prefix(FEMTO);
}
/**
* Returns the specified unit multiplied by the factor 10-18
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-18)
.
* @see #ATTO
*/
public static > Unit ATTO(Unit unit) {
return unit.prefix(ATTO);
}
/**
* Returns the specified unit multiplied by the factor 10-21
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-21)
.
* #see ZEPTO
*/
public static > Unit ZEPTO(Unit unit) {
return unit.prefix(ZEPTO);
}
/**
* Returns the specified unit multiplied by the factor 10-24
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-24)
.
* @see #YOCTO
*/
public static > Unit YOCTO(Unit unit) {
return unit.prefix(YOCTO);
}
/**
* Returns the specified unit multiplied by the factor 10-27
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-27)
.
* @see #RONTO
*/
public static > Unit RONTO(Unit unit) {
return unit.prefix(RONTO);
}
/**
* Returns the specified unit multiplied by the factor 10-30
*
* @param
* type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.times(1e-30)
.
* @see #QUECTO
*/
public static > Unit QUECTO(Unit unit) {
return unit.prefix(QUECTO);
}
/**
* Returns the symbol of this prefix.
*
* @return this prefix symbol, not {@code null}.
*/
@Override
public String getSymbol() {
return symbol;
}
/**
* Base part of the associated factor in {@code base^exponent} representation. For metric prefix, this is always 10.
*/
@Override
public Integer getValue() {
return 10;
}
/**
* Exponent part of the associated factor in {@code base^exponent} representation.
*/
@Override
public int getExponent() {
return exponent;
}
/**
* Returns the name of this prefix.
*
* @return this prefix name, not {@code null}.
*/
@Override
public String getName() {
return name();
}
}