tec.units.ri.unit.MetricPrefix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unit-ri Show documentation
Show all versions of unit-ri Show documentation
Unit Standard (JSR 363) Reference Implementation.
/*
* Units of Measurement Reference Implementation
* Copyright (c) 2005-2016, Jean-Marie Dautelle, Werner Keil, V2COM.
*
* 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-363 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 tec.units.ri.unit;
import static tec.units.ri.internal.MathUtil.pow;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.UnitConverter;
import tec.units.ri.function.RationalConverter;
import tec.uom.lib.common.function.SymbolSupplier;
import tec.uom.lib.common.function.UnitConverterSupplier;
/**
*
* This class provides support for the 20 prefixes used in the metric system (decimal multiples and submultiples of units). For example:
*
*
*
* import static tec.units.ri.unit.Units.*; // Static import.
* import static tec.units.ri.unit.MetricPrefix.*; // Static import.
* import javax.measure.*;
* import javax.measure.quantity.*;
* ...
* Unit HECTOPASCAL = HECTO(PASCAL);
* Unit KILOMETRE = KILO(METRE);
*
*
*
*
*
* @see Wikipedia: Metric Prefix
* @author Jean-Marie Dautelle
* @author Werner Keil
* @version 0.9.1, $Date: 2016-03-17 $
*/
public enum MetricPrefix implements SymbolSupplier, UnitConverterSupplier {
YOTTA("Y", RationalConverter.of(1000000000000000000000000d, 1d)), ZETTA("Z", RationalConverter.of(1000000000000000000000d, 1d)), EXA("E",
RationalConverter.of(pow(10, 18), 1d)), PETA("P", RationalConverter.of(pow(10, 15), 1d)), TERA("T", RationalConverter.of(pow(10, 12), 1d)), GIGA(
"G", RationalConverter.of(pow(10, 9), 1d)), MEGA("M", RationalConverter.of(pow(10, 6), 1d)), KILO("k", RationalConverter.of(pow(10, 3), 1d)), HECTO(
"h", RationalConverter.of(100d, 1d)), DEKA("da", RationalConverter.of(10d, 1d)), DECI("d", RationalConverter.of(1d, 10d)), CENTI("c",
RationalConverter.of(1d, 100d)), MILLI("m", RationalConverter.of(1d, 1000d)), MICRO("µ", RationalConverter.of(1d, pow(10, 6))), NANO("n",
RationalConverter.of(1d, pow(10, 9))), PICO("p", RationalConverter.of(1d, pow(10, 12))), FEMTO("f", RationalConverter.of(1d, pow(10, 15))), ATTO(
"a", RationalConverter.of(1d, pow(10, 18))), ZEPTO("z", RationalConverter.of(1d, pow(10, 21))), YOCTO("y", RationalConverter
.of(1d, pow(10, 24)));
/**
* The symbol of this prefix, as returned by {@link #getSymbol}.
*
* @serial
* @see #getSymbol()
*/
private final String symbol;
/**
* The UnitConverter
of this prefix, as returned by {@link #getConverter}.
*
* @serial
* @see #getConverter()
* @see {@link UnitConverter}
*/
private final UnitConverter converter;
/**
* Creates a new prefix.
*
* @param symbol
* the symbol of this prefix.
* @param converter
* the associated unit converter.
*/
MetricPrefix(String symbol, RationalConverter converter) {
this.symbol = symbol;
this.converter = converter;
}
/**
* Returns the symbol of this prefix.
*
* @return this prefix symbol, not {@code null}.
*
* @see #toString()
*/
public String getSymbol() {
return symbol;
}
/**
* Returns the corresponding unit converter.
*
* @return the unit converter.
*/
public UnitConverter getConverter() {
return converter;
}
/**
* Returns the specified unit multiplied by the factor 1024
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e24)
.
*/
public static final > Unit YOTTA(Unit unit) {
return unit.transform(YOTTA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 1021
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e21)
.
*/
public static final > Unit ZETTA(Unit unit) {
return unit.transform(ZETTA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 1018
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e18)
.
*/
public static final > Unit EXA(Unit unit) {
return unit.transform(EXA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 1015
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e15)
.
*/
public static final > Unit PETA(Unit unit) {
return unit.transform(PETA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 1012
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e12)
.
*/
public static final > Unit TERA(Unit unit) {
return unit.transform(TERA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 109
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e9)
.
*/
public static > Unit GIGA(Unit unit) {
return unit.transform(GIGA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 106
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e6)
.
*/
public static final > Unit MEGA(Unit unit) {
return unit.transform(MEGA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 103
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e3)
.
*/
public static final > Unit KILO(Unit unit) {
return unit.transform(KILO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 102
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e2)
.
*/
public static final > Unit HECTO(Unit unit) {
return unit.transform(HECTO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 101
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e1)
.
*/
public static final > Unit DEKA(Unit unit) {
return unit.transform(DEKA.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-1
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-1)
.
*/
public static final > Unit DECI(Unit unit) {
return unit.transform(DECI.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-2
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-2)
.
*/
public static > Unit CENTI(Unit unit) {
return unit.transform(CENTI.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-3
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-3)
.
*/
public static final > Unit MILLI(Unit unit) {
return unit.transform(MILLI.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-6
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-6)
.
*/
public static final > Unit MICRO(Unit unit) {
return unit.transform(MICRO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-9
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-9)
.
*/
public static final > Unit NANO(Unit unit) {
return unit.transform(NANO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-12
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-12)
.
*/
public static final > Unit PICO(Unit unit) {
return unit.transform(PICO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-15
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-15)
.
*/
public static final > Unit FEMTO(Unit unit) {
return unit.transform(FEMTO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-18
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-18)
.
*/
public static final > Unit ATTO(Unit unit) {
return unit.transform(ATTO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-21
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-21)
.
*/
public static final > Unit ZEPTO(Unit unit) {
return unit.transform(ZEPTO.getConverter());
}
/**
* Returns the specified unit multiplied by the factor 10-24
*
* @param
* The type of the quantity measured by the unit.
* @param unit
* any unit.
* @return unit.multiply(1e-24)
.
*/
public static final > Unit YOCTO(Unit unit) {
return unit.transform(YOCTO.getConverter());
}
}