/*
 * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
 * Copyright (C) 2006 - JScience (http://jscience.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javax.measure.unit;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.measure.converter.MultiplyConverter;
import javax.measure.converter.RationalConverter;
import javax.measure.quantity.*;

/**
 * 

This class contains SI (Système International d'Unités) base units, * and derived units.

* *

It also defines the 20 SI prefixes used to form decimal multiples and * submultiples of SI units. For example:[code] * import static org.jscience.physics.units.SI.*; // Static import. * ... * Unit HECTO_PASCAL = HECTO(PASCAL); * Unit KILO_METER = KILO(METER); * [/code]

* * @author Jean-Marie Dautelle * @version 4.2, August 26, 2006 * @see Wikipedia: SI * @see Wikipedia: SI prefix */ public final class SI extends SystemOfUnits { /** * Holds collection of SI units. */ private static HashSet> UNITS = new HashSet>(); /** * Default constructor (prevents this class from being instantiated). */ private SI() { } /** * Returns the unique instance of this class. * * @return the SI instance. */ public static SI getInstance() { return INSTANCE; } private static final SI INSTANCE = new SI(); //////////////// // BASE UNITS // //////////////// /** * The base unit for electric current quantities (A). * The Ampere is that constant current which, if maintained in two straight * parallel conductors of infinite length, of negligible circular * cross-section, and placed 1 metre apart in vacuum, would produce between * these conductors a force equal to 2 × 10-7 newton per metre of length. * It is named after the French physicist Andre Ampere (1775-1836). */ public static final BaseUnit AMPERE = si(new BaseUnit( "A")); /** * The base unit for luminous intensity quantities (cd). * The candela is the luminous intensity, in a given direction, * of a source that emits monochromatic radiation of frequency * 540 × 1012 hertz and that has a radiant intensity in that * direction of 1/683 watt per steradian * @see * Wikipedia: Candela */ public static final BaseUnit CANDELA = si(new BaseUnit( "cd")); /** * The base unit for thermodynamic temperature quantities (K). * The kelvin is the 1/273.16th of the thermodynamic temperature of the * triple point of water. It is named after the Scottish mathematician and * physicist William Thomson 1st Lord Kelvin (1824-1907) */ public static final BaseUnit KELVIN = si(new BaseUnit( "K")); /** * The base unit for mass quantities (kg). * It is the only SI unit with a prefix as part of its name and symbol. * The kilogram is equal to the mass of an international prototype in the * form of a platinum-iridium cylinder kept at Sevres in France. * @see #GRAM */ public static final BaseUnit KILOGRAM = si(new BaseUnit("kg")); /** * The base unit for length quantities (m). * One meter was redefined in 1983 as the distance traveled by light in * a vacuum in 1/299,792,458 of a second. */ public static final BaseUnit METRE = si(new BaseUnit("m")); /** * Equivalent to {@link #METRE} (American spelling). */ public static final Unit METER = METRE; /** * The base unit for amount of substance quantities (mol). * The mole is the amount of substance of a system which contains as many * elementary entities as there are atoms in 0.012 kilogram of carbon 12. */ public static final BaseUnit MOLE = si(new BaseUnit( "mol")); /** * The base unit for duration quantities (s). * It is defined as the duration of 9,192,631,770 cycles of radiation * corresponding to the transition between two hyperfine levels of * the ground state of cesium (1967 Standard). */ public static final BaseUnit SECOND = si(new BaseUnit( "s")); //////////////////////////////// // SI DERIVED ALTERNATE UNITS // //////////////////////////////// /** * The derived unit for mass quantities (g). * The base unit for mass quantity is {@link #KILOGRAM}. */ public static final Unit GRAM = KILOGRAM.divide(1000); /** * The unit for plane angle quantities (rad). * One radian is the angle between two radii of a circle such that the * length of the arc between them is equal to the radius. */ public static final AlternateUnit RADIAN = si(new AlternateUnit( "rad", Unit.ONE)); /** * The unit for solid angle quantities (sr). * One steradian is the solid angle subtended at the center of a sphere by * an area on the surface of the sphere that is equal to the radius squared. * The total solid angle of a sphere is 4*Pi steradians. */ public static final AlternateUnit STERADIAN = si(new AlternateUnit( "sr", Unit.ONE)); /** * The unit for binary information (bit). */ public static final AlternateUnit BIT = si(new AlternateUnit( "bit", Unit.ONE)); /** * The derived unit for frequency (Hz). * A unit of frequency equal to one cycle per second. * After Heinrich Rudolf Hertz (1857-1894), German physicist who was the * first to produce radio waves artificially. */ public static final AlternateUnit HERTZ = si(new AlternateUnit( "Hz", Unit.ONE.divide(SECOND))); /** * The derived unit for force (N). * One newton is the force required to give a mass of 1 kilogram an Force * of 1 metre per second per second. It is named after the English * mathematician and physicist Sir Isaac Newton (1642-1727). */ public static final AlternateUnit NEWTON = si(new AlternateUnit( "N", METRE.times(KILOGRAM).divide(SECOND.pow(2)))); /** * The derived unit for pressure, stress (Pa). * One pascal is equal to one newton per square meter. It is named after * the French philosopher and mathematician Blaise Pascal (1623-1662). */ public static final AlternateUnit PASCAL = si(new AlternateUnit( "Pa", NEWTON.divide(METRE.pow(2)))); /** * The derived unit for energy, work, quantity of heat (J). * One joule is the amount of work done when an applied force of 1 newton * moves through a distance of 1 metre in the direction of the force. * It is named after the English physicist James Prescott Joule (1818-1889). */ public static final AlternateUnit JOULE = si(new AlternateUnit( "J", NEWTON.times(METRE))); /** * The derived unit for power, radiant, flux (W). * One watt is equal to one joule per second. It is named after the British * scientist James Watt (1736-1819). */ public static final AlternateUnit WATT = si(new AlternateUnit( "W", JOULE.divide(SECOND))); /** * The derived unit for electric charge, quantity of electricity * (C). * One Coulomb is equal to the quantity of charge transferred in one second * by a steady current of one ampere. It is named after the French physicist * Charles Augustin de Coulomb (1736-1806). */ public static final AlternateUnit COULOMB = si(new AlternateUnit( "C", SECOND.times(AMPERE))); /** * The derived unit for electric potential difference, electromotive force * (V). * One Volt is equal to the difference of electric potential between two * points on a conducting wire carrying a constant current of one ampere * when the power dissipated between the points is one watt. It is named * after the Italian physicist Count Alessandro Volta (1745-1827). */ public static final AlternateUnit VOLT = si(new AlternateUnit( "V", WATT.divide(AMPERE))); /** * The derived unit for capacitance (F). * One Farad is equal to the capacitance of a capacitor having an equal * and opposite charge of 1 coulomb on each plate and a potential difference * of 1 volt between the plates. It is named after the British physicist * and chemist Michael Faraday (1791-1867). */ public static final AlternateUnit FARAD = si(new AlternateUnit( "F", COULOMB.divide(VOLT))); /** * The derived unit for electric resistance (Ω or * Ohm). * One Ohm is equal to the resistance of a conductor in which a current of * one ampere is produced by a potential of one volt across its terminals. * It is named after the German physicist Georg Simon Ohm (1789-1854). */ public static final AlternateUnit OHM = si(new AlternateUnit( "Ω", VOLT.divide(AMPERE))); /** * The derived unit for electric conductance (S). * One Siemens is equal to one ampere per volt. It is named after * the German engineer Ernst Werner von Siemens (1816-1892). */ public static final AlternateUnit SIEMENS = si(new AlternateUnit( "S", AMPERE.divide(VOLT))); /** * The derived unit for magnetic flux (Wb). * One Weber is equal to the magnetic flux that in linking a circuit of one * turn produces in it an electromotive force of one volt as it is uniformly * reduced to zero within one second. It is named after the German physicist * Wilhelm Eduard Weber (1804-1891). */ public static final AlternateUnit WEBER = si(new AlternateUnit( "Wb", VOLT.times(SECOND))); /** * The derived unit for magnetic flux density (T). * One Tesla is equal equal to one weber per square meter. It is named * after the Serbian-born American electrical engineer and physicist * Nikola Tesla (1856-1943). */ public static final AlternateUnit TESLA = si(new AlternateUnit( "T", WEBER.divide(METRE.pow(2)))); /** * The derived unit for inductance (H). * One Henry is equal to the inductance for which an induced electromotive * force of one volt is produced when the current is varied at the rate of * one ampere per second. It is named after the American physicist * Joseph Henry (1791-1878). */ public static final AlternateUnit HENRY = si(new AlternateUnit( "H", WEBER.divide(AMPERE))); /** * The derived unit for Celsius temperature (℃). * This is a unit of temperature such as the freezing point of water * (at one atmosphere of pressure) is 0 ℃, while the boiling point is * 100 ℃. */ public static final Unit CELSIUS = si(KELVIN.plus(273.15)); /** * The derived unit for luminous flux (lm). * One Lumen is equal to the amount of light given out through a solid angle * by a source of one candela intensity radiating equally in all directions. */ public static final AlternateUnit LUMEN = si(new AlternateUnit( "lm", CANDELA.times(STERADIAN))); /** * The derived unit for illuminance (lx). * One Lux is equal to one lumen per square meter. */ public static final AlternateUnit LUX = si(new AlternateUnit( "lx", LUMEN.divide(METRE.pow(2)))); /** * The derived unit for activity of a radionuclide (Bq). * One becquerel is the radiation caused by one disintegration per second. * It is named after the French physicist, Antoine-Henri Becquerel * (1852-1908). */ public static final AlternateUnit BECQUEREL = si(new AlternateUnit( "Bq", Unit.ONE.divide(SECOND))); /** * The derived unit for absorbed dose, specific energy (imparted), kerma * (Gy). * One gray is equal to the dose of one joule of energy absorbed per one * kilogram of matter. It is named after the British physician * L. H. Gray (1905-1965). */ public static final AlternateUnit GRAY = si(new AlternateUnit( "Gy", JOULE.divide(KILOGRAM))); /** * The derived unit for dose equivalent (Sv). * One Sievert is equal is equal to the actual dose, in grays, multiplied * by a "quality factor" which is larger for more dangerous forms of * radiation. It is named after the Swedish physicist Rolf Sievert * (1898-1966). */ public static final AlternateUnit SIEVERT = si(new AlternateUnit( "Sv", JOULE.divide(KILOGRAM))); /** * The derived unit for catalytic activity (kat). */ public static final AlternateUnit KATAL = si(new AlternateUnit( "kat", MOLE.divide(SECOND))); ////////////////////////////// // SI DERIVED PRODUCT UNITS // ////////////////////////////// /** * The metric unit for velocity quantities (m/s). */ public static final Unit METRES_PER_SECOND = si(new ProductUnit( METRE.divide(SECOND))); /** * Equivalent to {@link #METRES_PER_SECOND}. */ public static final Unit METERS_PER_SECOND = METRES_PER_SECOND; /** * The metric unit for acceleration quantities (m/s²). */ public static final Unit METRES_PER_SQUARE_SECOND = si(new ProductUnit( METRES_PER_SECOND.divide(SECOND))); /** * Equivalent to {@link #METRES_PER_SQUARE_SECOND}. */ public static final Unit METERS_PER_SQUARE_SECOND = METRES_PER_SQUARE_SECOND; /** * The metric unit for area quantities (m²). */ public static final Unit SQUARE_METRE = si(new ProductUnit( METRE.times(METRE))); /** * The metric unit for volume quantities (m³). */ public static final Unit CUBIC_METRE = si(new ProductUnit( SQUARE_METRE.times(METRE))); /** * Equivalent to KILO(METRE). */ public static final Unit KILOMETRE = METER.times(1000); /** * Equivalent to {@link #KILOMETRE}. */ public static final Unit KILOMETER = KILOMETRE; /** * Equivalent to CENTI(METRE). */ public static final Unit CENTIMETRE = METRE.divide(100); /** * Equivalent to {@link #CENTIMETRE}. */ public static final Unit CENTIMETER = CENTIMETRE; /** * Equivalent to MILLI(METRE). */ public static final Unit MILLIMETRE = METRE.divide(1000); /** * Equivalent to {@link #MILLIMETRE}. */ public static final Unit MILLIMETER = MILLIMETRE; ///////////////// // SI PREFIXES // ///////////////// /** * Returns the specified unit multiplied by the factor * 1024 * * @param unit any unit. * @return unit.multiply(1e24). */ public static Unit YOTTA(Unit unit) { return unit.transform(E24); } /** * Returns the specified unit multiplied by the factor * 1021 * * @param unit any unit. * @return unit.multiply(1e21). */ public static Unit ZETTA(Unit unit) { return unit.transform(E21); } /** * Returns the specified unit multiplied by the factor * 1018 * * @param unit any unit. * @return unit.multiply(1e18). */ public static Unit EXA(Unit unit) { return unit.transform(E18); } /** * Returns the specified unit multiplied by the factor * 1015 * * @param unit any unit. * @return unit.multiply(1e15). */ public static Unit PETA(Unit unit) { return unit.transform(E15); } /** * Returns the specified unit multiplied by the factor * 1012 * * @param unit any unit. * @return unit.multiply(1e12). */ public static Unit TERA(Unit unit) { return unit.transform(E12); } /** * Returns the specified unit multiplied by the factor * 109 * * @param unit any unit. * @return unit.multiply(1e9). */ public static Unit GIGA(Unit unit) { return unit.transform(E9); } /** * Returns the specified unit multiplied by the factor * 106 * * @param unit any unit. * @return unit.multiply(1e6). */ public static Unit MEGA(Unit unit) { return unit.transform(E6); } /** * Returns the specified unit multiplied by the factor * 103 * * @param unit any unit. * @return unit.multiply(1e3). */ public static Unit KILO(Unit unit) { return unit.transform(E3); } /** * Returns the specified unit multiplied by the factor * 102 * * @param unit any unit. * @return unit.multiply(1e2). */ public static Unit HECTO(Unit unit) { return unit.transform(E2); } /** * Returns the specified unit multiplied by the factor * 101 * * @param unit any unit. * @return unit.multiply(1e1). */ public static Unit DEKA(Unit unit) { return unit.transform(E1); } /** * Returns the specified unit multiplied by the factor * 10-1 * * @param unit any unit. * @return unit.multiply(1e-1). */ public static Unit DECI(Unit unit) { return unit.transform(Em1); } /** * Returns the specified unit multiplied by the factor * 10-2 * * @param unit any unit. * @return unit.multiply(1e-2). */ public static Unit CENTI(Unit unit) { return unit.transform(Em2); } /** * Returns the specified unit multiplied by the factor * 10-3 * * @param unit any unit. * @return unit.multiply(1e-3). */ public static Unit MILLI(Unit unit) { return unit.transform(Em3); } /** * Returns the specified unit multiplied by the factor * 10-6 * * @param unit any unit. * @return unit.multiply(1e-6). */ public static Unit MICRO(Unit unit) { return unit.transform(Em6); } /** * Returns the specified unit multiplied by the factor * 10-9 * * @param unit any unit. * @return unit.multiply(1e-9). */ public static Unit NANO(Unit unit) { return unit.transform(Em9); } /** * Returns the specified unit multiplied by the factor * 10-12 * * @param unit any unit. * @return unit.multiply(1e-12). */ public static Unit PICO(Unit unit) { return unit.transform(Em12); } /** * Returns the specified unit multiplied by the factor * 10-15 * * @param unit any unit. * @return unit.multiply(1e-15). */ public static Unit FEMTO(Unit unit) { return unit.transform(Em15); } /** * Returns the specified unit multiplied by the factor * 10-18 * * @param unit any unit. * @return unit.multiply(1e-18). */ public static Unit ATTO(Unit unit) { return unit.transform(Em18); } /** * Returns the specified unit multiplied by the factor * 10-21 * * @param unit any unit. * @return unit.multiply(1e-21). */ public static Unit ZEPTO(Unit unit) { return unit.transform(Em21); } /** * Returns the specified unit multiplied by the factor * 10-24 * * @param unit any unit. * @return unit.multiply(1e-24). */ public static Unit YOCTO(Unit unit) { return unit.transform(Em24); } ///////////////////// // Collection View // ///////////////////// /** * Returns a read only view over theunits defined in this class. * * @return the collection of SI units. */ public Set> getUnits() { return Collections.unmodifiableSet(UNITS); } /** * Adds a new unit to the collection. * * @param unit the unit being added. * @return unit. */ private static > U si(U unit) { UNITS.add(unit); return unit; } // Holds prefix converters (optimization). static final MultiplyConverter E24 = new MultiplyConverter(1E24); static final MultiplyConverter E21 = new MultiplyConverter(1E21); static final RationalConverter E18 = new RationalConverter( 1000000000000000000L, 1); static final RationalConverter E15 = new RationalConverter( 1000000000000000L, 1); static final RationalConverter E12 = new RationalConverter(1000000000000L, 1); static final RationalConverter E9 = new RationalConverter(1000000000L, 1); static final RationalConverter E6 = new RationalConverter(1000000L, 1); static final RationalConverter E3 = new RationalConverter(1000L, 1); static final RationalConverter E2 = new RationalConverter(100L, 1); static final RationalConverter E1 = new RationalConverter(10L, 1); static final RationalConverter Em1 = new RationalConverter(1, 10L); static final RationalConverter Em2 = new RationalConverter(1, 100L); static final RationalConverter Em3 = new RationalConverter(1, 1000L); static final RationalConverter Em6 = new RationalConverter(1, 1000000L); static final RationalConverter Em9 = new RationalConverter(1, 1000000000L); static final RationalConverter Em12 = new RationalConverter(1, 1000000000000L); static final RationalConverter Em15 = new RationalConverter(1, 1000000000000000L); static final RationalConverter Em18 = new RationalConverter(1, 1000000000000000000L); static final MultiplyConverter Em21 = new MultiplyConverter(1E-21); static final MultiplyConverter Em24 = new MultiplyConverter(1E-24); /** * @deprecated replaced by {@link #METRES_PER_SECOND}. */ public static final Unit METRE_PER_SECOND = METRES_PER_SECOND; /** * @deprecated replaced by {@link #METRES_PER_SQUARE_SECOND}. */ public static final Unit METRE_PER_SQUARE_SECOND = METRES_PER_SQUARE_SECOND; }

Ads help maintain this website.