001/*
002 * Units of Measurement Systems
003 * Copyright (c) 2005-2017, Jean-Marie Dautelle, Werner Keil and others.
004 *
005 * All rights reserved.
006 *
007 * Redistribution and use in source and binary forms, with or without modification,
008 * are permitted provided that the following conditions are met:
009 *
010 * 1. Redistributions of source code must retain the above copyright notice,
011 *    this list of conditions and the following disclaimer.
012 *
013 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
014 *    and the following disclaimer in the documentation and/or other materials provided with the distribution.
015 *
016 * 3. Neither the name of JSR-363, Units of Measurement nor the names of their contributors may be used to
017 *    endorse or promote products derived from this software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package systems.uom.unicode;
031
032import static tec.units.ri.unit.MetricPrefix.*;
033import static tec.units.ri.unit.Units.CUBIC_METRE;
034import static tec.units.ri.unit.Units.METRE;
035import static tec.units.ri.unit.Units.SQUARE_METRE;
036import static tec.units.ri.AbstractUnit.ONE;
037
038import systems.uom.quantity.Concentration;
039import systems.uom.quantity.Consumption;
040import systems.uom.quantity.Information;
041import systems.uom.quantity.InformationRate;
042import tec.units.ri.*;
043import tec.units.ri.format.SimpleUnitFormat;
044import tec.units.ri.function.PiMultiplierConverter;
045import tec.units.ri.function.RationalConverter;
046import tec.units.ri.unit.AlternateUnit;
047import tec.units.ri.unit.ProductUnit;
048import tec.units.ri.unit.TransformedUnit;
049import tec.units.ri.unit.Units;
050
051import javax.measure.Quantity;
052import javax.measure.Unit;
053import javax.measure.quantity.*;
054
055/**
056 * <p>
057 * This class contains {@linkplain SI} and Non-SI units as defined in the
058 * <a href="http//cldr.unicode.org/">Unicode CLDR Project</a>.
059 * </p>
060 *
061 * <p>
062 * Compatibility with {@linkplain SI} units has been given priority over strict
063 * adherence to the standard. We have attempted to note every place where the
064 * definitions in this class deviate from the CLDR standard, but such notes are
065 * likely to be incomplete.
066 * </p>
067 * 
068 * @noextend This class is not intended to be extended by clients.
069 *
070 * @author <a href="mailto:units@catmedia.us">Werner Keil</a>
071 * @see <a href="http://cldr.unicode.org">Unicode CLDR</a>
072 * @version 0.7, $Date: 2017-06-18 $
073 */
074public final class CLDR extends AbstractSystemOfUnits {
075
076    /**
077     * The singleton instance.
078     */
079    private static final CLDR INSTANCE = new CLDR();
080
081    /**
082     * Default constructor (prevents this class from being instantiated).
083     */
084    private CLDR() {
085    }
086
087    /**
088     * Returns the singleton instance of this class.
089     *
090     * @return the CLDR system instance.
091     */
092    public static CLDR getInstance() {
093        return INSTANCE;
094    }
095
096    ////////////
097    // Length //
098    ////////////
099    /**
100     * US name for {@link Units#METRE}. Constant for unit of length: meter
101     * 
102     * @stable ICU 53.
103     */
104    public static final Unit<Length> METER = addUnit(METRE);
105
106    /**
107     * Constant for unit of length: millimeter<br>
108     * This is a <b>convenience method</b> for <code>MILLI(METER)</code>.
109     * 
110     * @stable ICU 53.
111     */
112    public static final Unit<Length> MILLIMETER = MILLI(METER);
113
114    /**
115     * Constant for unit of length: centimeter<br>
116     * This is a <b>convenience method</b> for <code>CENTI(METER)</code>.
117     * 
118     * @stable ICU 53.
119     */
120    public static final Unit<Length> CENTIMETER = CENTI(METER);
121
122    /**
123     * Constant for unit of length: kilometer<br>
124     * This is a <b>convenience method</b> for <code>KILO(METER)</code>.
125     * 
126     * @stable ICU 53
127     */
128    public static final Unit<Length> KILOMETER = KILO(METRE);
129
130    /**
131     * A unit of length equal to <code>0.3048 m</code> (standard name
132     * <code>ft</code>).
133     */
134    public static final Unit<Length> FOOT = addUnit(METER.multiply(3048).divide(10000));
135
136    /**
137     * Constant for unit of length: furlong<br>
138     * A unit of length equal to <code>201.168 m</code> (standard name
139     * <code>fur</code>).
140     * 
141     * @see <a href="https://en.wikipedia.org/wiki/Furlong">Wikipedia:
142     *      Furlong</a>
143     * @stable ICU 54.
144     */
145    public static final Unit<Length> FURLONG = addUnit(FOOT.multiply(660));
146
147    /**
148     * A unit of length equal to <code>0.9144 m</code> (standard name
149     * <code>yd</code>).
150     */
151    public static final Unit<Length> YARD = addUnit(FOOT.multiply(3));
152
153    /**
154     * A unit of length equal to <code>0.0254 m</code> (standard name
155     * <code>in</code>).
156     */
157    public static final Unit<Length> INCH = addUnit(FOOT.divide(12));
158
159    /**
160     * Constant for unit of length: mile<br>
161     * A unit of length equal to <code>1609.344 m</code> (standard name
162     * <code>mi</code>).
163     * 
164     * @stable ICU 53
165     */
166    public static final Unit<Length> MILE = addUnit(METER.multiply(1609344).divide(1000));
167
168    /**
169     * A unit of length equal to the average distance from the center of the
170     * Earth to the center of the Sun (standard name <code>ua</code>).
171     */
172    public static final Unit<Length> ASTRONOMICAL_UNIT = addUnit(METRE.multiply(149597870691.0));
173
174    /**
175     * Constant for unit of length: fathom<br>
176     * A unit of length equal to <code>1.8288 m</code> (standard name
177     * <code>fm</code>).
178     * 
179     * @stable ICU 53.
180     */
181    public static final Unit<Length> FATHOM = addUnit(FOOT.multiply(6));
182
183    /**
184     * Constant for unit of length: mile-scandinavian
185     * 
186     * @draft ICU 56
187     * @provisional This API might change or be removed in a future release.
188     * @see <a href="https://en.wikipedia.org/wiki/Scandinavian_mile">Wikipedia:
189     *      Scandinavian mile</a>
190     */
191    public static final Unit<Length> MILE_SCANDINAVIAN = addUnit(KILOMETER.multiply(10));
192
193    /**
194     * Constant for unit of duration: second
195     * @stable ICU 4.0
196     */
197    public static final Unit<Time> SECOND = addUnit(Units.SECOND);
198
199    /**
200     * Constant for unit of duration: week<br>
201     * A unit of duration equal to 7 {@link #DAY} (standard name <code>week</code>).
202     * @stable ICU 4.0
203     */
204    public static final Unit<Time> WEEK = addUnit(Units.WEEK);
205    
206    /**
207     * Constant for unit of angle: radian
208     * 
209     * @stable ICU 54
210     */
211    public static final Unit<Angle> RADIAN = addUnit(Units.RADIAN);
212
213    /**
214     * Constant for unit of angle: revolution<br>
215     * A unit of angle equal to a full circle or <code>2<i>&pi;</i>
216     * * {@link #RADIAN}</code> (standard name <code>rev</code>).
217     * 
218     * @draft ICU 56
219     * @provisional This API might change or be removed in a future release.
220     */
221    public static final Unit<Angle> REVOLUTION_ANGLE = addUnit(RADIAN.multiply(2).multiply(Math.PI).asType(Angle.class),
222            "rev", true);
223
224    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
225    public static final Unit<Temperature> KELVIN = addUnit(Units.KELVIN);
226
227    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
228    private static final Unit<LuminousIntensity> CANDELA = addUnit(Units.CANDELA);
229
230    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
231    public static final Unit<Dimensionless> PI = addUnit(ONE.transform(new PiMultiplierConverter()));
232    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
233    public static final Unit<Dimensionless> PERCENT = addUnit(ONE.divide(100), "Percent", "%");
234
235    ////////////////////
236    // SI UNITS: CLDR //
237    ////////////////////
238    /**
239     * We deviate slightly from the standard here, to maintain compatibility
240     * with the existing SI units. In CLDR, the mole is no longer a base unit,
241     * but is defined as <code>Unit.ONE.multiply(6.0221367E23)</code>.
242     */
243    private static final Unit<AmountOfSubstance> MOLE = addUnit(Units.MOLE);
244    /**
245     * We deviate slightly from the standard here, to maintain compatibility
246     * with the existing SI units. In CLDR, the steradian is defined as
247     * <code>RADIAN.pow(2)</code>.
248     */
249    public static final Unit<SolidAngle> STERADIAN = addUnit(Units.STERADIAN);
250
251    public static final Unit<Frequency> HERTZ = addUnit(Units.HERTZ);
252    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
253    public static final Unit<Force> NEWTON = addUnit(Units.NEWTON);
254    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
255    public static final Unit<Pressure> PASCAL = addUnit(Units.PASCAL);
256
257    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
258    // private static final Unit<Pressure> METER_OF_WATER_COLUMN =
259    // KILO(PASCAL).multiply(980665).divide(100000);
260    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
261    private static final Unit<Pressure> METER_OF_MERCURY_COLUMN = KILO(PASCAL).multiply(1333220).divide(10000);
262    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
263    // private static final Unit<Pressure> INCH_OF_WATER_COLUMN =
264    // new
265    // ProductUnit<Pressure>(METER_OF_WATER_COLUMN.multiply(INCH).divide(METER));
266    /**
267     * Constant for unit of pressure: inch-hg
268     * 
269     * @stable ICU 53
270     */
271    public static final Unit<Pressure> INCH_HG = addUnit(
272            new ProductUnit<Pressure>(METER_OF_MERCURY_COLUMN.multiply(INCH).divide(METER)));
273
274    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
275    public static final Unit<Energy> JOULE = addUnit(Units.JOULE);
276    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
277    public static final Unit<Power> WATT = addUnit(Units.WATT);
278    /**
279     * We deviate slightly from the standard here, to maintain compatability
280     * with the existing SI units. In CLDR, the ampere is defined as
281     * <code>COULOMB.divide(SECOND)</code>.
282     */
283    public static final Unit<ElectricCurrent> AMPERE = addUnit(Units.AMPERE);
284
285    /**
286     * We deviate slightly from the standard here, to maintain compatibility
287     * with the existing SI units. In CLDR, the volt is defined as
288     * <code>JOULE.divide(COULOMB)</code>.
289     */
290    public static final Unit<ElectricPotential> VOLT = addUnit(Units.VOLT);
291
292    /**
293     * Constant for unit of electric: ohm
294     * 
295     * @stable ICU 54
296     */
297    public static final Unit<ElectricResistance> OHM = addUnit(Units.OHM);
298    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
299    public static final Unit<Temperature> CELSIUS = addUnit(Units.CELSIUS);
300    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
301    public static final Unit<ElectricInductance> HENRY = addUnit(Units.HENRY);
302
303    /**
304     * Constant for unit of light: lux
305     * 
306     * @stable ICU 54
307     */
308    public static final Unit<Illuminance> LUX = addUnit(Units.LUX);
309
310    /////////////////////////////////////////////////////////////////
311    // Units outside the SI that are accepted for use with the SI. //
312    /////////////////////////////////////////////////////////////////
313
314    /**
315     * An angle unit accepted for use with SI units (standard name
316     * <code>deg/code>).
317     */
318    static final Unit<Angle> DEGREE_ANGLE = new TransformedUnit<Angle>(RADIAN,
319            new PiMultiplierConverter().concatenate(new RationalConverter(1, 180)));
320
321    /**
322     * An angle unit accepted for use with SI units (standard name
323     * <code>'/code>).
324     */
325    static final Unit<Angle> MINUTE_ANGLE = new TransformedUnit<Angle>(RADIAN,
326            new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60)));
327
328    /**
329     * An angle unit accepted for use with SI units (standard name
330     * <code>''</code>).
331     */
332    static final Unit<Angle> SECOND_ANGLE = new TransformedUnit<Angle>(RADIAN,
333            new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60 * 60)));
334
335    /**
336     * We deviate slightly from the standard here, to maintain compatibility
337     * with the existing NonSI units. In CLDR, the degree is defined as
338     * <code>PI.multiply(RADIAN.divide(180))</code>.
339     */
340    public static final Unit<Angle> DEGREE = addUnit(DEGREE_ANGLE);
341
342    /**
343     * As per CLDR standard.
344     */
345    public static final Unit<Angle> ARC_MINUTE = addUnit(MINUTE_ANGLE);
346
347    public static final Unit<Angle> ARC_SECOND = addUnit(SECOND_ANGLE);
348
349    //////////
350    // Area //
351    //////////
352    /**
353     * Constant for unit of area: square-foot<br>
354     * A unit of area (standard name <code>sft</code> ).
355     * @stable ICU 53
356     */
357    public static final Unit<Area> SQUARE_FOOT = addUnit(new ProductUnit<Area>((AbstractUnit<?>) FOOT.multiply(FOOT)));
358
359    /**
360     * A unit of area equal to <code>100 m²</code> (standard name <code>a</code>
361     * ).
362     */
363    private static final Unit<Area> ARE = SQUARE_METRE.multiply(100);
364
365    /**
366     * A unit of area equal to <code>100 {@link #ARE}</code> (standard name
367     * <code>ha</code>).
368     * 
369     * @stable ICU 53.
370     */
371    public static final Unit<Area> HECTARE = addUnit(ARE.multiply(100)); // Exact.
372
373    /**
374     * The acre is a unit of area used in the imperial and U.S. customary
375     * systems. It is equivalent to <code>43,560 square feet</code>. An acre is
376     * about 40% of a <code>HECTARE</code> – slightly smaller than an American
377     * football field. (standard name <code>ac</code> ).
378     * 
379     * @see <a href="http://en.wikipedia.org/wiki/Acre">Wikipedia: Acre</a>
380     */
381    public static final Unit<Area> ACRE = addUnit(SQUARE_FOOT.multiply(43560));
382
383    /**
384     * Constant for unit of area: square-inch
385     * 
386     * @stable ICU 54
387     */
388    public static final Unit<Area> SQUARE_INCH = addUnit(
389            new ProductUnit<Area>(INCH.pow(2)));
390    
391    /**
392     * Constant for unit of area: square-yard
393     * @stable ICU 54
394     */
395    public static final Unit<Area> SQUARE_YARD = addUnit(
396            new ProductUnit<Area>(YARD.pow(2)));
397
398    ////////////
399    // Volume //
400    ////////////
401    /**
402     * Constant for unit of volume: liter<br>
403     * A unit of volume equal to one cubic decimeter (default label
404     * <code>L</code>, also recognized <code>µL, mL, cL, dL</code>).
405     * 
406     * @stable ICU 53
407     */
408    public static final Unit<Volume> LITER = new TransformedUnit<Volume>(CUBIC_METRE, new RationalConverter(1, 1000));
409    // private static final Unit<Volume> LITRE = addUnit(Units.LITRE);
410
411    /**
412     * Constant for unit of volume: cubic-meter (<code>m³</code>).
413     * 
414     * @stable ICU 54.
415     */
416    public static final Unit<Volume> CUBIC_METER = addUnit(CUBIC_METRE);
417
418    /**
419     * A unit of volume equal to one cubic inch (<code>in³</code>).
420     */
421    public static final Unit<Volume> CUBIC_INCH = addUnit(INCH.pow(3).asType(Volume.class));
422
423    /**
424     * Constant for unit of volume: gallon A unit of volume equal to one US
425     * gallon, Liquid Unit. The U.S. liquid gallon is based on the Queen Anne or
426     * Wine gallon occupying 231 cubic inches (standard name <code>gal</code>).
427     * 
428     * @stable ICU 54.
429     */
430    public static final Unit<Volume> GALLON = addUnit(CUBIC_INCH.multiply(231));
431
432    /**
433     * Constant for unit of volume: gallon-imperial
434     * 
435     * @stable ICU 57.
436     */
437    public static final Unit<Volume> GALLON_IMPERIAL = addUnit(LITER.multiply(454609).divide(100000));
438
439    /**
440     * Constant for unit of volume: cubic-foot<br>
441     * The cubic foot is an imperial and US customary (non-metric) unit of
442     * volume, used in the United States, Canada, and the United Kingdom. It is
443     * defined as the volume of a cube with sides of one foot (0.3048 m) in
444     * length. Its volume is 28.3168 liters or about 1⁄35 of a cubic meter. (
445     * <code>ft³</code>).
446     * 
447     * @stable ICU 54.
448     */
449    public static final Unit<Volume> CUBIC_FOOT = addUnit(CUBIC_INCH.multiply(1728).asType(Volume.class));
450
451    /**
452     * Constant for unit of volume: cubic-mile<br>
453     * A unit of volume equal to one cubic-mile (<code>cu mi</code>).
454     * 
455     * @stable ICU 53.
456     */
457    public static final Unit<Volume> CUBIC_MILE = addUnit(CUBIC_FOOT.multiply(147197952000L));
458
459    /**
460     * Constant for unit of volume: cubic-yard<br>
461     * A unit of volume equal to one cubic-yard (<code>cyd.</code>).
462     * 
463     * @stable ICU 54.
464     */
465    public static final Unit<Volume> CUBIC_YARD = addUnit(CUBIC_FOOT.multiply(27));
466
467    /**
468     * A unit of volume equal to <code>1 / 128 {@link #GALLON_LIQUID}</code>
469     * (standard name <code>oz_fl</code>).
470     */
471    public static final Unit<Volume> FLUID_OUNCE = addUnit(GALLON.divide(128));
472
473    /**
474     * An acre-foot is a unit of volume commonly used in the United States in
475     * reference to large-scale water resources, such as reservoirs, aqueducts,
476     * canals, sewer flow capacity, irrigation water, and river flows.
477     */
478    public static final Unit<Volume> ACRE_FOOT = addUnit(CUBIC_FOOT.multiply(43560));
479
480    /**
481     * Constant for unit of volume: bushel
482     */
483    public static final Unit<Volume> BUSHEL = addUnit(CUBIC_INCH.multiply(215042).divide(100));
484
485    /**
486     * Constant for unit of volume: cup<br>
487     * The cup is a unit of measurement for volume, used in cooking to measure
488     * liquids (fluid measurement) and bulk foods such as granulated sugar (dry
489     * measurement). A cup is equal to <code>8 {@link #FLUID_OUNCE}</code>
490     * (standard name <code>cup</code>).
491     * 
492     * @stable ICU 54.
493     */
494    public static final Unit<Volume> CUP = addUnit(FLUID_OUNCE.multiply(8));
495
496    /**
497     * Constant for unit of volume: cup-metric
498     * 
499     * @see <a href=
500     *      "https://en.wikipedia.org/wiki/Cup_(unit)#Metric_cup">Wikipedia:
501     *      Metric cup</a>
502     * @stable ICU 56.
503     */
504    public static final Unit<Volume> CUP_METRIC = addUnit(MILLI(LITER).multiply(250));
505
506    /**
507     * Constant for unit of volume: pint<br>
508     * A unit of volume equal to <code>20 {@link #FLUID_OUNCE}</code> (standard
509     * name <code>pt</code>).
510     * 
511     * @stable ICU 54
512     */
513    public static final Unit<Volume> PINT = addUnit(FLUID_OUNCE.multiply(20), "Pint", "pt", true);
514
515    /**
516     * Constant for unit of volume: pint-metric
517     * 
518     * @draft ICU 56
519     * @provisional This API might change or be removed in a future release.
520     */
521    public static final Unit<Volume> PINT_METRIC = addUnit(MILLI(LITER).multiply(500), "Metric Pint", "metr. pt", true);
522
523    /**
524     * Constant for unit of volume: quart<br>
525     * A unit of volume equal to <code>40 {@link #FLUID_OUNCE}</code> (standard
526     * name <code>qt</code>).
527     * 
528     * @stable ICU 54
529     */
530    public static final Unit<Volume> QUART = addUnit(FLUID_OUNCE.multiply(40), "Quart", "qt");
531
532    /**
533     * A unit of volume <code>~ 1 drop or 0.95 grain of water </code> (standard
534     * name <code>min</code>).
535     */
536    private static final Unit<Volume> MINIM = MICRO(LITER).multiply(61.61152d);
537
538    /**
539     * Constant for unit of volume: teaspoon<br>
540     * A unit of volume equal to <code>80 {@link #MINIM}</code> (standard name
541     * <code>tsp</code>).
542     * @stable ICU 54
543     */
544    public static final Unit<Volume> TEASPOON = addUnit(MINIM.multiply(80));
545
546    /**
547     * Constant for unit of volume: tablespoon<br>
548     * A unit of volume equal to <code>3 {@link #TEASPOON}</code> (standard name
549     * <code>Tbsp</code>).
550     * @stable ICU 54
551     */
552    public static final Unit<Volume> TABLESPOON = addUnit(TEASPOON.multiply(3));
553
554    //////////
555    // Time //
556    //////////
557    /**
558     * Constant for unit of duration: minute
559     * 
560     * @stable ICU 4.0
561     */
562    public static final Unit<Time> MINUTE = addUnit(Units.MINUTE);
563    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
564    public static final Unit<Time> HOUR = addUnit(Units.HOUR);
565    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
566    public static final Unit<Time> DAY = addUnit(Units.DAY);
567
568    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
569    static final Unit<Time> YEAR_JULIAN = addUnit(Units.DAY.multiply(365.25));
570
571    /**
572     * Constant for unit of duration: year<br>
573     * A time unit accepted for use with SI units (standard name <code>y</code> ).
574     * @stable ICU 4.0
575     */
576    public static final Unit<Time> YEAR = addUnit(Units.DAY.multiply(365.25));
577
578    /**
579     * Constant for unit of duration: month
580     * 
581     * @stable ICU 4.0
582     */
583    public static final Unit<Time> MONTH = addUnit(YEAR_JULIAN.divide(12));
584
585    /**
586     * Constant for unit of time: century
587     * 
588     * @see <a href="http://www.aqua-calc.com/what-is/time/century">What Is
589     *      century?</a>
590     * @stable ICU 56.
591     */
592    public static final Unit<Time> CENTURY = addUnit(YEAR.multiply(100));
593
594    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
595    private static final Unit<Pressure> BAR = addUnit(Units.PASCAL.multiply(100000));
596    public static final Unit<Mass> GRAM = addUnit(Units.GRAM);
597
598    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
599    public static final Unit<Mass> TONNE = addUnit(Units.KILOGRAM.multiply(1000));
600
601    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
602    private static final Unit<Mass> GRAIN = MILLI(GRAM).multiply(6479891).divide(100000);
603    /**
604     * Constant for unit of mass: pound
605     * 
606     * @stable ICU 53
607     */
608    public static final Unit<Mass> POUND = addUnit(GRAIN.multiply(7000));
609
610    /**
611     * Constant for unit of mass: ounce<br>
612     * A unit of mass equal to <code>1 / 16 {@link #POUND}</code> (standard name
613     * <code>oz</code>).
614     * 
615     * @stable ICU 53
616     */
617    public static final Unit<Mass> OUNCE = addUnit(POUND.divide(16), "oz", true);
618
619    /** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
620    private static final Unit<Mass> PENNYWEIGHT_TROY = GRAIN.multiply(24);
621    /**
622     * Constant for unit of mass: ounce-troy
623     * 
624     * @stable ICU 54
625     */
626    public static final Unit<Mass> OUNCE_TROY = addUnit(PENNYWEIGHT_TROY.multiply(20));
627    
628    /**
629     * Constant for unit of area: square-yard
630     * @stable ICU 54
631     */
632    public static final Unit<Mass> STONE = addUnit(POUND.multiply(14));
633    
634    ///////////////////
635    // NATURAL UNITS //
636    ///////////////////
637    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
638    static final Unit<Speed> C = addUnit(Units.METRE_PER_SECOND.multiply(299792458));
639    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
640    // public static final Unit<Action> PLANCK = addUnit(SI.JOULE_SECOND
641    // .multiply(6.6260755E-24)); // FIXME get rid of JXQ import (where
642    // from??) */
643
644    /**
645     * Constant for unit of acceleration: g-force
646     * 
647     * @stable ICU 53.
648     */
649    public static final Unit<Acceleration> G_FORCE = addUnit(Units.METRE_PER_SQUARE_SECOND.multiply(9.80665));
650
651    ////////////
652    // Length //
653    ////////////
654    /**
655     * Constant for unit of length: light-year<br>
656     * A unit of length equal to the distance that light travels in one year
657     * through a vacuum (standard name <code>ly</code>).
658     * 
659     * @stable ICU 53
660     */
661    public static final Unit<Length> LIGHT_YEAR = addUnit(new ProductUnit<Length>(C.multiply(YEAR_JULIAN)));
662    /**
663     * A unit of length equal to the distance that light travels in one year
664     * through a vacuum (standard name <code>ly</code>).
665     */
666    // static final Unit<Length> LIGHT_YEAR = addUnit(METRE
667    // .multiply(9.460528405e15));
668
669    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
670    static final Unit<Length> INCH_INTERNATIONAL = addUnit(CENTI(METRE).multiply(254).divide(100));
671    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
672    static final Unit<Length> FOOT_INTERNATIONAL = addUnit(INCH_INTERNATIONAL.multiply(12));
673    /**
674     * Constant for unit of length: nautical-mile
675     * 
676     * @stable ICU 54
677     */
678    public static final Unit<Length> NAUTICAL_MILE = addUnit(METRE.multiply(1852));
679
680    /**
681     * Constant for unit of speed: knot
682     * 
683     * @draft ICU 56
684     * @provisional This API might change or be removed in a future release.
685     */
686    public static final Unit<Speed> KNOT = addUnit(new ProductUnit<Speed>(NAUTICAL_MILE.divide(HOUR)));
687
688    /**
689     * Constant for unit of speed: meter-per-second<br>
690     * The unit for speed (standard name <code>m/s</code>).
691     * 
692     * @stable ICU 53
693     */
694    public static final Unit<Speed> METER_PER_SECOND = addUnit(new ProductUnit<Speed>(METER.divide(SECOND)),
695            Speed.class);
696
697    /**
698     * Constant for unit of speed: mile-per-hour<br>
699     * A unit of velocity expressing the number of international {@link #MILE
700     * miles} per {@link #HOUR hour} (abbreviation <code>mph</code>).
701     * 
702     * @stable ICU 53
703     */
704    public static final Unit<Speed> MILE_PER_HOUR = addUnit(MILE.divide(HOUR).asType(Speed.class), "Mile per hour",
705            "mph");
706
707    /**
708     * Constant for unit of speed: mile-per-hour<br>
709     * The unit for acceleration (standard name <code>m/s2</code> ).
710     * 
711     * @stable ICU 53
712     */
713    public static final Unit<Acceleration> METER_PER_SECOND_SQUARED = addUnit(
714            new ProductUnit<Acceleration>(METER_PER_SECOND.divide(SECOND)), Acceleration.class);
715
716    /**
717     * Constant for unit of mass: carat<br>
718     * Carat (mass) is a unit of {@link Mass} for gems. It is equal to 0.2 gram
719     * (standard name <code>ct</code>).</br>
720     * In the United States, carat almost exclusively means the unit of mass.
721     * 
722     * @see <a href="https://en.wikipedia.org/wiki/Carat_(mass)">Wikipedia:
723     *      Carat (mass)</a>
724     *
725     * @stable ICU 54
726     */
727    public static final Unit<Mass> CARAT = addUnit(GRAM.divide(5));
728    // public static final Unit<Mass> CARAT = addUnit((KILOGRAM.divide(5000)));
729
730    /**
731     * Constant for unit of proportion: karat
732     * 
733     * @stable ICU 54
734     */
735    public static final Unit<Dimensionless> KARAT = addUnit(ONE.divide(24));
736
737    private static final Unit<Force> POUND_FORCE = addUnit(POUND.multiply(G_FORCE).asType(Force.class));
738
739    /**
740     * Constant for unit of length: parsec<br>
741     * A unit of length equal to the distance at which a star would appear to
742     * shift its position by one arcsecond over the course the time (about 3
743     * months) in which the Earth moves a distance of {@link #ASTRONOMICAL_UNIT}
744     * in the direction perpendicular to the direction to the star (standard
745     * name <code>pc</code>).
746     * 
747     * @stable ICU 54.
748     */
749    public static final Unit<Length> PARSEC = addUnit(METRE.multiply(30856770e9));
750
751    ///////////////////////////////
752    // TYPESETTER'S LENGTH UNITS //
753    ///////////////////////////////
754    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
755    static final Unit<Length> LINE = addUnit(INCH_INTERNATIONAL.divide(12));
756    /**
757     * A unit of length equal to <code>0.013837 {@link #INCH}</code> exactly
758     * (standard name <code>pt</code>).
759     * 
760     * @see #PIXEL
761     */
762    /*
763     * public static final Unit<Length> POINT = addUnit(LINE.divide(6)); //
764     * static final Unit<Length> POINT = addUnit(INCH.multiply(13837) //
765     * .divide(1000000));
766     * 
767     * /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. public
768     * static final Unit<Length> PICA = addUnit(POINT.multiply(12)); /** As per
769     * <a href="http//cldr.unicode.org/">CLDR</a> standard. public static final
770     * Unit<Length> POINT_PRINTER =
771     * addUnit(INCH_INTERNATIONAL.multiply(13837).divide(1000000)); /** As per
772     * <a href="http//cldr.unicode.org/">CLDR</a> standard. public static final
773     * Unit<Length> PICA_PRINTER = addUnit(POINT_PRINTER.multiply(12));
774     */
775    //////////////////////////////
776    // OTHER LEGACY UNITS: CLDR //
777    //////////////////////////////
778    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
779    public static final Unit<Temperature> FAHRENHEIT = addUnit(KELVIN.multiply(5).divide(9).shift(459.67));
780
781    /**
782     * Constant for unit of energy: foodcalorie.
783     * 
784     * @see <a href=
785     *      "http://www.convertunits.com/info/calorie+[nutritional]">Calorie
786     *      (nutritional)</a>
787     * 
788     * @stable ICU 54
789     */
790    public static final Unit<Energy> FOODCALORIE = addUnit(JOULE.multiply(4186.8));
791
792    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
793    private static final Unit<Energy> CALORIE_THERMOCHEMICAL = addUnit(JOULE.multiply(4184).divide(1000));
794    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
795    public static final Unit<Energy> CALORIE = addUnit(CALORIE_THERMOCHEMICAL);
796    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
797    // private static final Unit<Energy> CALORIE_FOOD =
798    // addUnit(KILO(CALORIE_THERMOCHEMICAL));
799
800    /**
801     * Constant for unit of power: horsepower
802     * 
803     * @stable ICU 53
804     */
805    public static final Unit<Power> HORSEPOWER = addUnit(
806            new ProductUnit<Power>(FOOT_INTERNATIONAL.multiply(POUND_FORCE).divide(SECOND)));
807
808    /**
809     * Constant for unit of pressure: pound-per-square-inch
810     * 
811     * @stable ICU 54
812     */
813    public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(
814            new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
815    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
816    // private static final Unit<Angle> CIRCLE = new
817    // ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2)));
818
819    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
820    public static final Unit<SolidAngle> SPHERE = addUnit(
821            new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
822
823    /**
824     * The unit for binary information (standard name <code>bit</code>).
825     * 
826     * @stable ICU 54
827     */
828    public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), "Bit", "bit",
829            Information.class);
830
831    /**
832     * A unit of data amount equal to <code>8 {@link #BIT}</code> (BinarY TErm,
833     * standard name <code>byte</code>).
834     */
835    public static final Unit<Information> BYTE = addUnit(BIT.multiply(8), "Byte", "byte");
836
837    /**
838     * The unit for binary information rate (standard name <code>bit/s</code>).
839     * 
840     * @draft Non-ICU
841     */
842    static final Unit<InformationRate> BIT_PER_SECOND = addUnit(new ProductUnit<InformationRate>(BIT.divide(SECOND)),
843            InformationRate.class);
844
845    /**
846     * Equivalent {@link #BYTE}
847     */
848    static final Unit<Information> OCTET = BYTE;
849
850    /**
851     * A unit used to measure the frequency (rate) at which an imaging device
852     * produces unique consecutive images (standard name <code>fps</code>).
853     * 
854     * @draft Non-ICU
855     */
856    static final Unit<Frequency> FRAME_PER_SECOND = ONE.divide(SECOND).asType(Frequency.class);
857
858    ///////////////////
859    // Concentration //
860    ///////////////////
861
862    /**
863     * Constant for unit of concentr: milligram-per-deciliter
864     * 
865     * @stable ICU 57
866     */
867    @SuppressWarnings("unchecked")
868    public static final Unit<Concentration<Mass>> MILLIGRAM_PER_DECILITER = addUnit(
869            MILLI(GRAM).divide(DECI(LITER)).asType(Concentration.class));
870
871    ///////////////////
872    // Consumption //
873    ///////////////////
874
875    /**
876     * Constant for unit of consumption: liter-per-100kilometers
877     * 
878     * @draft ICU 56
879     * @provisional This API might change or be removed in a future release.
880     */
881    @SuppressWarnings("unchecked")
882    public static final Unit<Consumption<Volume>> LITER_PER_100KILOMETERS = addUnit(
883            (KILOMETER.multiply(100)).divide(LITER).asType(Consumption.class));;
884
885    /**
886     * Constant for unit of consumption: liter-per-kilometer
887     * 
888     * @stable ICU 54
889     */
890    @SuppressWarnings("unchecked")
891    public static final Unit<Consumption<Volume>> LITER_PER_KILOMETER = addUnit(
892            KILOMETER.divide(LITER).asType(Consumption.class));
893
894    /**
895     * Constant for unit of consumption: mile-per-gallon
896     * 
897     * @stable ICU 54
898     */
899    @SuppressWarnings("unchecked")
900    public static final Unit<Consumption<Volume>> MILE_PER_GALLON = addUnit(
901            MILE.divide(GALLON).asType(Consumption.class));
902
903    /////////////////////
904    // Collection View //
905    /////////////////////
906
907    @Override
908    public String getName() {
909        return "Unicode CLDR";
910    }
911
912    /**
913     * Adds a new unit not mapped to any specified quantity type.
914     *
915     * @param unit
916     *            the unit being added.
917     * @return <code>unit</code>.
918     */
919    private static <U extends Unit<Q>, Q extends Quantity<Q>> U addUnit(U unit) {
920        INSTANCE.units.add(unit);
921        return unit;
922    }
923
924    /**
925     * Adds a new unit and maps it to the specified quantity type.
926     *
927     * @param unit
928     *            the unit being added.
929     * @param type
930     *            the quantity type.
931     * @return <code>unit</code>.
932     */
933    private static <U extends Unit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) {
934        INSTANCE.units.add(unit);
935        INSTANCE.quantityToUnit.put(type, unit);
936        return unit;
937    }
938
939    /**
940     * Adds a new unit not mapped to any specified quantity type and puts a text
941     * as symbol or label.
942     *
943     * @param unit
944     *            the unit being added.
945     * @param name
946     *            the string to use as name
947     * @param text
948     *            the string to use as label or symbol
949     * @param isLabel
950     *            if the string should be used as a label or not
951     * @return <code>unit</code>.
952     */
953    private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) {
954        if (isLabel) {
955            SimpleUnitFormat.getInstance().label(unit, text);
956        }
957        if (name != null && unit instanceof AbstractUnit) {
958            return Helper.addUnit(INSTANCE.units, unit, name);
959        } else {
960            INSTANCE.units.add(unit);
961        }
962        return unit;
963    }
964
965    /**
966     * Adds a new unit not mapped to any specified quantity type and puts a text
967     * as symbol or label.
968     *
969     * @param unit
970     *            the unit being added.
971     * @param name
972     *            the string to use as name
973     * @param text
974     *            the string to use as label or symbol
975     * @param isLabel
976     *            if the string should be used as a label or not
977     * @return <code>unit</code>.
978     */
979    private static <U extends Unit<?>> U addUnit(U unit, String name, String text) {
980        return addUnit(unit, name, text, true);
981    }
982
983    /**
984     * Adds a new unit and maps it to the specified quantity type.
985     *
986     * @param unit
987     *            the unit being added.
988     * @param type
989     *            the quantity type.
990     * @return <code>unit</code>.
991     */
992    private static <U extends AbstractUnit<?>> U addUnit(U unit, String name, String label,
993            Class<? extends Quantity<?>> type) {
994        INSTANCE.quantityToUnit.put(type, unit);
995        return addUnit(unit, name, label);
996    }
997
998    /**
999     * Adds a new unit not mapped to any specified quantity type and puts a text
1000     * as symbol or label.
1001     *
1002     * @param unit
1003     *            the unit being added.
1004     * @param text
1005     *            the string to use as label or symbol
1006     * @param isLabel
1007     *            if the string should be used as a label or not
1008     * @return <code>unit</code>.
1009     */
1010    private static <U extends Unit<?>> U addUnit(U unit, String text, boolean isLabel) {
1011        return addUnit(unit, null, text, isLabel);
1012    }
1013
1014    // //////////////////////////////////////////////////////////////////////////
1015    // Label adjustments for CLDR system
1016    static {
1017        SimpleUnitFormat.getInstance().alias(BYTE, "B");
1018        SimpleUnitFormat.getInstance().label(KARAT, "kt");
1019        SimpleUnitFormat.getInstance().label(CARAT, "ct");
1020        SimpleUnitFormat.getInstance().label(POUND, "lb");
1021        SimpleUnitFormat.getInstance().label(BAR, "b");
1022        SimpleUnitFormat.getInstance().label(PARSEC, "pc");
1023        SimpleUnitFormat.getInstance().label(SQUARE_FOOT, "sft");
1024    }
1025}