001/*
002 * Unit Systems
003 * Copyright (c) 2005-2017, Jean-Marie Dautelle, Werner Keil, V2COM.
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 nor the names of its contributors may be used to endorse or promote products
017 *    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;
037import systems.uom.quantity.Information;
038import systems.uom.quantity.InformationRate;
039import tec.uom.se.*;
040import tec.uom.se.format.SimpleUnitFormat;
041import tec.uom.se.function.PiMultiplierConverter;
042import tec.uom.se.function.RationalConverter;
043import tec.uom.se.unit.AlternateUnit;
044import tec.uom.se.unit.ProductUnit;
045import tec.uom.se.unit.TransformedUnit;
046import tec.uom.se.unit.Units;
047
048import javax.measure.Quantity;
049import javax.measure.Unit;
050import javax.measure.quantity.*;
051
052/**
053 * <p>
054 * This class contains SI and Non-SI units as defined in the
055 * <a href="http//cldr.unicode.org/">Unicode CLDR Project</a>.
056 * </p>
057 *
058 * <p>
059 * Compatibility with {@linkplain SI} units has been given priority over strict
060 * adherence to the standard. We have attempted to note every place where the
061 * definitions in this class deviate from the CLDR standard, but such notes are
062 * likely to be incomplete.
063 * </p>
064 * 
065 * @noextend This class is not intended to be extended by clients.
066 *
067 * @author <a href="mailto:units@catmedia.us">Werner Keil</a>
068 * @see <a href="http://cldr.unicode.org">Unicode CLDR</a>
069 * @version 0.5.3, $Date: 2017-03-05 $
070 */
071public final class CLDR extends AbstractSystemOfUnits {
072
073    /**
074     * The singleton instance.
075     */
076    private static final CLDR INSTANCE = new CLDR();
077
078    /**
079     * Default constructor (prevents this class from being instantiated).
080     */
081    private CLDR() {
082    }
083
084    /**
085     * Returns the singleton instance of this class.
086     *
087     * @return the CLDR system instance.
088     */
089    public static CLDR getInstance() {
090        return INSTANCE;
091    }
092
093    ////////////
094    // Length //
095    ////////////
096    /**
097     * US name for {@link Units#METRE}.
098     */
099    public static final Unit<Length> METER = METRE;
100
101    /**
102     * A unit of length equal to <code>0.3048 m</code> (standard name
103     * <code>ft</code>).
104     */
105    public static final Unit<Length> FOOT = addUnit(METER.multiply(3048).divide(10000));
106
107    /**
108     * A unit of length equal to <code>1200/3937 m</code> (standard name
109     * <code>foot_survey_us</code>). See also:
110     * <a href="http://www.sizes.com/units/foot.htm">foot</a>
111     */
112    public static final Unit<Length> FOOT_SURVEY = addUnit(METER.multiply(1200).divide(3937));
113
114    /**
115     * A unit of length equal to <code>0.9144 m</code> (standard name
116     * <code>yd</code>).
117     */
118    public static final Unit<Length> YARD = addUnit(FOOT.multiply(3));
119
120    /**
121     * A unit of length equal to <code>0.0254 m</code> (standard name
122     * <code>in</code>).
123     */
124    public static final Unit<Length> INCH = addUnit(FOOT.divide(12));
125
126    /**
127     * A unit of length equal to <code>1609.344 m</code> (standard name
128     * <code>mi</code>).
129     */
130    public static final Unit<Length> MILE = addUnit(METER.multiply(1609344).divide(1000));
131
132    /**
133     * A unit of length equal to the average distance from the center of the
134     * Earth to the center of the Sun (standard name <code>ua</code>).
135     */
136    public static final Unit<Length> ASTRONOMICAL_UNIT = addUnit(METRE.multiply(149597870691.0));
137
138    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
139    public static final Unit<Time> SECOND = addUnit(Units.SECOND);
140
141    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
142    public static final Unit<Angle> RADIAN = addUnit(Units.RADIAN);
143    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
144    public static final Unit<Temperature> KELVIN = addUnit(Units.KELVIN);
145
146    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
147    public static final Unit<LuminousIntensity> CANDELA = addUnit(Units.CANDELA);
148
149    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
150    public static final Unit<Dimensionless> PI = addUnit(ONE.transform(new PiMultiplierConverter()));
151    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
152    public static final Unit<Dimensionless> PERCENT = addUnit(ONE.divide(100), "Percent", "%");
153
154    ////////////////////
155    // SI UNITS: CLDR //
156    ////////////////////
157    /**
158     * We deviate slightly from the standard here, to maintain compatibility
159     * with the existing SI units. In CLDR, the mole is no longer a base unit,
160     * but is defined as <code>Unit.ONE.multiply(6.0221367E23)</code>.
161     */
162    public static final Unit<AmountOfSubstance> MOLE = addUnit(Units.MOLE);
163    /**
164     * We deviate slightly from the standard here, to maintain compatibility
165     * with the existing SI units. In CLDR, the steradian is defined as
166     * <code>RADIAN.pow(2)</code>.
167     */
168    public static final Unit<SolidAngle> STERADIAN = addUnit(Units.STERADIAN);
169
170    public static final Unit<Frequency> HERTZ = addUnit(Units.HERTZ);
171    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
172    public static final Unit<Force> NEWTON = addUnit(Units.NEWTON);
173    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
174    public static final Unit<Pressure> PASCAL = addUnit(Units.PASCAL);
175    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
176    public static final Unit<Energy> JOULE = addUnit(Units.JOULE);
177    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
178    public static final Unit<Power> WATT = addUnit(Units.WATT);
179    /**
180     * We deviate slightly from the standard here, to maintain compatability
181     * with the existing SI units. In CLDR, the ampere is defined as
182     * <code>COULOMB.divide(SECOND)</code>.
183     */
184    public static final Unit<ElectricCurrent> AMPERE = addUnit(Units.AMPERE);
185
186    /**
187     * We deviate slightly from the standard here, to maintain compatibility
188     * with the existing SI units. In CLDR, the volt is defined as
189     * <code>JOULE.divide(COULOMB)</code>.
190     */
191    public static final Unit<ElectricPotential> VOLT = addUnit(Units.VOLT);
192    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
193    public static final Unit<ElectricCapacitance> FARAD = addUnit(Units.FARAD);
194    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
195    public static final Unit<ElectricResistance> OHM = addUnit(Units.OHM);
196    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
197    public static final Unit<ElectricConductance> SIEMENS = addUnit(Units.SIEMENS);
198    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
199    public static final Unit<MagneticFlux> WEBER = addUnit(Units.WEBER);
200    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
201    public static final Unit<Temperature> CELSIUS = addUnit(Units.CELSIUS);
202    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
203    public static final Unit<MagneticFluxDensity> TESLA = addUnit(Units.TESLA);
204    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
205    public static final Unit<ElectricInductance> HENRY = addUnit(Units.HENRY);
206    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
207    public static final Unit<LuminousFlux> LUMEN = addUnit(Units.LUMEN);
208    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
209    public static final Unit<Illuminance> LUX = addUnit(Units.LUX);
210
211    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
212    public static final Unit<RadiationDoseAbsorbed> GRAY = addUnit(Units.GRAY);
213    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
214    public static final Unit<RadiationDoseEffective> SIEVERT = addUnit(Units.SIEVERT);
215
216    /////////////////////////////////////////////////////////////////
217    // Units outside the SI that are accepted for use with the SI. //
218    /////////////////////////////////////////////////////////////////
219
220    /**
221     * An angle unit accepted for use with SI units (standard name
222     * <code>deg/code>).
223     */
224    static final Unit<Angle> DEGREE_ANGLE = new TransformedUnit<Angle>(RADIAN,
225            new PiMultiplierConverter().concatenate(new RationalConverter(1, 180)));
226
227    /**
228     * An angle unit accepted for use with SI units (standard name
229     * <code>'/code>).
230     */
231    static final Unit<Angle> MINUTE_ANGLE = new TransformedUnit<Angle>(RADIAN,
232            new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60)));
233
234    /**
235     * An angle unit accepted for use with SI units (standard name
236     * <code>''</code>).
237     */
238    static final Unit<Angle> SECOND_ANGLE = new TransformedUnit<Angle>(RADIAN,
239            new PiMultiplierConverter().concatenate(new RationalConverter(1, 180 * 60 * 60)));
240
241    /**
242     * We deviate slightly from the standard here, to maintain compatibility
243     * with the existing NonSI units. In CLDR, the degree is defined as
244     * <code>PI.multiply(RADIAN.divide(180))</code>.
245     */
246    public static final Unit<Angle> DEGREE = addUnit(DEGREE_ANGLE);
247
248    public static final Unit<Angle> ARC_MINUTE = addUnit(MINUTE_ANGLE);
249
250    public static final Unit<Angle> ARC_SECOND = addUnit(SECOND_ANGLE);
251
252    //////////
253    // Area //
254    //////////
255    /**
256     * A unit of area (standard name <code>sft</code> ).
257     */
258    public static final Unit<Area> SQUARE_FOOT = addUnit(new ProductUnit<Area>((AbstractUnit<?>) FOOT.multiply(FOOT)),
259            "Square Foot", "sft");
260
261    /**
262     * A unit of area equal to <code>100 m²</code> (standard name <code>a</code>
263     * ).
264     */
265    private static final Unit<Area> ARE = addUnit(SQUARE_METRE.multiply(100));
266
267    /**
268     * A unit of area equal to <code>100 {@link #ARE}</code> (standard name
269     * <code>ha</code>).
270     */
271    public static final Unit<Area> HECTARE = addUnit(ARE.multiply(100), "Hectare", "ha");
272
273    /**
274     * The acre is a unit of area used in the imperial and U.S. customary
275     * systems. It is equivalent to <code>43,560 square feet</code>. An acre is
276     * about 40% of a <code>HECTARE</code> – slightly smaller than an American
277     * football field. (standard name <code>ac</code> ).
278     * 
279     * @see <a href="http://en.wikipedia.org/wiki/Acre">Wikipedia: Acre</a>
280     */
281    public static final Unit<Area> ACRE = addUnit(SQUARE_FOOT.multiply(43560));
282
283    ////////////
284    // Volume //
285    ////////////
286    /**
287     * A unit of volume equal to one cubic decimeter (default label
288     * <code>L</code>, also recognized <code>µL, mL, cL, dL</code>).
289     */
290    public static final Unit<Volume> LITER = new TransformedUnit<Volume>(CUBIC_METRE, new RationalConverter(1, 1000));
291    // private static final Unit<Volume> LITRE = addUnit(Units.LITRE);
292
293    /**
294     * A unit of volume equal to one cubic inch (<code>in³</code>).
295     */
296    public static final Unit<Volume> CUBIC_INCH = addUnit(INCH.pow(3).asType(Volume.class));
297
298    /**
299     * The cubic foot is an imperial and US customary (non-metric) unit of
300     * volume, used in the United States, Canada, and the United Kingdom. It is
301     * defined as the volume of a cube with sides of one foot (0.3048 m) in
302     * length. Its volume is 28.3168 liters or about 1⁄35 of a cubic meter. (
303     * <code>ft³</code>).
304     */
305    public static final Unit<Volume> CUBIC_FOOT = addUnit(CUBIC_INCH.multiply(1728).asType(Volume.class));
306
307    /**
308     * An acre-foot is a unit of volume commonly used in the United States in
309     * reference to large-scale water resources, such as reservoirs, aqueducts,
310     * canals, sewer flow capacity, irrigation water, and river flows.
311     */
312    public static final Unit<Volume> ACRE_FOOT = addUnit(CUBIC_FOOT.multiply(43560));
313
314    /**
315     * Constant for unit of volume: bushel
316     */
317    public static final Unit<Volume> BUSHEL = addUnit(CUBIC_INCH.multiply(215042).divide(100));
318
319    //////////
320    // Time //
321    //////////
322    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
323    public static final Unit<Time> MINUTE = addUnit(Units.MINUTE);
324    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
325    public static final Unit<Time> HOUR = addUnit(Units.HOUR);
326    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
327    public static final Unit<Time> DAY = addUnit(Units.DAY);
328
329    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
330    static final Unit<Time> YEAR_JULIAN = addUnit(Units.DAY.multiply(365.25));
331
332    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
333    public static final Unit<Time> YEAR = addUnit(Units.DAY.multiply(365.25));
334    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
335
336    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
337    public static final Unit<Time> MONTH = addUnit(YEAR_JULIAN.divide(12));
338
339    /** Constant for unit of time: century */
340    public static final Unit<Time> CENTURY = addUnit(YEAR.multiply(100));
341
342    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
343    private static final Unit<Pressure> BAR = addUnit(Units.PASCAL.multiply(100000));
344    public static final Unit<Mass> GRAM = addUnit(Units.GRAM);
345
346    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
347    public static final Unit<Mass> TONNE = addUnit(Units.KILOGRAM.multiply(1000));
348
349    ///////////////////
350    // NATURAL UNITS //
351    ///////////////////
352    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
353    static final Unit<Speed> C = addUnit(Units.METRE_PER_SECOND.multiply(299792458));
354    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
355    // public static final Unit<Action> PLANCK = addUnit(SI.JOULE_SECOND
356    // .multiply(6.6260755E-24)); // FIXME get rid of JXQ import (where
357    // from??) */
358
359    private static final Unit<Acceleration> ACCELLERATION_OF_FREEFALL = addUnit(
360            Units.METRE_PER_SQUARE_SECOND.multiply(9.80665));
361
362    ////////////
363    // Length //
364    ////////////
365    /**
366     * A unit of length equal to the distance that light travels in one year
367     * through a vacuum (standard name <code>ly</code>).
368     */
369    public static final Unit<Length> LIGHT_YEAR = addUnit(new ProductUnit<Length>(C.multiply(YEAR_JULIAN)));
370    /**
371     * A unit of length equal to the distance that light travels in one year
372     * through a vacuum (standard name <code>ly</code>).
373     */
374    // static final Unit<Length> LIGHT_YEAR = addUnit(METRE
375    // .multiply(9.460528405e15));
376
377    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
378    static final Unit<Length> INCH_INTERNATIONAL = addUnit(CENTI(METRE).multiply(254).divide(100));
379    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
380    static final Unit<Length> FOOT_INTERNATIONAL = addUnit(INCH_INTERNATIONAL.multiply(12));
381    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
382    public static final Unit<Length> NAUTICAL_MILE = addUnit(METRE.multiply(1852));
383    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
384    public static final Unit<Speed> KNOT = addUnit(new ProductUnit<Speed>(NAUTICAL_MILE.divide(HOUR)));
385
386    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
387    private static final Unit<Mass> GRAIN = addUnit(MILLI(GRAM).multiply(6479891).divide(100000));
388    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
389    static final Unit<Mass> POUND = addUnit(GRAIN.multiply(7000));
390
391    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
392    public static final Unit<Mass> CARAT = addUnit(GRAM.divide(5));
393    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
394    private static final Unit<Dimensionless> CARAT_GOLD = addUnit(ONE.divide(24));
395
396    private static final Unit<Force> POUND_FORCE = addUnit(
397            POUND.multiply(ACCELLERATION_OF_FREEFALL).asType(Force.class));
398
399    /**
400     * A unit of length equal to the distance at which a star would appear to
401     * shift its position by one arcsecond over the course the time (about 3
402     * months) in which the Earth moves a distance of {@link #ASTRONOMICAL_UNIT}
403     * in the direction perpendicular to the direction to the star (standard
404     * name <code>pc</code>).
405     * 
406     * @stable ICU 54.
407     */
408    public static final Unit<Length> PARSEC = addUnit(METRE.multiply(30856770e9));
409
410    ///////////////////////////////
411    // TYPESETTER'S LENGTH UNITS //
412    ///////////////////////////////
413    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
414    static final Unit<Length> LINE = addUnit(INCH_INTERNATIONAL.divide(12));
415    /**
416     * A unit of length equal to <code>0.013837 {@link #INCH}</code> exactly
417     * (standard name <code>pt</code>).
418     * 
419     * @see #PIXEL
420     */
421    static final Unit<Length> POINT = LINE.divide(6);
422    // static final Unit<Length> POINT = addUnit(INCH.multiply(13837)
423    // .divide(1000000));
424
425    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
426    static final Unit<Length> PICA = POINT.multiply(12);
427    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
428    static final Unit<Length> POINT_PRINTER = INCH_INTERNATIONAL.multiply(13837).divide(1000000);
429    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
430    static final Unit<Length> PICA_PRINTER = POINT_PRINTER.multiply(12);
431
432    //////////////////////////////
433    // OTHER LEGACY UNITS: CLDR //
434    //////////////////////////////
435    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
436    public static final Unit<Temperature> FAHRENHEIT = addUnit(KELVIN.multiply(5).divide(9).shift(459.67));
437
438    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
439    private static final Unit<Energy> CALORIE_THERMOCHEMICAL = addUnit(JOULE.multiply(4184).divide(1000));
440    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
441    public static final Unit<Energy> CALORIE = addUnit(CALORIE_THERMOCHEMICAL);
442    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
443//    private static final Unit<Energy> CALORIE_FOOD = addUnit(KILO(CALORIE_THERMOCHEMICAL));
444
445    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
446    public static final Unit<Power> HORSEPOWER = addUnit(
447            new ProductUnit<Power>(FOOT_INTERNATIONAL.multiply(POUND_FORCE).divide(SECOND)));
448
449    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
450    public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(
451            new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
452    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
453    public static final Unit<Angle> CIRCLE = addUnit(new ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2))));
454
455    /** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
456    public static final Unit<SolidAngle> SPHERE = addUnit(
457            new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
458
459    /**
460     * The unit for binary information (standard name <code>bit</code>).
461     */
462    public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), "Bit", "bit",
463            Information.class);
464
465    /**
466     * A unit of data amount equal to <code>8 {@link #BIT}</code> (BinarY
467     * TErm, standard name <code>byte</code>).
468     */
469    public static final Unit<Information> BYTE = addUnit(BIT.multiply(8), "Byte", "byte");
470
471    /**
472     * The unit for binary information rate (standard name <code>bit/s</code>).
473     */
474    static final ProductUnit<InformationRate> BITS_PER_SECOND = addUnit(
475            new ProductUnit<InformationRate>(BIT.divide(SECOND)), InformationRate.class);
476
477    /**
478     * Equivalent {@link #BYTE}
479     */
480    static final Unit<Information> OCTET = BYTE;
481
482    // ///////////////////
483    // Collection View //
484    // ///////////////////
485
486    @Override
487    public String getName() {
488        return "Unicode CLDR";
489    }
490
491    /**
492     * Adds a new unit not mapped to any specified quantity type.
493     *
494     * @param unit
495     *            the unit being added.
496     * @return <code>unit</code>.
497     */
498    private static <U extends Unit<?>> U addUnit(U unit) {
499        INSTANCE.units.add(unit);
500        return unit;
501    }
502
503    /**
504     * Adds a new unit and maps it to the specified quantity type.
505     *
506     * @param unit
507     *            the unit being added.
508     * @param type
509     *            the quantity type.
510     * @return <code>unit</code>.
511     */
512    private static <U extends AbstractUnit<?>> U addUnit(U unit, Class<? extends Quantity<?>> type) {
513        INSTANCE.units.add(unit);
514        INSTANCE.quantityToUnit.put(type, unit);
515        return unit;
516    }
517
518    /**
519     * Adds a new unit not mapped to any specified quantity type and puts a text
520     * as symbol or label.
521     *
522     * @param unit
523     *            the unit being added.
524     * @param name
525     *            the string to use as name
526     * @param text
527     *            the string to use as label or symbol
528     * @param isLabel
529     *            if the string should be used as a label or not
530     * @return <code>unit</code>.
531     */
532    private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) {
533        if (isLabel) {
534            SimpleUnitFormat.getInstance().label(unit, text);
535        }
536        if (name != null && unit instanceof AbstractUnit) {
537            return Helper.addUnit(INSTANCE.units, unit, name);
538        } else {
539            INSTANCE.units.add(unit);
540        }
541        return unit;
542    }
543
544    /**
545     * Adds a new unit not mapped to any specified quantity type and puts a text
546     * as symbol or label.
547     *
548     * @param unit
549     *            the unit being added.
550     * @param name
551     *            the string to use as name
552     * @param text
553     *            the string to use as label or symbol
554     * @param isLabel
555     *            if the string should be used as a label or not
556     * @return <code>unit</code>.
557     */
558    private static <U extends Unit<?>> U addUnit(U unit, String name, String text) {
559        return addUnit(unit, name, text, true);
560    }
561
562    /**
563     * Adds a new unit and maps it to the specified quantity type.
564     *
565     * @param unit
566     *            the unit being added.
567     * @param type
568     *            the quantity type.
569     * @return <code>unit</code>.
570     */
571    private static <U extends AbstractUnit<?>> U addUnit(U unit, String name, String text,
572            Class<? extends Quantity<?>> type) {
573        INSTANCE.quantityToUnit.put(type, unit);
574        return addUnit(unit, name, text);
575    }
576
577    // //////////////////////////////////////////////////////////////////////////
578    // Label adjustments for CLDR system
579    static {
580        SimpleUnitFormat.getInstance().alias(BYTE, "B");
581        SimpleUnitFormat.getInstance().label(CARAT_GOLD, "kt");
582        SimpleUnitFormat.getInstance().label(CARAT, "ct");
583        SimpleUnitFormat.getInstance().label(POUND, "lb");
584        SimpleUnitFormat.getInstance().label(BAR, "b");
585        SimpleUnitFormat.getInstance().label(PARSEC, "pc");
586        SimpleUnitFormat.getInstance().label(SQUARE_FOOT, "sft");
587    }
588}