All Downloads are FREE. Search and download functionalities are using the official Maven repository.

si.uom.SI Maven / Gradle / Ivy

/*
 * International System of Units (SI)
 * Copyright (c) 2005-2018, 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 javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.Acceleration;
import javax.measure.quantity.Angle;
import javax.measure.quantity.Area;
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.2, May 20, 2018 */ 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); /** * Alias {@link #METRE_PER_SQUARE_SECOND} * * @deprecated use METRE_PER_SQUARE_SECOND */ public static final Unit METRES_PER_SQUARE_SECOND = METRE_PER_SQUARE_SECOND; /** * 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); /** * Alias for {@link #SQUARE_METRE_PER_SECOND} * * @deprecated use SQUARE_METRE_PER_SECOND */ public static final Unit SQUARE_METRES_PER_SECOND = SQUARE_METRE_PER_SECOND; /** * 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)))); /** * An angle unit accepted for use with SI units (standard name * ha). */ public static final Unit HECTARE = new TransformedUnit(SQUARE_METRE, new RationalConverter(10000, 1)); ///////////////////// // 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. */ @SuppressWarnings("unused") 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. * * @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> 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> 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> type) { INSTANCE.units.add(unit); INSTANCE.quantityToUnit.put(type, unit); return unit; } }