View Javadoc
1   package org.djunits.unit.si;
2   
3   import org.djutils.exceptions.Throw;
4   
5   /**
6    * SIPrefix contains information about one prefix, such as M for mega with the value 1.0E6.
7    * <p>
8    * Copyright (c) 2019-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
9    * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>
10   * @author Alexander Verbraeck
11   */
12  public class SIPrefix
13  {
14      /** The default textual prefix abbreviation, such as "M" for mega and "da" for deca. */
15      private final String defaultTextualPrefix;
16  
17      /** The default display prefix abbreviation, such as "\u03BC" for micro. */
18      private final String defaultDisplayPrefix;
19  
20      /** The prefix name such as "mega" or "deca". */
21      private final String prefixName;
22  
23      /** The exponent that the SI prefix represents, such as 6 for mega. */
24      private final int exponent;
25  
26      /** The factor that the SI prefix represents, such as 1.0E6 for mega. */
27      private final double factor;
28  
29      /** The type of SI prefix. */
30      private final PrefixType type;
31  
32      /**
33       * Construct an SI prefix.
34       * @param defaultTextualPrefix the prefix abbreviation, such as "M" for mega and "da" for deca
35       * @param prefixName the prefix name such as "mega" or "deca"
36       * @param exponent the exponent that the SI prefix represents, such as 6 for mega
37       * @param defaultDisplayPrefix "\u03BC" for micro
38       * @param type the prefix type, e.g., KILO
39       */
40      public SIPrefix(final String defaultTextualPrefix, final String prefixName, final int exponent,
41              final String defaultDisplayPrefix, final PrefixType type)
42      {
43          Throw.whenNull(defaultTextualPrefix, "SIPrefix.defaultTextualPrefix cannot be null");
44          Throw.whenNull(prefixName, "SIPrefix.prefixName cannot be null");
45          Throw.whenNull(defaultDisplayPrefix, "SIPrefix.defaultDisplayPrefix cannot be null");
46          Throw.whenNull(type, "SIPrefix.type cannot be null");
47          this.defaultTextualPrefix = defaultTextualPrefix;
48          this.prefixName = prefixName;
49          this.exponent = exponent;
50          this.factor = Math.pow(10.0, exponent);
51          this.defaultDisplayPrefix = defaultDisplayPrefix;
52          this.type = type;
53      }
54  
55      /**
56       * Construct an SI prefix with the defaultDisplayPrefix equal to the defaultTextualPrefix.
57       * @param defaultTextualPrefix the prefix abbreviation, such as "M" for mega and "da" for deca
58       * @param prefixName the prefix name such as "mega" or "deca"
59       * @param exponent the exponent that the SI prefix represents, such as 6 for mega
60       * @param type the prefix type, e.g., KILO
61       */
62      public SIPrefix(final String defaultTextualPrefix, final String prefixName, final int exponent, final PrefixType type)
63      {
64          this(defaultTextualPrefix, prefixName, exponent, defaultTextualPrefix, type);
65      }
66  
67      /**
68       * Retrieve the default textual prefix.
69       * @return the default textual prefix
70       */
71      public String getDefaultTextualPrefix()
72      {
73          return this.defaultTextualPrefix;
74      }
75  
76      /**
77       * Retrieve the prefix name.
78       * @return the prefix name
79       */
80      public String getPrefixName()
81      {
82          return this.prefixName;
83      }
84  
85      /**
86       * Retrieve the exponent.
87       * @return the exponent
88       */
89      public int getExponent()
90      {
91          return this.exponent;
92      }
93  
94      /**
95       * Retrieve the factor.
96       * @return the factor
97       */
98      public double getFactor()
99      {
100         return this.factor;
101     }
102 
103     /**
104      * Retrieve the default display prefix.
105      * @return the default display prefix
106      */
107     public String getDefaultDisplayPrefix()
108     {
109         return this.defaultDisplayPrefix;
110     }
111 
112     /**
113      * Retrieve the type.
114      * @return the type
115      */
116     public PrefixType getType()
117     {
118         return this.type;
119     }
120 
121     @Override
122     public String toString()
123     {
124         return "SIPrefix [type=" + this.type + ", defaultTextualPrefix=" + this.defaultTextualPrefix + ", defaultDisplayPrefix="
125                 + this.defaultDisplayPrefix + ", prefixName=" + this.prefixName + ", exponent=" + this.exponent + ", factor="
126                 + this.factor + "]";
127     }
128 
129 }