View Javadoc
1   package org.djunits.unit.si;
2   
3   import java.util.LinkedHashMap;
4   import java.util.Map;
5   
6   /**
7    * Useful sets of SI prefixes.
8    * <p>
9    * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>
11   * </p>
12   * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
13   */
14  public enum SIPrefixes
15  {
16      /** No SI prefixes allowed. E.g., for the "inch". */
17      NONE,
18  
19      /** All standard SI prefixes allowed. E.g., for the "meter". */
20      UNIT,
21  
22      /** All SI prefixes indicating larger than 1. E.g., for the electronVolt to avoid underflow with float values. */
23      UNIT_POS,
24  
25      /** All standard SI prefixes allowed for "per unit". E.g., for the "per second". */
26      PER_UNIT,
27  
28      /** SI prefixes allowed, but default starts with "kilo" / "k", e.g., for the "kilogram". */
29      KILO;
30  
31      /** The SI prefixes and their values for the "UNIT" settings. */
32      public static final Map<String, SIPrefix> UNIT_PREFIXES = new LinkedHashMap<>();
33  
34      /** The SI prefixes and their values for the "PER_UNIT" settings. */
35      public static final Map<String, SIPrefix> PER_UNIT_PREFIXES = new LinkedHashMap<>();
36  
37      /** The larger than 1 SI prefixes and their values for the "UNIT_POS" settings. */
38      public static final Map<String, SIPrefix> UNIT_POS_PREFIXES = new LinkedHashMap<>();
39  
40      /** The SI prefixes and their values for the "KILO" settings. */
41      public static final Map<String, SIPrefix> KILO_PREFIXES = new LinkedHashMap<>();
42  
43      static
44      {
45          UNIT_PREFIXES.put("y", new SIPrefix("y", "yocto", 1.0E-24));
46          UNIT_PREFIXES.put("z", new SIPrefix("z", "zepto", 1.0E-21));
47          UNIT_PREFIXES.put("a", new SIPrefix("a", "atto", 1.0E-18));
48          UNIT_PREFIXES.put("f", new SIPrefix("f", "femto", 1.0E-15));
49          UNIT_PREFIXES.put("p", new SIPrefix("p", "pico", 1.0E-12));
50          UNIT_PREFIXES.put("n", new SIPrefix("n", "nano", 1.0E-9));
51          UNIT_PREFIXES.put("mu", new SIPrefix("mu", "micro", 1.0E-6, "\u03BC"));
52          UNIT_PREFIXES.put("m", new SIPrefix("m", "milli", 1.0E-3));
53          UNIT_PREFIXES.put("c", new SIPrefix("c", "centi", 1.0E-2));
54          UNIT_PREFIXES.put("d", new SIPrefix("d", "deci", 1.0E-1));
55  
56          UNIT_PREFIXES.put("da", new SIPrefix("da", "deca", 1.0E1));
57          UNIT_PREFIXES.put("h", new SIPrefix("h", "hecto", 1.0E2));
58          UNIT_PREFIXES.put("k", new SIPrefix("k", "kilo", 1.0E3));
59          UNIT_PREFIXES.put("M", new SIPrefix("M", "mega", 1.0E6));
60          UNIT_PREFIXES.put("G", new SIPrefix("G", "giga", 1.0E9));
61          UNIT_PREFIXES.put("T", new SIPrefix("T", "tera", 1.0E12));
62          UNIT_PREFIXES.put("P", new SIPrefix("P", "peta", 1.0E15));
63          UNIT_PREFIXES.put("E", new SIPrefix("E", "exa", 1.0E18));
64          UNIT_PREFIXES.put("Z", new SIPrefix("Z", "zetta", 1.0E21));
65          UNIT_PREFIXES.put("Y", new SIPrefix("Y", "yotta", 1.0E24));
66  
67          PER_UNIT_PREFIXES.put("/y", new SIPrefix("/y", "per yocto", 1.0E24));
68          PER_UNIT_PREFIXES.put("/z", new SIPrefix("/z", "per zepto", 1.0E21));
69          PER_UNIT_PREFIXES.put("/a", new SIPrefix("/a", "per atto", 1.0E18));
70          PER_UNIT_PREFIXES.put("/f", new SIPrefix("/f", "per femto", 1.0E15));
71          PER_UNIT_PREFIXES.put("/p", new SIPrefix("/p", "per pico", 1.0E12));
72          PER_UNIT_PREFIXES.put("/n", new SIPrefix("/n", "per nano", 1.0E9));
73          PER_UNIT_PREFIXES.put("/mu", new SIPrefix("/mu", "per micro", 1.0E6, "/\u03BC"));
74          PER_UNIT_PREFIXES.put("/m", new SIPrefix("/m", "per milli", 1.0E3));
75          PER_UNIT_PREFIXES.put("/c", new SIPrefix("/c", "per centi", 1.0E2));
76          PER_UNIT_PREFIXES.put("/d", new SIPrefix("/d", "per deci", 1.0E1));
77  
78          PER_UNIT_PREFIXES.put("/da", new SIPrefix("/da", "per deca", 1.0E-1));
79          PER_UNIT_PREFIXES.put("/h", new SIPrefix("/h", "per hecto", 1.0E-2));
80          PER_UNIT_PREFIXES.put("/k", new SIPrefix("/k", "per kilo", 1.0E-3));
81          PER_UNIT_PREFIXES.put("/M", new SIPrefix("/M", "per mega", 1.0E-6));
82          PER_UNIT_PREFIXES.put("/G", new SIPrefix("/G", "per giga", 1.0E-9));
83          PER_UNIT_PREFIXES.put("/T", new SIPrefix("/T", "per tera", 1.0E-12));
84          PER_UNIT_PREFIXES.put("/P", new SIPrefix("/P", "per peta", 1.0E-15));
85          PER_UNIT_PREFIXES.put("/E", new SIPrefix("/E", "per exa", 1.0E-18));
86          PER_UNIT_PREFIXES.put("/Z", new SIPrefix("/Z", "per zetta", 1.0E-21));
87          PER_UNIT_PREFIXES.put("/Y", new SIPrefix("/Y", "per yotta", 1.0E-24));
88  
89          UNIT_POS_PREFIXES.put("da", new SIPrefix("da", "deca", 1.0E1));
90          UNIT_POS_PREFIXES.put("h", new SIPrefix("h", "hecto", 1.0E2));
91          UNIT_POS_PREFIXES.put("k", new SIPrefix("k", "kilo", 1.0E3));
92          UNIT_POS_PREFIXES.put("M", new SIPrefix("M", "mega", 1.0E6));
93          UNIT_POS_PREFIXES.put("G", new SIPrefix("G", "giga", 1.0E9));
94          UNIT_POS_PREFIXES.put("T", new SIPrefix("T", "tera", 1.0E12));
95          UNIT_POS_PREFIXES.put("P", new SIPrefix("P", "peta", 1.0E15));
96          UNIT_POS_PREFIXES.put("E", new SIPrefix("E", "exa", 1.0E18));
97          UNIT_POS_PREFIXES.put("Z", new SIPrefix("Z", "zetta", 1.0E21));
98          UNIT_POS_PREFIXES.put("Y", new SIPrefix("Y", "yotta", 1.0E24));
99  
100         KILO_PREFIXES.put("y", new SIPrefix("y", "yocto", 1.0E-27));
101         KILO_PREFIXES.put("z", new SIPrefix("z", "zepto", 1.0E-24));
102         KILO_PREFIXES.put("a", new SIPrefix("a", "atto", 1.0E-21));
103         KILO_PREFIXES.put("f", new SIPrefix("f", "femto", 1.0E-18));
104         KILO_PREFIXES.put("p", new SIPrefix("p", "pico", 1.0E-15));
105         KILO_PREFIXES.put("n", new SIPrefix("n", "nano", 1.0E-12));
106         KILO_PREFIXES.put("mu", new SIPrefix("mu", "micro", 1.0E-9, "\u03BC"));
107         KILO_PREFIXES.put("m", new SIPrefix("m", "milli", 1.0E-6));
108         KILO_PREFIXES.put("c", new SIPrefix("c", "centi", 1.0E-5));
109         KILO_PREFIXES.put("d", new SIPrefix("d", "deci", 1.0E-4));
110         KILO_PREFIXES.put("", new SIPrefix("", "", 1.0E-3));
111         KILO_PREFIXES.put("da", new SIPrefix("da", "deca", 1.0E-2));
112         KILO_PREFIXES.put("h", new SIPrefix("h", "hecto", 1.0E-1));
113 
114         KILO_PREFIXES.put("M", new SIPrefix("M", "mega", 1.0E3));
115         KILO_PREFIXES.put("G", new SIPrefix("G", "giga", 1.0E6));
116         KILO_PREFIXES.put("T", new SIPrefix("T", "tera", 1.0E9));
117         KILO_PREFIXES.put("P", new SIPrefix("P", "peta", 1.0E12));
118         KILO_PREFIXES.put("E", new SIPrefix("E", "exa", 1.0E15));
119         KILO_PREFIXES.put("Z", new SIPrefix("Z", "zetta", 1.0E18));
120         KILO_PREFIXES.put("Y", new SIPrefix("Y", "yotta", 1.0E21));
121     }
122 
123     /**
124      * Look up and return the prefix information for the given prefix key (e.g., "G" for "giga").
125      * @param prefixKey String; the prefix key, e.g., "G" for "giga"
126      * @return SIPrefix; the SIPrefix information, or null if the <code>prefixKey</code> does not exist
127      */
128     public static SIPrefix getUnit(final String prefixKey)
129     {
130         return UNIT_PREFIXES.get(prefixKey);
131     }
132 
133     /**
134      * Look up and return the prefix information for the given prefix key (e.g., "/n" for "per nano").
135      * @param prefixKey String; the prefix key, e.g., "/n" for "per nano"
136      * @return SIPrefix; the SIPrefix information, or null if the <code>prefixKey</code> does not exist
137      */
138     public static SIPrefix getPerUnit(final String prefixKey)
139     {
140         return PER_UNIT_PREFIXES.get(prefixKey);
141     }
142 
143     /**
144      * Return the prefix information for the given prefix key (e.g., "G" for "giga"), with an offset of a factor 1000 for units
145      * that have "kilo" as the default.
146      * @param prefixKey String; the prefix key, e.g., "G" for "giga"
147      * @return SIPrefix; the SIPrefix information, with an offset of 1000. So "k" will return 1, and "" will return 1.0E-3.
148      */
149     public static SIPrefix getKiloUnit(final String prefixKey)
150     {
151         return KILO_PREFIXES.get(prefixKey);
152     }
153 
154 }