si.uom.SI Maven / Gradle / Ivy
/*
* International System of Units (SI)
* Copyright (c) 2005-2019, Jean-Marie Dautelle, Werner Keil and others.
*
* 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, Units of Measurement nor the names of their 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 si.uom;
import static tec.uom.se.AbstractUnit.ONE;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.Acceleration;
import javax.measure.quantity.Angle;
import javax.measure.quantity.Dimensionless;
import javax.measure.quantity.ElectricCharge;
import javax.measure.quantity.Energy;
import javax.measure.quantity.Length;
import javax.measure.quantity.Mass;
import si.uom.quantity.Action;
import si.uom.quantity.AngularAcceleration;
import si.uom.quantity.AngularSpeed;
import si.uom.quantity.DynamicViscosity;
import si.uom.quantity.ElectricPermittivity;
import si.uom.quantity.Intensity;
import si.uom.quantity.IonizingRadiation;
import si.uom.quantity.KinematicViscosity;
import si.uom.quantity.Luminance;
import si.uom.quantity.MagneticFieldStrength;
import si.uom.quantity.MagneticPermeability;
import si.uom.quantity.MagnetomotiveForce;
import si.uom.quantity.Radiance;
import si.uom.quantity.RadiantIntensity;
import si.uom.quantity.WaveNumber;
import tec.uom.se.AbstractUnit;
import tec.uom.se.format.SimpleUnitFormat;
import tec.uom.se.function.MultiplyConverter;
import tec.uom.se.function.PiMultiplierConverter;
import tec.uom.se.function.RationalConverter;
import tec.uom.se.unit.AlternateUnit;
import tec.uom.se.unit.ProductUnit;
import tec.uom.se.unit.TransformedUnit;
import tec.uom.se.unit.Units;
/**
*
* This class defines all SI (Système International d'Unités) base units and
* derived units as well as units that are accepted for use with the SI units.
*
*
* @see Wikipedia:
* International System of Units
* @see Units outside
* the SI that are accepted for use with the SI
* @see SI 2006
* - Official Specification
* @see tec.uom.se.unit.MetricPrefix
*
* @author Jean-Marie Dautelle
* @author Werner Keil
* @version 1.4, May 1, 2019
*/
public final class SI extends Units {
/**
* The singleton instance.
*/
private static final SI INSTANCE = new SI();
////////////////////////////////
// SI DERIVED ALTERNATE UNITS //
////////////////////////////////
/**
* The SI unit for magnetomotive force (standard name At
).
*/
public static final Unit AMPERE_TURN = addUnit(
new AlternateUnit(Units.AMPERE, "At"), MagnetomotiveForce.class);
//////////////////////////////
// SI DERIVED PRODUCT UNITS //
//////////////////////////////
/**
* The SI unit for acceleration quantities (standard name
* m/s²
).
*/
public static final Unit METRE_PER_SQUARE_SECOND = addUnit(
new ProductUnit(METRE_PER_SECOND.divide(SECOND)), Acceleration.class);
/**
* The SI unit for action quantities (standard name j.s
).
*/
public static final Unit JOULE_SECOND = addUnit(new ProductUnit(JOULE.multiply(SECOND)),
Action.class);
/**
* The SI unit for electric permittivity (standard name ε
,
* F/m
or F·m−1
). In electromagnetism, absolute
* permittivity is the measure of resistance that is encountered when
* forming an electric field in a medium.
*/
public static final Unit FARAD_PER_METRE = addUnit(
new AlternateUnit(FARAD.divide(METRE), "ε"), ElectricPermittivity.class);
/**
* The SI unit for magnetic permeability quantities (standard name
* N/A2
).
*/
public static final Unit NEWTON_PER_SQUARE_AMPERE = addUnit(
new ProductUnit(NEWTON.divide(AMPERE.pow(2))), MagneticPermeability.class);
/**
* The SI unit for wave number quantities (standard name 1/m
).
*/
public static final Unit RECIPROCAL_METRE = addUnit(new ProductUnit(METRE.pow(-1)),
WaveNumber.class);
/**
* The SI unit for dynamic viscosity quantities (standard name
* Pa.s
).
*/
public static final Unit PASCAL_SECOND = addUnit(
new ProductUnit(PASCAL.multiply(SECOND)), DynamicViscosity.class);
/**
* Luminance is a photometric measure of the luminous intensity per unit
* area of light travelling in a given direction. It describes the amount of
* light that passes through, is emitted or reflected from a particular
* area, and falls within a given solid angle. The SI unit for luminance is
* candela per square metre (cd/m2
).
*
* @see Wikipedia:
* Luminance
*/
public static final Unit CANDELA_PER_SQUARE_METRE = addUnit(
new ProductUnit(CANDELA.divide(SQUARE_METRE)), Luminance.class);
/**
* The SI unit for kinematic viscosity quantities (standard name
* m2/s"
).
*/
public static final Unit SQUARE_METRE_PER_SECOND = addUnit(
new ProductUnit(SQUARE_METRE.divide(SECOND)), KinematicViscosity.class);
/**
* A magnetic field is the magnetic effect of electric currents and magnetic
* materials. The magnetic field at any given point is specified by both a
* direction and a magnitude (or strength); as such it is a vector field.
* The H-field is measured in amperes per metre (A/m
) in SI
* units.
*
* @see
* Wikipedia: Magnetic Field - The H Field
*/
public static final Unit AMPERE_PER_METRE = addUnit(
new ProductUnit(AMPERE.divide(METRE)), MagneticFieldStrength.class);
/**
* The SI unit for ionizing radiation quantities (standard name
* C/kg"
).
*/
public static final Unit COULOMB_PER_KILOGRAM = addUnit(
new ProductUnit(COULOMB.divide(KILOGRAM)), IonizingRadiation.class);
/**
* The SI unit for radiant intensity (standard name W/sr
).
*/
public static final Unit WATT_PER_STERADIAN = addUnit(
WATT.divide(STERADIAN).asType(RadiantIntensity.class));
/**
* The SI unit for radiance (standard name W⋅sr−1⋅m−2
).
*/
public static final Unit WATT_PER_STERADIAN_PER_SQUARE_METRE = addUnit(
WATT_PER_STERADIAN.divide(SQUARE_METRE).asType(Radiance.class));
/**
* The SI unit for intensity (standard name W/m2
).
*/
public static final Unit WATT_PER_SQUARE_METRE = addUnit(
WATT.divide(SQUARE_METRE).asType(Intensity.class));
/**
* The SI unit of angular speed (standard name
* rad/s
).
* @see AngularSpeed
*/
public static final Unit RADIAN_PER_SECOND = addUnit(
new ProductUnit(RADIAN.divide(SECOND)), "Radian per second", AngularSpeed.class);
/**
* The SI unit of angular acceleration (standard name
* rad/s²
).
* @see AngularAcceleration
*/
public static final Unit RADIAN_PER_SQUARE_SECOND = addUnit(
new ProductUnit(RADIAN_PER_SECOND.divide(SECOND)), "Radian per square second", AngularAcceleration.class);
/////////////////////////////////////////////////////////////////
// Units outside the SI that are accepted for use with the SI. //
/////////////////////////////////////////////////////////////////
/**
* An energy unit accepted for use with SI units (standard name
* eV
). The electronvolt is the kinetic energy acquired by an
* electron passing through a potential difference of 1 V in vacuum. The
* value must be obtained by experiment, and is therefore not known exactly.
*/
public static final Unit ELECTRON_VOLT = new TransformedUnit(JOULE,
new MultiplyConverter(1.602176487E-19));
// CODATA 2006 - http://physics.nist.gov/cuu/Constants/codata.pdf
/**
* A mass unit accepted for use with SI units (standard name
* u
). The unified atomic mass unit is equal to 1/12 of the
* mass of an unbound atom of the nuclide 12C, at rest and in its ground
* state. The value must be obtained by experiment, and is therefore not
* known exactly.
*/
public static final Unit UNIFIED_ATOMIC_MASS = addUnit(
new TransformedUnit(KILOGRAM, new MultiplyConverter(1.660538782E-27)), "Unified atomic mass", "u",
true);
// CODATA 2006 - http://physics.nist.gov/cuu/Constants/codata.pdf
/**
* A length unit accepted for use with SI units (standard name
* UA
). The astronomical unit is a unit of length. Its value is
* such that, when used to describe the motion of bodies in the solar
* system, the heliocentric gravitation constant is (0.017 202 098 95)2
* ua3·d-2. The value must be obtained by experiment, and is therefore not
* known exactly.
*/
public static final Unit ASTRONOMICAL_UNIT = addUnit(
new TransformedUnit(METRE, new MultiplyConverter(149597871000.0)));
// Best estimate source: http://maia.usno.navy.mil/NSFA/CBE.html
/**
* An angle unit accepted for use with SI units (standard name
* rev
).
*/
public static final Unit REVOLUTION = addUnit(
new TransformedUnit(RADIAN, new PiMultiplierConverter().concatenate(new RationalConverter(2, 1))));
///////////////////////////
// Fundamental Constants //
///////////////////////////
/**
* Holds the numeric value of the Avogadro constant.
*/
static final double AVOGADRO_CONSTANT_VALUE = 6.02214199E23; // (1/mol).
/**
* Holds the numeric value of the Boltzmann constant.
*/
static final double BOLTZMANN_CONSTANT_VALUE = 1.3806485279E-23;
/**
* Holds the electric charge of one electron.
*/
static final double ELEMENTARY_CHARGE_VALUE = 1.602176462E-19; // (C).
/**
* Holds the numeric value of the Planck constant.
*/
static final double PLANCK_CONSTANT_VALUE = 6.62607015E-34; // (1/mol).
/**
* The Avogadro constant, named after scientist Amedeo Avogadro, is the number of constituent particles, usually molecules, atoms or ions that are contained in the amount of substance given by one mole.
* It is the proportionality factor that relates the molar mass of a substance to the mass of a sample, is designated with the symbol NA
or L
, and has the value 6.022140857(74)×1023 mol−1 in the International System of Units (SI).
*/
public static final Unit AVOGADRO_CONSTANT = addUnit(new AlternateUnit(ONE.divide(MOLE), "m-1").multiply(AVOGADRO_CONSTANT_VALUE), "L"); // (1/mol).
/**
* The Boltzmann constant (kB
or k
) is a physical constant named after its discoverer, Ludwig Boltzmann,
* which relates the average relative kinetic energy of particles in a gas with the temperature of the gas and occurs in Planck's law of black-body radiation and in Boltzmann's entropy formula.
*/
public static final Unit BOLTZMANN_CONSTANT = addUnit(new AlternateUnit(JOULE.divide(KILOGRAM), "J/K").multiply(BOLTZMANN_CONSTANT_VALUE), "k");
/**
* The elementary charge, usually denoted by e
or sometimes qe
, is the electric charge carried by a single proton or,
* equivalently, the magnitude of the electric charge carried by a single electron, which has charge −1 e.
* This elementary charge is a fundamental physical constant.
* To avoid confusion over its sign, e is sometimes called the elementary positive charge.
*/
public static final Unit ELEMENTARY_CHARGE = addUnit(COULOMB.multiply(ELEMENTARY_CHARGE_VALUE), "e", true);
/**
* The Planck constant (denoted h
, also called Planck's constant) is a physical constant that is the quantum of electromagnetic action, which relates the energy carried by a photon to its frequency. A photon's energy is equal to its frequency multiplied by the Planck constant. The Planck constant is of fundamental importance in quantum mechanics, and in metrology it is the basis for the definition of the kilogram.
*/
public static final Unit PLANCK_CONSTANT = addUnit(JOULE_SECOND.multiply(PLANCK_CONSTANT_VALUE),"h", true);
/////////////////////
// Collection View //
/////////////////////
/**
* Default constructor (prevents this class from being instantiated).
*/
private SI() { // Singleton
}
@Override
public String getName() {
return SI.class.getSimpleName(); // for Java SE this works
}
/**
* Returns the singleton instance of this class.
*
* @return the metric system instance.
*/
public static SI getInstance() {
return INSTANCE;
}
/**
* Adds a new unit not mapped to any specified quantity type and puts a text
* as symbol or label.
*
* @param unit
* the unit being added.
* @param name
* the string to use as name
* @param text
* the string to use as label or symbol
* @param isLabel
* if the string should be used as a label or not
* @return unit
.
*/
private static > U addUnit(U unit, String name, String text, boolean isLabel) {
if (isLabel) {
SimpleUnitFormat.getInstance().label(unit, text);
}
if (name != null && unit instanceof AbstractUnit) {
return Helper.addUnit(INSTANCE.units, unit, name);
} else {
INSTANCE.units.add(unit);
}
return unit;
}
/**
* Adds a new unit not mapped to any specified quantity type and puts a text
* as symbol or label.
*
* @param unit
* the unit being added.
* @param text
* the string to use as label or symbol
* @param isLabel
* if the string should be used as a label or not
* @return unit
.
*/
private static > U addUnit(U unit, String text, boolean isLabel) {
return addUnit(unit, null, text, isLabel);
}
/**
* Adds a new unit not mapped to any specified quantity type and puts a text
* as symbol or label.
*
* @param unit
* the unit being added.
* @param text
* the string to use as label or symbol
* @return unit
.
*/
private static > U addUnit(U unit, String text) {
return addUnit(unit, null, text, true);
}
/**
* Adds a new unit not mapped to any specified quantity type.
*
* @param unit
* the unit being added.
* @return unit
.
*/
private static > U addUnit(U unit) {
INSTANCE.units.add(unit);
return unit;
}
/**
* Adds a new unit with name and label and maps it to the specified quantity type.
*
* @param unit
* the unit being added.
* @param name
* the string to use as name
* @param label
* the string to use as label
* @param type
* the quantity type.
* @return unit
.
*/
// private static > U addUnit(U unit, String name, String label, Class extends Quantity>> type) {
// INSTANCE.quantityToUnit.put(type, unit);
// return addUnit(unit, name, label, true);
// }
/**
* Adds a new unit with a name and maps it to the specified quantity type.
*
* @param unit
* the unit being added.
* @param name
* the string to use as name
* @param type
* the quantity type.
* @return unit
.
*/
private static > U addUnit(U unit, String name, Class extends Quantity>> type) {
INSTANCE.quantityToUnit.put(type, unit);
return addUnit(unit, name, null, false);
}
/**
* Adds a new unit and maps it to the specified quantity type.
*
* @param unit
* the unit being added.
* @param type
* the quantity type.
* @return unit
.
*/
private static > U addUnit(U unit, Class extends Quantity>> type) {
INSTANCE.units.add(unit);
INSTANCE.quantityToUnit.put(type, unit);
return unit;
}
}