1 package org.djunits.unit.si;
2
3 import java.io.Serializable;
4
5 import org.djutils.exceptions.Throw;
6
7 /**
8 * SIPrefix contains information about one prefix, such as M for mega with the value 1.0E6.
9 * <p>
10 * Copyright (c) 2019-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>
12 * </p>
13 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
14 */
15 public class SIPrefix implements Serializable
16 {
17 /** */
18 private static final long serialVersionUID = 20190821L;
19
20 /** The default textual prefix abbreviation, such as "M" for mega and "da" for deca. */
21 private final String defaultTextualPrefix;
22
23 /** The default display prefix abbreviation, such as "\u03BC" for micro. */
24 private final String defaultDisplayPrefix;
25
26 /** The prefix name such as "mega" or "deca". */
27 private final String prefixName;
28
29 /** The factor that the SI prefix represents, such as 1.0E6 for mega. */
30 private final double factor;
31
32 /**
33 * Construct an SI prefix.
34 * @param defaultTextualPrefix the prefix abbreviation, duch as "M" for mega and "da" for deca
35 * @param prefixName the prefix name such as "mega" or "deca"
36 * @param factor the factor that the SI prefix represents, such as 1.0E6 for mega
37 * @param defaultDisplayPrefix "\u03BC" for micro
38 */
39 public SIPrefix(final String defaultTextualPrefix, final String prefixName, final double factor,
40 final String defaultDisplayPrefix)
41 {
42 Throw.whenNull(defaultTextualPrefix, "SIPrefix.defaultTextualPrefix cannot be null");
43 Throw.whenNull(prefixName, "SIPrefix.prefixName cannot be null");
44 Throw.whenNull(defaultDisplayPrefix, "SIPrefix.defaultDisplayPrefix cannot be null");
45 Throw.when(factor == 0, SIRuntimeException.class, "SIPrefix.factor cannot be 0");
46 this.defaultTextualPrefix = defaultTextualPrefix;
47 this.prefixName = prefixName;
48 this.factor = factor;
49 this.defaultDisplayPrefix = defaultDisplayPrefix;
50 }
51
52 /**
53 * Construct an SI prefix with the defaultDisplayPrefix equal to the defaultTextualPrefix.
54 * @param defaultTextualPrefix the prefix abbreviation, duch as "M" for mega and "da" for deca
55 * @param prefixName the prefix name such as "mega" or "deca"
56 * @param factor the factor that the SI prefix represents, such as 1.0E6 for mega
57 */
58 public SIPrefix(final String defaultTextualPrefix, final String prefixName, final double factor)
59 {
60 this(defaultTextualPrefix, prefixName, factor, defaultTextualPrefix);
61 }
62
63 /**
64 * Retrieve the default textual prefix.
65 * @return the default textual prefix
66 */
67 public String getDefaultTextualPrefix()
68 {
69 return this.defaultTextualPrefix;
70 }
71
72 /**
73 * Retrieve the prefix name.
74 * @return the prefix name
75 */
76 public String getPrefixName()
77 {
78 return this.prefixName;
79 }
80
81 /**
82 * Retrieve the factor.
83 * @return the factor
84 */
85 public double getFactor()
86 {
87 return this.factor;
88 }
89
90 /**
91 * Retrieve the default display prefix.
92 * @return the default display prefix
93 */
94 public String getDefaultDisplayPrefix()
95 {
96 return this.defaultDisplayPrefix;
97 }
98
99 @Override
100 public String toString()
101 {
102 return "SIPrefix [defaultTextualPrefix=" + this.defaultTextualPrefix + ", defaultDisplayPrefix="
103 + this.defaultDisplayPrefix + ", prefixName=" + this.prefixName + ", factor=" + this.factor + "]";
104 }
105
106 }