
si.uom.SI Maven / Gradle / Ivy
The newest version!
/*
* International System of Units (SI)
* Copyright (c) 2005-2025, 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 SI System, 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 tech.units.indriya.AbstractUnit.ONE;
import javax.measure.MetricPrefix;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.Acceleration;
import javax.measure.quantity.Dimensionless;
import javax.measure.quantity.ElectricCharge;
import javax.measure.quantity.Frequency;
import javax.measure.quantity.Speed;
import si.uom.quantity.Absement;
import si.uom.quantity.Action;
import si.uom.quantity.AngularAcceleration;
import si.uom.quantity.AngularSpeed;
import si.uom.quantity.AreaDensity;
import si.uom.quantity.Density;
import si.uom.quantity.DynamicViscosity;
import si.uom.quantity.ElectricPermittivity;
import si.uom.quantity.ElectricalConductivity;
import si.uom.quantity.ElectricalResistivity;
import si.uom.quantity.Impulse;
import si.uom.quantity.Intensity;
import si.uom.quantity.IonizingRadiation;
import si.uom.quantity.KinematicViscosity;
import si.uom.quantity.Luminance;
import si.uom.quantity.LuminousEfficacy;
import si.uom.quantity.MagneticFieldStrength;
import si.uom.quantity.MagneticPermeability;
import si.uom.quantity.MagnetomotiveForce;
import si.uom.quantity.MassFlowRate;
import si.uom.quantity.Momentum;
import si.uom.quantity.Radiance;
import si.uom.quantity.RadiantIntensity;
import si.uom.quantity.RadiationDoseAbsorbedRate;
import si.uom.quantity.WaveNumber;
import tech.units.indriya.AbstractUnit;
import tech.units.indriya.format.EBNFUnitFormat;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.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 Brochure:
* The International System of Units (SI)
* @see SI:
* Defining constants
* @see MetricPrefix
*
* @noextend This class is not intended to be extended by clients.
*
* @author Jean-Marie Dautelle
* @author Werner Keil
* @version 3.4, Feb 19, 2025
*/
public final class SI extends Units {
/**
* The singleton instance.
*/
private static final SI INSTANCE = new SI();
/**
* Default constructor (prevents this class from being instantiated).
*/
private SI() {
}
/**
* Returns the singleton instance of this class.
*
* @return the metric system instance.
*/
public static SI getInstance() {
return INSTANCE;
}
////////////////////////////////
// SI DERIVED ALTERNATE UNITS //
////////////////////////////////
/**
* The SI unit for magnetomotive force (standard name At
).
*/
public static final AlternateUnit AMPERE_TURN = addUnit(
new AlternateUnit(AMPERE, "At"), MagnetomotiveForce.class);
//////////////////////////////
// SI DERIVED PRODUCT UNITS //
//////////////////////////////
/**
* The SI unit for acceleration quantities (standard name m/s2
).
*/
public static final Unit METRE_PER_SQUARE_SECOND = addUnit(
new ProductUnit(METRE_PER_SECOND.divide(SECOND)), Acceleration.class);
/**
* The SI unit for absement quantities (standard name m.s
).
* @see Wikipedia:
* Absement
*/
public static final Unit METRE_SECOND = addUnit(
new ProductUnit(METRE.multiply(SECOND)), Absement.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 ProductUnit(FARAD.divide(METRE)), ElectricPermittivity.class);
/**
* The SI unit for electrical conductivity, S/m
).
* @see Wikipedia: Electrical resistivity and conductivity
*/
public static final Unit SIEMENS_PER_METRE = addUnit(
new ProductUnit(SIEMENS.divide(METRE)), ElectricalConductivity.class);
/**
* The SI unit for electrical resistivity, Ω⋅m
).
* @see Wikipedia: Electrical resistivity and conductivity
*/
public static final Unit OHM_METRE = addUnit(
new ProductUnit(OHM.multiply(METRE)), ElectricalResistivity.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);
/**
* The SI unit for magnetic field strength quantities (standard name
* A/m"
).
*/
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);
/**
* A kilogram per second (kg/s) is the derived SI unit of mass flow rate.
*
* @see Wikipedia:
* Mass flow rate
*/
public static final Unit KILOGRAM_PER_SECOND = addUnit(
new ProductUnit(KILOGRAM.divide(SECOND)), MassFlowRate.class);
/**
* The newton-second (also newton second; symbol: N⋅s or N s)[1] is the derived SI unit of impulse.
* It is dimensionally equivalent to the momentum unit kilogram-metre per second (kg⋅m/s).
* One newton-second corresponds to a one-newton force applied for one second.
*
* @see Wikipedia: Impulse (physics)
* @see #KILOGRAM_METRE_PER_SECOND
*/
public static final Unit NEWTON_SECOND = addUnit(
new ProductUnit(NEWTON.multiply(SECOND)), Impulse.class);
/**
* A kilogram-metre per second (kg⋅m/s) is the derived SI unit of momentum.
* It is dimensionally equivalent to the newton-second.
* One newton-second corresponds to a one-newton force applied for one second.
*
* @see #NEWTON_SECOND
* @see Wikipedia:
* Momentum
*/
public static final Unit KILOGRAM_METRE_PER_SECOND = addUnit(
new ProductUnit(KILOGRAM.multiply(METRE_PER_SECOND)), Momentum.class);
/**
* A kilogram per square metre (kg/m2) is the derived SI unit of area density.
*
* @see Wikipedia:
* Area density
*/
public static final Unit KILOGRAM_PER_SQUARE_METRE = addUnit(
new ProductUnit(KILOGRAM.divide(SQUARE_METRE)), AreaDensity.class);
/**
* A kilogram per cubic metre (kg/m3) is the derived SI unit of area density.
*
* @see Wikipedia:
* Kilogram per cubic metre
* @see Wikipedia:
* Density
*/
public static final Unit KILOGRAM_PER_CUBIC_METRE = addUnit(
new ProductUnit(KILOGRAM.divide(CUBIC_METRE)), Density.class);
/**
* A gray per second (kg⋅m/s) is the derived SI unit of radiation absorbed dose rate.
*
* @see Wikipedia:
* Absorbed dose
*/
public static final Unit GRAY_PER_SECOND = addUnit(
new ProductUnit(GRAY.divide(SECOND)), RadiationDoseAbsorbedRate.class);
///////////////////////////
// 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 value of one electron.
*/
static final double ELEMENTARY_CHARGE_VALUE = 1.602176462E-19; // (E).
/**
* Holds the numeric value of the Planck constant.
*/
static final double PLANCK_CONSTANT_VALUE = 6.62607015E-34;
/**
* 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), "NA", true); // (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(KELVIN), "J/K").multiply(BOLTZMANN_CONSTANT_VALUE), "kB",
true);
/**
* The Natural Unit of {@link Speed}, the speed of light in vacuum (standard name
* c
).
*
* @see Wikipedia:
* Speed of light
*/
public static final Unit C = addUnit(METRE_PER_SECOND.multiply(299792458), "C",
true);
/**
* The ground state hyperfine structure transition frequency of the caesium-133 atom ΔνCs
is exactly 9192631770 hertz (Hz).
*
* @see Wikipedia:
* Hyperfine Structure Transition - Use in defining the SI second and meter
*/
public static final Unit DELTA_V_CS = addUnit(HERTZ.multiply(9192631770l), "Δν",
true);
/**
* 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 luminous efficacy of monochromatic radiation of frequency 540 ×1012 hertz Kcd
is 683 lm/W.
*/
public static final Unit KCD = addUnit((LUMEN.divide(WATT)).multiply(683).asType(LuminousEfficacy.class),
"KCD", true);
/**
* The Planck constant (denoted ℎ
, 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), "\u210E", true);
////////////////////////////////////////////////////////////////////////////
// Label adjustments for SI
////////////////////////////////////////////////////////////////////////////
static {
// Simple
SimpleUnitFormat.getInstance().alias(FARAD_PER_METRE, "ε");
// EBNF
EBNFUnitFormat.getInstance().alias(FARAD_PER_METRE, "ε");
EBNFUnitFormat.getInstance().label(AMPERE_TURN, "At");
}
/////////////////////
// Collection View //
/////////////////////
@Override
public String getName() {
return "SI";
}
/**
* 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);
EBNFUnitFormat.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 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
.
*/
@SuppressWarnings("unused")
private static > U addUnit(U unit, String name, String label,
Class extends Quantity>> type) {
INSTANCE.quantityToUnit.put(type, unit);
return addUnit(unit, name, label);
}
/**
* 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 to a set and maps it to the specified quantity type.
*
* @param units the set to add to.
* @param unit the unit being added.
* @param name the name of the unit being added.
* @param type the quantity type.
* @return unit
.
*/
private static > U addUnit(U unit, String name, Class extends Quantity>> type) {
Helper.addUnit(INSTANCE.units, unit, name);
INSTANCE.quantityToUnit.put(type, unit);
return unit;
}
/**
* 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;
}
/**
* Adds a new unit with name and symbol.
*
* @param unit the unit being added.
* @param name the string to use as name
* @param symbol the string to use as symbol
* @return unit
.
*/
private static > U addUnit(U unit, String name, String symbol) {
return Helper.addUnit(INSTANCE.units, unit, name, symbol);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy