001/*
002 * Units of Measurement Systems
003 * Copyright (c) 2005-2021, 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-385, 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.common;
031
032import javax.measure.Prefix;
033import javax.measure.Quantity;
034import javax.measure.Unit;
035
036/**
037 * Utility class holding prefixes used today in India, Pakistan, Bangladesh, Nepal
038 * and Myanmar (Burma); based on grouping by two decimal places, rather than the
039 * three decimal places common in most parts of the world. [code] import static
040 * org.eclipse.uomo.units.IndianPrefix.*; // Static import. ... Unit<Pressure>
041 * LAKH_PASCAL = LAKH(PASCAL);
042 * Unit<Length>CRORE_METER = CRORE(METER); [/code]
043 * 
044 * @author <a href="mailto:werner@uom.systems">Werner Keil</a>
045 * @version 2.0 $Date: 2019-06-19 $
046 * @see <a
047 *      href="http://en.wikipedia.org/wiki/Indian_numbering_system">Wikipedia: Indian numbering system</a>
048 */
049public enum IndianPrefix implements Prefix {
050    /** Prefix for 10<sup>24</sup>. */
051        EK("E", 1, 1),
052    /** Prefix for 10<sup>21</sup>. */
053        DAS("D", 10, 1),
054    /** Prefix for 10<sup>18</sup>. */
055        SAU("S", 10, 2),
056    /** Prefix for 10<sup>15</sup>. */
057        SAHASR("SA", 10, 3),
058    /** Prefix for 10<sup>12</sup>. */
059        LAKH("Lk", 10, 5),
060    /** Prefix for 10<sup>9</sup>. */
061        CRORE("cr", 10, 7),
062    /** Prefix for 10<sup>6</sup>. */
063        ARAWB("A", 10, 9),
064    /** Prefix for 10<sup>3</sup>. */
065        KHARAWB("K", 10, 11),
066    /** Prefix for 10<sup>2</sup>. */
067        NEEL("N", 10, 13),
068    /** Prefix for 10<sup>1</sup>. */
069        PADMA("Pa", 10, 15),
070    /** Prefix for 10<sup>-1</sup>. */
071        SHANKH("SH", 10, 17),
072    /** Prefix for 10<sup>-2</sup>. */
073        MAHASHANKH("M", 10, 19);
074        
075    /**
076     * The symbol of this prefix, as returned by {@link #getSymbol}.
077     *
078     * @serial
079     * @see #getSymbol()
080     */
081    private final String symbol;
082
083    /**
084     * Base part of the associated factor in base^exponent representation.
085     */
086    private final int base;
087    
088    /**
089     * Exponent part of the associated factor in base^exponent representation.
090     */
091    private final int exponent;
092
093    /**
094     * Creates a new prefix.
095     *
096     * @param symbol
097     *          the symbol of this prefix.
098     * @param exponent
099     *          part of the associated factor in base^exponent representation.
100     */
101    private IndianPrefix(String symbol, int base, int exponent) {
102        this.symbol = symbol;
103        this.base = base;
104        this.exponent = exponent;
105    }
106    
107    /**
108     * Base part of the associated factor in base^exponent representation. For metric prefix, this is always 10.
109     */
110    @Override
111    public Integer getValue() {
112        return base;
113    }
114    
115
116    /**
117     * Exponent part of the associated factor in base^exponent representation.
118     */
119    @Override
120    public int getExponent() {
121        return exponent;
122    }
123
124    /**
125     * Returns the name of this prefix.
126     *
127     * @return this prefix name, not {@code null}.
128     */
129    @Override
130    public String getName() {
131        return name();
132    }
133    
134    /**
135     * Returns the symbol of this prefix.
136     *
137     * @return this prefix symbol, not {@code null}.
138     */
139    @Override
140    public String getSymbol() {
141        return symbol;
142    }
143
144        /**
145         * <p>
146         * एक (Ek)
147         * </p>
148         * Returns the specified unit multiplied by the factor <code>1</code>
149         * 
150         * @param unit
151         *            any unit.
152         * @return <code>unit.times(1)</code>.
153         */
154        public static final <Q extends Quantity<Q>> Unit<Q> EK(Unit<Q> unit) {
155                return unit;
156        }
157
158        /**
159         * <p>
160         * दस (Das)
161         * </p>
162         * Returns the specified unit multiplied by the factor
163         * <code>10<sup>1</sup></code>
164         * 
165         * @param unit
166         *            any unit.
167         * @return <code>unit.times(10)</code>.
168         */
169        public static final <Q extends Quantity<Q>> Unit<Q> DAS(Unit<Q> unit) {
170                return unit.prefix(DAS);
171        }
172
173        /**
174         * <p>
175         * सौ (Sau)
176         * </p>
177         * Returns the specified unit multiplied by the factor
178         * <code>10<sup>2</sup></code>
179         * 
180         * @param unit
181         *            any unit.
182         * @return <code>unit.times(100)</code>.
183         */
184        public static final <Q extends Quantity<Q>> Unit<Q> SAU(Unit<Q> unit) {
185                return unit.prefix(SAU);
186        }
187
188        /**
189         * <p>
190         * सहस्र (Sahasr)
191         * </p>
192         * Returns the specified unit multiplied by the factor
193         * <code>10<sup>3</sup></code>
194         * 
195         * @param unit
196         *            any unit.
197         * @return <code>unit.times(1e3)</code>.
198         */
199        public static final <Q extends Quantity<Q>> Unit<Q> SAHASR(Unit<Q> unit) {
200                return unit.prefix(SAHASR);
201        }
202
203        /**
204         * <p>
205         * हजार (Hazaar)
206         * </p>
207         * Equivalent to {@link #SAHASR}.
208         */
209        public static final <Q extends Quantity<Q>> Unit<Q> HAZAAR(Unit<Q> unit) {
210                return SAHASR(unit);
211        }
212
213        /**
214         * <p>
215         * लाख (Lakh)
216         * </p>
217         * Returns the specified unit multiplied by the factor
218         * <code>10<sup>5</sup></code>
219         * 
220         * @param unit
221         *            any unit.
222         * @return <code>unit.times(1e5)</code>.
223         */
224        public static final <Q extends Quantity<Q>> Unit<Q> LAKH(Unit<Q> unit) {
225                return unit.prefix(LAKH);
226        }
227
228        /**
229         * <p>
230         * करोड़ (Crore)
231         * </p>
232         * Returns the specified unit multiplied by the factor
233         * <code>10<sup>7</sup></code>
234         * 
235         * @param unit
236         *            any unit.
237         * @return <code>unit.times(1e7)</code>.
238         */
239        public static final <Q extends Quantity<Q>> Unit<Q> CRORE(Unit<Q> unit) {
240                return unit.prefix(CRORE);
241        }
242
243        /**
244         * <p>
245         * अरब (Arawb)
246         * </p>
247         * Returns the specified unit multiplied by the factor
248         * <code>10<sup>9</sup></code>
249         * 
250         * @param unit
251         *            any unit.
252         * @return <code>unit.times(1e9)</code>.
253         */
254        public static final <Q extends Quantity<Q>> Unit<Q> ARAWB(Unit<Q> unit) {
255                return unit.prefix(ARAWB);
256        }
257
258        /**
259         * <p>
260         * खरब (Kharawb)
261         * </p>
262         * Returns the specified unit multiplied by the factor
263         * <code>10<sup>11</sup></code>
264         * 
265         * @param unit
266         *            any unit.
267         * @return <code>unit.times(1e11)</code>.
268         */
269        public static final <Q extends Quantity<Q>> Unit<Q> KHARAWB(Unit<Q> unit) {
270                return unit.prefix(KHARAWB);
271        }
272
273        /**
274         * <p>
275         * नील (Neel)
276         * </p>
277         * Returns the specified unit multiplied by the factor
278         * <code>10<sup>13</sup></code>
279         * 
280         * @param unit
281         *            any unit.
282         * @return <code>unit.times(1e13)</code>.
283         */
284        public static final <Q extends Quantity<Q>> Unit<Q> NEEL(Unit<Q> unit) {
285                return unit.prefix(NEEL);
286        }
287
288        /**
289         * <p>
290         * पद्म (Padma)
291         * </p>
292         * Returns the specified unit multiplied by the factor
293         * <code>10<sup>15</sup></code>
294         * 
295         * @param unit
296         *            any unit.
297         * @return <code>unit.times(1e15)</code>.
298         */
299        public static final <Q extends Quantity<Q>> Unit<Q> PADMA(Unit<Q> unit) {
300                return unit.prefix(PADMA);
301        }
302
303        /**
304         * <p>
305         * शंख (Shankh)
306         * </p>
307         * Returns the specified unit multiplied by the factor
308         * <code>10<sup>17</sup></code>
309         * 
310         * @param unit
311         *            any unit.
312         * @return <code>unit.times(1e17)</code>.
313         */
314        public static final <Q extends Quantity<Q>> Unit<Q> SHANKH(Unit<Q> unit) {
315                return unit.prefix(SHANKH);
316        }
317
318        /**
319         * <p>
320         * महाशंख (Mahashankh)
321         * </p>
322         * Returns the specified unit multiplied by the factor
323         * <code>10<sup>19</sup></code>
324         * 
325         * @param unit
326         *            any unit.
327         * @return <code>unit.times(1e19)</code>.
328         */
329        public static final <Q extends Quantity<Q>> Unit<Q> MAHASHANKH(Unit<Q> unit) {
330                return unit.prefix(MAHASHANKH);
331        }
332}