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