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