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 factor that the SI prefix represents, such as 1.0E6 for mega. */
24 private final double factor;
25
26 /** The type of SI prefix. */
27 private final PrefixType type;
28
29 /**
30 * Construct an SI prefix.
31 * @param defaultTextualPrefix the prefix abbreviation, duch as "M" for mega and "da" for deca
32 * @param prefixName the prefix name such as "mega" or "deca"
33 * @param factor the factor that the SI prefix represents, such as 1.0E6 for mega
34 * @param defaultDisplayPrefix "\u03BC" for micro
35 * @param type the prefix type, e.g., KILO
36 */
37 public SIPrefix(final String defaultTextualPrefix, final String prefixName, final double factor,
38 final String defaultDisplayPrefix, final PrefixType type)
39 {
40 Throw.whenNull(defaultTextualPrefix, "SIPrefix.defaultTextualPrefix cannot be null");
41 Throw.whenNull(prefixName, "SIPrefix.prefixName cannot be null");
42 Throw.whenNull(defaultDisplayPrefix, "SIPrefix.defaultDisplayPrefix cannot be null");
43 Throw.whenNull(type, "SIPrefix.type cannot be null");
44 Throw.when(factor == 0, IllegalArgumentException.class, "SIPrefix.factor cannot be 0");
45 this.defaultTextualPrefix = defaultTextualPrefix;
46 this.prefixName = prefixName;
47 this.factor = factor;
48 this.defaultDisplayPrefix = defaultDisplayPrefix;
49 this.type = type;
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 * @param type the prefix type, e.g., KILO
58 */
59 public SIPrefix(final String defaultTextualPrefix, final String prefixName, final double factor, final PrefixType type)
60 {
61 this(defaultTextualPrefix, prefixName, factor, defaultTextualPrefix, type);
62 }
63
64 /**
65 * Retrieve the default textual prefix.
66 * @return the default textual prefix
67 */
68 public String getDefaultTextualPrefix()
69 {
70 return this.defaultTextualPrefix;
71 }
72
73 /**
74 * Retrieve the prefix name.
75 * @return the prefix name
76 */
77 public String getPrefixName()
78 {
79 return this.prefixName;
80 }
81
82 /**
83 * Retrieve the factor.
84 * @return the factor
85 */
86 public double getFactor()
87 {
88 return this.factor;
89 }
90
91 /**
92 * Retrieve the default display prefix.
93 * @return the default display prefix
94 */
95 public String getDefaultDisplayPrefix()
96 {
97 return this.defaultDisplayPrefix;
98 }
99
100 /**
101 * Retrieve the type.
102 * @return the type
103 */
104 public PrefixType getType()
105 {
106 return this.type;
107 }
108
109 @Override
110 public String toString()
111 {
112 return "SIPrefix [defaultTextualPrefix=" + this.defaultTextualPrefix + ", defaultDisplayPrefix="
113 + this.defaultDisplayPrefix + ", prefixName=" + this.prefixName + ", factor=" + this.factor + "]";
114 }
115
116 }