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 /**
27 * Construct an SI prefix.
28 * @param defaultTextualPrefix the prefix abbreviation, duch as "M" for mega and "da" for deca
29 * @param prefixName the prefix name such as "mega" or "deca"
30 * @param factor the factor that the SI prefix represents, such as 1.0E6 for mega
31 * @param defaultDisplayPrefix "\u03BC" for micro
32 */
33 public SIPrefix(final String defaultTextualPrefix, final String prefixName, final double factor,
34 final String defaultDisplayPrefix)
35 {
36 Throw.whenNull(defaultTextualPrefix, "SIPrefix.defaultTextualPrefix cannot be null");
37 Throw.whenNull(prefixName, "SIPrefix.prefixName cannot be null");
38 Throw.whenNull(defaultDisplayPrefix, "SIPrefix.defaultDisplayPrefix cannot be null");
39 Throw.when(factor == 0, IllegalArgumentException.class, "SIPrefix.factor cannot be 0");
40 this.defaultTextualPrefix = defaultTextualPrefix;
41 this.prefixName = prefixName;
42 this.factor = factor;
43 this.defaultDisplayPrefix = defaultDisplayPrefix;
44 }
45
46 /**
47 * Construct an SI prefix with the defaultDisplayPrefix equal to the defaultTextualPrefix.
48 * @param defaultTextualPrefix the prefix abbreviation, duch as "M" for mega and "da" for deca
49 * @param prefixName the prefix name such as "mega" or "deca"
50 * @param factor the factor that the SI prefix represents, such as 1.0E6 for mega
51 */
52 public SIPrefix(final String defaultTextualPrefix, final String prefixName, final double factor)
53 {
54 this(defaultTextualPrefix, prefixName, factor, defaultTextualPrefix);
55 }
56
57 /**
58 * Retrieve the default textual prefix.
59 * @return the default textual prefix
60 */
61 public String getDefaultTextualPrefix()
62 {
63 return this.defaultTextualPrefix;
64 }
65
66 /**
67 * Retrieve the prefix name.
68 * @return the prefix name
69 */
70 public String getPrefixName()
71 {
72 return this.prefixName;
73 }
74
75 /**
76 * Retrieve the factor.
77 * @return the factor
78 */
79 public double getFactor()
80 {
81 return this.factor;
82 }
83
84 /**
85 * Retrieve the default display prefix.
86 * @return the default display prefix
87 */
88 public String getDefaultDisplayPrefix()
89 {
90 return this.defaultDisplayPrefix;
91 }
92
93 @Override
94 public String toString()
95 {
96 return "SIPrefix [defaultTextualPrefix=" + this.defaultTextualPrefix + ", defaultDisplayPrefix="
97 + this.defaultDisplayPrefix + ", prefixName=" + this.prefixName + ", factor=" + this.factor + "]";
98 }
99
100 }