/*
 * 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.LogConverter;
import javax.measure.converter.RationalConverter;
import javax.measure.quantity.*;

import static javax.measure.unit.SI.*;

/**
 * 

This class contains units that are not part of the International * System of Units, that is, they are outside the SI, but are important * and widely used.

* * @author Jean-Marie Dautelle * @version 4.2, August 26, 2007 */ public final class NonSI extends SystemOfUnits { /** * Holds collection of NonSI units. */ private static HashSet> UNITS = new HashSet>(); /** * Holds the standard gravity constant: 9.80665 m/s² exact. */ private static final int STANDARD_GRAVITY_DIVIDEND = 980665; private static final int STANDARD_GRAVITY_DIVISOR = 100000; /** * Holds the international foot: 0.3048 m exact. */ private static final int INTERNATIONAL_FOOT_DIVIDEND = 3048; private static final int INTERNATIONAL_FOOT_DIViSOR = 10000; /** * Holds the avoirdupois pound: 0.45359237 kg exact */ private static final int AVOIRDUPOIS_POUND_DIVIDEND = 45359237; private static final int AVOIRDUPOIS_POUND_DIVISOR = 100000000; /** * Holds the Avogadro constant. */ private static final double AVOGADRO_CONSTANT = 6.02214199e23; // (1/mol). /** * Holds the electric charge of one electron. */ private static final double ELEMENTARY_CHARGE = 1.602176462e-19; // (C). /** * Default constructor (prevents this class from being instantiated). */ private NonSI() { } /** * Returns the unique instance of this class. * * @return the NonSI instance. */ public static NonSI getInstance() { return INSTANCE; } private static final NonSI INSTANCE = new NonSI(); /////////////////// // Dimensionless // /////////////////// /** * A dimensionless unit equals to 0.01 * (standard name %). */ public static final Unit PERCENT = nonSI(Unit.ONE.divide(100)); /** * A logarithmic unit used to describe a ratio * (standard name dB). */ public static final Unit DECIBEL = nonSI(Unit.ONE .transform(new LogConverter(10).inverse().concatenate( new RationalConverter(1, 10)))); ///////////////////////// // Amount of substance // ///////////////////////// /** * A unit of amount of substance equals to one atom * (standard name atom). */ public static final Unit ATOM = nonSI(MOLE .divide(AVOGADRO_CONSTANT)); //////////// // Length // //////////// /** * A unit of length equal to 0.3048 m * (standard name ft). */ public static final Unit FOOT = nonSI(METRE.times(INTERNATIONAL_FOOT_DIVIDEND).divide(INTERNATIONAL_FOOT_DIViSOR)); /** * A unit of length equal to 1200/3937 m * (standard name foot_survey_us). * See also: foot */ public static final Unit FOOT_SURVEY_US = nonSI(METRE .times(1200).divide(3937)); /** * A unit of length equal to 0.9144 m * (standard name yd). */ public static final Unit YARD = nonSI(FOOT.times(3)); /** * A unit of length equal to 0.0254 m * (standard name in). */ public static final Unit INCH = nonSI(FOOT.divide(12)); /** * A unit of length equal to 1609.344 m * (standard name mi). */ public static final Unit MILE = nonSI(METRE.times(1609344).divide(1000)); /** * A unit of length equal to 1852.0 m * (standard name nmi). */ public static final Unit NAUTICAL_MILE = nonSI(METRE.times(1852)); /** * A unit of length equal to 1E-10 m * (standard name Å). */ public static final Unit ANGSTROM = nonSI(METRE.divide(10000000000L)); /** * A unit of length equal to the average distance from the center of the * Earth to the center of the Sun (standard name ua). */ public static final Unit ASTRONOMICAL_UNIT = nonSI(METRE .times(149597870691.0)); /** * A unit of length equal to the distance that light travels in one year * through a vacuum (standard name ly). */ public static final Unit LIGHT_YEAR = nonSI(METRE.times(9.460528405e15)); /** * A unit of length equal to the distance at which a star would appear to * shift its position by one arcsecond over the course the time * (about 3 months) in which the Earth moves a distance of * {@link #ASTRONOMICAL_UNIT} in the direction perpendicular to the * direction to the star (standard name pc). */ public static final Unit PARSEC = nonSI(METRE.times(30856770e9)); /** * A unit of length equal to 0.013837 {@link #INCH} exactly * (standard name pt). * @see #PIXEL */ public static final Unit POINT = nonSI(INCH.times(13837).divide(1000000)); /** * A unit of length equal to 1/72 {@link #INCH} * (standard name pixel). * It is the American point rounded to an even 1/72 inch. * @see #POINT */ public static final Unit PIXEL = nonSI(INCH.divide(72)); /** * Equivalent {@link #PIXEL} */ public static final Unit COMPUTER_POINT = PIXEL; ////////////// // Duration // ////////////// /** * A unit of duration equal to 60 s * (standard name min). */ public static final Unit MINUTE = nonSI(SI.SECOND.times(60)); /** * A unit of duration equal to 60 {@link #MINUTE} * (standard name h). */ public static final Unit HOUR = nonSI(MINUTE.times(60)); /** * A unit of duration equal to 24 {@link #HOUR} * (standard name d). */ public static final Unit DAY = nonSI(HOUR.times(24)); /** * A unit of duration equal to 7 {@link #DAY} * (standard name week). */ public static final Unit WEEK = nonSI(DAY.times(7)); /** * A unit of duration equal to 365 days, 5 hours, 49 minutes, * and 12 seconds (standard name year). */ public static final Unit YEAR = nonSI(SECOND.times(31556952)); /** * A unit of duration equal to one twelfth of a year * (standard name month). */ public static final Unit MONTH = nonSI(YEAR.divide(12)); /** * A unit of duration equal to the time required for a complete rotation of * the earth in reference to any star or to the vernal equinox at the * meridian, equal to 23 hours, 56 minutes, 4.09 seconds * (standard name day_sidereal). */ public static final Unit DAY_SIDEREAL = nonSI(SECOND.times(86164.09)); /** * A unit of duration equal to one complete revolution of the * earth about the sun, relative to the fixed stars, or 365 days, 6 hours, * 9 minutes, 9.54 seconds (standard name year_sidereal). */ public static final Unit YEAR_SIDEREAL = nonSI(SECOND .times(31558149.54)); /** * A unit of duration equal to 365 {@link #DAY} * (standard name year_calendar). */ public static final Unit YEAR_CALENDAR = nonSI(DAY.times(365)); ////////// // Mass // ////////// /** * A unit of mass equal to 1/12 the mass of the carbon-12 atom * (standard name u). */ public static final Unit ATOMIC_MASS = nonSI(KILOGRAM .times(1e-3 / AVOGADRO_CONSTANT)); /** * A unit of mass equal to the mass of the electron * (standard name me). */ public static final Unit ELECTRON_MASS = nonSI(KILOGRAM .times(9.10938188e-31)); /** * A unit of mass equal to 453.59237 grams (avoirdupois pound, * standard name lb). */ public static final Unit POUND = nonSI(KILOGRAM.times(AVOIRDUPOIS_POUND_DIVIDEND).divide(AVOIRDUPOIS_POUND_DIVISOR)); /** * A unit of mass equal to 1 / 16 {@link #POUND} * (standard name oz). */ public static final Unit OUNCE = nonSI(POUND.divide(16)); /** * A unit of mass equal to 2000 {@link #POUND} (short ton, * standard name ton_us). */ public static final Unit TON_US = nonSI(POUND.times(2000)); /** * A unit of mass equal to 2240 {@link #POUND} (long ton, * standard name ton_uk). */ public static final Unit TON_UK = nonSI(POUND.times(2240)); /** * A unit of mass equal to 1000 kg (metric ton, * standard name t). */ public static final Unit METRIC_TON = nonSI(KILOGRAM.times(1000)); ///////////////////// // Electric charge // ///////////////////// /** * A unit of electric charge equal to the charge on one electron * (standard name e). */ public static final Unit E = nonSI(COULOMB .times(ELEMENTARY_CHARGE)); /** * A unit of electric charge equal to equal to the product of Avogadro's * number (see {@link SI#MOLE}) and the charge (1 e) on a single electron * (standard name Fd). */ public static final Unit FARADAY = nonSI(COULOMB .times(ELEMENTARY_CHARGE * AVOGADRO_CONSTANT)); // e/mol /** * A unit of electric charge which exerts a force of one dyne on an equal * charge at a distance of one centimeter * (standard name Fr). */ public static final Unit FRANKLIN = nonSI(COULOMB .times(3.3356e-10)); ///////////////// // Temperature // ///////////////// /** * A unit of temperature equal to 5/9 °K * (standard name °R). */ public static final Unit RANKINE = nonSI(KELVIN.times(5).divide(9)); /** * A unit of temperature equal to degree Rankine minus * 459.67 °R (standard name °F). * @see #RANKINE */ public static final Unit FAHRENHEIT = nonSI(RANKINE.plus(459.67)); /////////// // Angle // /////////// /** * A unit of angle equal to a full circle or 2π * {@link SI#RADIAN} (standard name rev). */ public static final Unit REVOLUTION = nonSI(RADIAN.times(2.0 * Math.PI)); /** * A unit of angle equal to 1/360 {@link #REVOLUTION} * (standard name °). */ public static final Unit DEGREE_ANGLE = nonSI(REVOLUTION.divide(360)); /** * A unit of angle equal to 1/60 {@link #DEGREE_ANGLE} * (standard name ′). */ public static final Unit MINUTE_ANGLE = nonSI(DEGREE_ANGLE.divide(60)); /** * A unit of angle equal to 1/60 {@link #MINUTE_ANGLE} * (standard name "). */ public static final Unit SECOND_ANGLE = nonSI(MINUTE_ANGLE.divide(60)); /** * A unit of angle equal to 0.01 {@link SI#RADIAN} * (standard name centiradian). */ public static final Unit CENTIRADIAN = nonSI(RADIAN.divide(100)); /** * A unit of angle measure equal to 1/400 {@link #REVOLUTION} * (standard name grade). */ public static final Unit GRADE = nonSI(REVOLUTION.divide(400)); ////////////// // Velocity // ////////////// /** * A unit of velocity expressing the number of international {@link * #MILE miles} per {@link #HOUR hour} (abbreviation mph). */ public static final Unit MILES_PER_HOUR = nonSI(NonSI.MILE.divide(NonSI.HOUR)).asType(Velocity.class); /** * A unit of velocity expressing the number of {@link SI#KILOMETRE} per * {@link #HOUR hour}. */ public static final Unit KILOMETRES_PER_HOUR = nonSI(SI.KILOMETRE.divide(NonSI.HOUR)).asType(Velocity.class); /** * Equivalent to {@link #KILOMETRES_PER_HOUR}. */ public static final Unit KILOMETERS_PER_HOUR = KILOMETRES_PER_HOUR; /** * A unit of velocity expressing the number of {@link #NAUTICAL_MILE * nautical miles} per {@link #HOUR hour} (abbreviation kn). */ public static final Unit KNOT = nonSI(NonSI.NAUTICAL_MILE.divide(NonSI.HOUR)).asType(Velocity.class); /** * A unit of velocity to express the speed of an aircraft relative to * the speed of sound (standard name Mach). */ public static final Unit MACH = nonSI(METRES_PER_SECOND.times(331.6)); /** * A unit of velocity relative to the speed of light * (standard name c). */ public static final Unit C = nonSI(METRES_PER_SECOND.times(299792458)); ////////////////// // Acceleration // ////////////////// /** * A unit of acceleration equal to the gravity at the earth's surface * (standard name grav). */ public static final Unit G = nonSI(METRES_PER_SQUARE_SECOND .times(STANDARD_GRAVITY_DIVIDEND).divide(STANDARD_GRAVITY_DIVISOR)); ////////// // Area // ////////// /** * A unit of area equal to 100 m² * (standard name a). */ public static final Unit ARE = nonSI(SQUARE_METRE.times(100)); /** * A unit of area equal to 100 {@link #ARE} * (standard name ha). */ public static final Unit HECTARE = nonSI(ARE.times(100)); // Exact. ///////////////// // Data Amount // ///////////////// /** * A unit of data amount equal to 8 {@link SI#BIT} * (BinarY TErm, standard name byte). */ public static final Unit BYTE = nonSI(BIT.times(8)); /** * Equivalent {@link #BYTE} */ public static final Unit OCTET = BYTE; ////////////////////// // Electric current // ////////////////////// /** * A unit of electric charge equal to the centimeter-gram-second * electromagnetic unit of magnetomotive force, equal to 10/4 * πampere-turn (standard name Gi). */ public static final Unit GILBERT = nonSI(SI.AMPERE .times(10.0 / (4.0 * Math.PI))); //////////// // Energy // //////////// /** * A unit of energy equal to 1E-7 J * (standard name erg). */ public static final Unit ERG = nonSI(JOULE.divide(10000000)); /** * A unit of energy equal to one electron-volt (standard name * eV, also recognized keV, MeV, GeV). */ public static final Unit ELECTRON_VOLT = nonSI(JOULE .times(ELEMENTARY_CHARGE)); ///////////////// // Illuminance // ///////////////// /** * A unit of illuminance equal to 1E4 Lx * (standard name La). */ public static final Unit LAMBERT = nonSI(LUX.times(10000)); /////////////////// // Magnetic Flux // /////////////////// /** * A unit of magnetic flux equal 1E-8 Wb * (standard name Mx). */ public static final Unit MAXWELL = nonSI(WEBER.divide(100000000)); /////////////////////////// // Magnetic Flux Density // /////////////////////////// /** * A unit of magnetic flux density equal 1000 A/m * (standard name G). */ public static final Unit GAUSS = nonSI(TESLA.divide(10000)); /////////// // Force // /////////// /** * A unit of force equal to 1E-5 N * (standard name dyn). */ public static final Unit DYNE = nonSI(NEWTON.divide(100000)); /** * A unit of force equal to 9.80665 N * (standard name kgf). */ public static final Unit KILOGRAM_FORCE = nonSI(NEWTON .times(STANDARD_GRAVITY_DIVIDEND).divide(STANDARD_GRAVITY_DIVISOR)); /** * A unit of force equal to {@link #POUND}·{@link #G} * (standard name lbf). */ public static final Unit POUND_FORCE = nonSI(NEWTON .times(1L * AVOIRDUPOIS_POUND_DIVIDEND * STANDARD_GRAVITY_DIVIDEND).divide( 1L * AVOIRDUPOIS_POUND_DIVISOR * STANDARD_GRAVITY_DIVISOR)); /////////// // Power // /////////// /** * A unit of power equal to the power required to raise a mass of 75 * kilograms at a velocity of 1 meter per second (metric, * standard name hp). */ public static final Unit HORSEPOWER = nonSI(WATT.times(735.499)); ////////////// // Pressure // ////////////// /** * A unit of pressure equal to the average pressure of the Earth's * atmosphere at sea level (standard name atm). */ public static final Unit ATMOSPHERE = nonSI(PASCAL.times(101325)); /** * A unit of pressure equal to 100 kPa * (standard name bar). */ public static final Unit BAR = nonSI(PASCAL.times(100000)); /** * A unit of pressure equal to the pressure exerted at the Earth's * surface by a column of mercury 1 millimeter high * (standard name mmHg). */ public static final Unit MILLIMETER_OF_MERCURY =nonSI(PASCAL .times(133.322)); /** * A unit of pressure equal to the pressure exerted at the Earth's * surface by a column of mercury 1 inch high * (standard name inHg). */ public static final Unit INCH_OF_MERCURY = nonSI(PASCAL.times(3386.388)); ///////////////////////////// // Radiation dose absorbed // ///////////////////////////// /** * A unit of radiation dose absorbed equal to a dose of 0.01 joule of * energy per kilogram of mass (J/kg) (standard name rd). */ public static final Unit RAD = nonSI(GRAY.divide(100)); /** * A unit of radiation dose effective equal to 0.01 Sv * (standard name rem). */ public static final Unit REM = nonSI(SIEVERT.divide(100)); ////////////////////////// // Radioactive activity // ////////////////////////// /** * A unit of radioctive activity equal to the activity of a gram of radium * (standard name Ci). */ public static final Unit CURIE = nonSI(BECQUEREL .times(37000000000L)); /** * A unit of radioctive activity equal to 1 million radioactive * disintegrations per second (standard name Rd). */ public static final Unit RUTHERFORD = nonSI(SI.BECQUEREL .times(1000000)); ///////////////// // Solid angle // ///////////////// /** * A unit of solid angle equal to 4 π steradians * (standard name sphere). */ public static final Unit SPHERE = nonSI(STERADIAN .times(4.0 * Math.PI)); //////////// // Volume // //////////// /** * A unit of volume equal to one cubic decimeter (default label * L, also recognized µL, mL, cL, dL). */ public static final Unit LITRE = nonSI(CUBIC_METRE.divide(1000)); /** * Equivalent to {@link #LITRE} (American spelling). */ public static final Unit LITER = LITRE; /** * A unit of volume equal to one cubic inch (in³). */ public static final Unit CUBIC_INCH = nonSI( INCH.pow(3).asType(Volume.class)); /** * A unit of volume equal to one US gallon, Liquid Unit. The U.S. liquid * gallon is based on the Queen Anne or Wine gallon occupying 231 cubic * inches (standard name gal). */ public static final Unit GALLON_LIQUID_US = nonSI(CUBIC_INCH.times(231)); /** * A unit of volume equal to 1 / 128 {@link #GALLON_LIQUID_US} * (standard name oz_fl). */ public static final Unit OUNCE_LIQUID_US = nonSI(GALLON_LIQUID_US .divide(128)); /** * A unit of volume equal to one US dry gallon. * (standard name gallon_dry_us). */ public static final Unit GALLON_DRY_US = nonSI(CUBIC_INCH.times(2688025).divide(10000)); /** * A unit of volume equal to 4.546 09 {@link #LITRE} * (standard name gal_uk). */ public static final Unit GALLON_UK = nonSI(LITRE.times(454609).divide(100000)); /** * A unit of volume equal to 1 / 160 {@link #GALLON_UK} * (standard name oz_fl_uk). */ public static final Unit OUNCE_LIQUID_UK = nonSI(GALLON_UK.divide(160)); /////////////// // Viscosity // /////////////// /** * A unit of dynamic viscosity equal to 1 g/(cm·s) * (cgs unit). */ @SuppressWarnings("unchecked") public static final Unit POISE = nonSI((Unit) GRAM.divide(CENTI(METRE).times(SECOND))); /** * A unit of kinematic viscosity equal to 1 cm²/s * (cgs unit). */ @SuppressWarnings("unchecked") public static final Unit STOKE = nonSI((Unit) CENTI(METRE).pow(2).divide(SECOND)); //////////// // Others // //////////// /** * A unit used to measure the ionizing ability of radiation * (standard name Roentgen). */ public static final Unit ROENTGEN = nonSI(COULOMB.divide(KILOGRAM).times(2.58e-4)); ///////////////////// // Collection View // ///////////////////// /** * Returns a read only view over the units defined in this class. * * @return the collection of NonSI 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 nonSI(U unit) { UNITS.add(unit); return unit; } }

Ads help maintain this website.