1 package org.djunits.quantity;
2
3 import org.djunits.quantity.def.Quantity;
4 import org.djunits.unit.Unitless;
5 import org.djunits.unit.Units;
6 import org.djunits.unit.si.SIUnit;
7
8 /**
9 * Dimensionless quantity.
10 * <p>
11 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
12 * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
13 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
14 * @author Alexander Verbraeck
15 */
16 public class Dimensionless extends Quantity<Dimensionless, Unitless>
17 {
18 /** Constant with value zero. */
19 public static final Dimensionless ZERO = Dimensionless.ofSi(0.0);
20
21 /** Constant with value one. */
22 public static final Dimensionless ONE = Dimensionless.ofSi(1.0);
23
24 /** Constant with value NaN. */
25 @SuppressWarnings("checkstyle:constantname")
26 public static final Dimensionless NaN = Dimensionless.ofSi(Double.NaN);
27
28 /** Constant with value POSITIVE_INFINITY. */
29 public static final Dimensionless POSITIVE_INFINITY = Dimensionless.ofSi(Double.POSITIVE_INFINITY);
30
31 /** Constant with value NEGATIVE_INFINITY. */
32 public static final Dimensionless NEGATIVE_INFINITY = Dimensionless.ofSi(Double.NEGATIVE_INFINITY);
33
34 /** Constant with value MAX_VALUE. */
35 public static final Dimensionless POS_MAXVALUE = Dimensionless.ofSi(Double.MAX_VALUE);
36
37 /** Constant with value -MAX_VALUE. */
38 public static final Dimensionless NEG_MAXVALUE = Dimensionless.ofSi(-Double.MAX_VALUE);
39
40 /** */
41 private static final long serialVersionUID = 600L;
42
43 /**
44 * Instantiate a Dimensionless quantity with a unit.
45 * @param value the value, expressed in the unit
46 * @param unit the unit in which the value is expressed
47 */
48 public Dimensionless(final double value, final Unitless unit)
49 {
50 super(value, unit);
51 }
52
53 /**
54 * Instantiate a Dimensionless quantity with a unit, expressed as a String.
55 * @param value the value, expressed in the unit
56 * @param abbreviation the String abbreviation of the unit in which the value is expressed
57 */
58 public Dimensionless(final double value, final String abbreviation)
59 {
60 this(value, Units.resolve(Unitless.class, abbreviation));
61 }
62
63 /**
64 * Construct Dimensionless quantity.
65 * @param value Scalar from which to construct this instance
66 */
67 public Dimensionless(final Dimensionless value)
68 {
69 super(value.si(), Unitless.BASE);
70 setDisplayUnit(value.getDisplayUnit());
71 }
72
73 /**
74 * Return a Dimensionless instance based on an SI value.
75 * @param si the si value
76 * @return the Dimensionless instance based on an SI value
77 */
78 public static Dimensionless ofSi(final double si)
79 {
80 return new Dimensionless(si, Unitless.BASE);
81 }
82
83 @Override
84 public Dimensionless instantiate(final double si)
85 {
86 return ofSi(si);
87 }
88
89 @Override
90 public SIUnit siUnit()
91 {
92 return Unitless.SI_UNIT;
93 }
94
95 /**
96 * Returns a Dimensionless representation of a textual representation of a value with a unit. The String representation that
97 * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
98 * allowed, but not required, between the value and the unit.
99 * @param text the textual representation to parse into a Dimensionless
100 * @return the Scalar representation of the value in its unit
101 * @throws IllegalArgumentException when the text cannot be parsed
102 * @throws NullPointerException when the text argument is null
103 */
104 public static Dimensionless valueOf(final String text)
105 {
106 return Quantity.valueOf(text, ZERO);
107 }
108
109 /**
110 * Returns a Dimensionless based on a value and the textual representation of the unit, which can be localized.
111 * @param value the value to use
112 * @param unitString the textual representation of the unit
113 * @return the Scalar representation of the value in its unit
114 * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
115 * @throws NullPointerException when the unitString argument is null
116 */
117 public static Dimensionless of(final double value, final String unitString)
118 {
119 return Quantity.of(value, unitString, ZERO);
120 }
121
122 /**
123 * Calculate the division of Dimensionless and Dimensionless, which results in a Dimensionless quantity.
124 * @param v quantity
125 * @return quantity as a division of Dimensionless and Dimensionless
126 */
127 public final Dimensionless divide(final Dimensionless v)
128 {
129 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
130 }
131
132 /**
133 * Calculate the division of Dimensionless and Length, which results in a LinearObjectDensity scalar.
134 * @param v scalar
135 * @return scalar as a division of Dimensionless and Length
136 */
137 public final LinearObjectDensity divide(final Length v)
138 {
139 return new LinearObjectDensity(this.si() / v.si(), LinearObjectDensity.Unit.SI);
140 }
141
142 /**
143 * Calculate the division of Dimensionless and LinearObjectDensity, which results in a Length scalar.
144 * @param v scalar
145 * @return scalar as a division of Dimensionless and LinearObjectDensity
146 */
147 public final Length divide(final LinearObjectDensity v)
148 {
149 return new Length(this.si() / v.si(), Length.Unit.SI);
150 }
151
152 /**
153 * Calculate the division of Dimensionless and Duration, which results in a Frequency scalar.
154 * @param v scalar
155 * @return scalar as a division of Dimensionless and Duration
156 */
157 public final Frequency divide(final Duration v)
158 {
159 return new Frequency(this.si() / v.si(), Frequency.Unit.SI);
160 }
161
162 /**
163 * Calculate the division of Dimensionless and Frequency, which results in a Duration scalar.
164 * @param v scalar
165 * @return scalar as a division of Dimensionless and Frequency
166 */
167 public final Duration divide(final Frequency v)
168 {
169 return new Duration(this.si() / v.si(), Duration.Unit.SI);
170 }
171
172 /**
173 * Calculate the division of Dimensionless and ElectricalConductance, which results in a ElectricalResistance scalar.
174 * @param v scalar
175 * @return scalar as a division of Dimensionless and ElectricalConductance
176 */
177 public final ElectricalResistance divide(final ElectricalConductance v)
178 {
179 return new ElectricalResistance(this.si() / v.si(), ElectricalResistance.Unit.SI);
180 }
181
182 /**
183 * Calculate the division of Dimensionless and ElectricalResistance, which results in a ElectricalConductance scalar.
184 * @param v scalar
185 * @return scalar as a division of Dimensionless and ElectricalResistance
186 */
187 public final ElectricalConductance divide(final ElectricalResistance v)
188 {
189 return new ElectricalConductance(this.si() / v.si(), ElectricalConductance.Unit.SI);
190 }
191
192 @Override
193 public Dimensionless reciprocal()
194 {
195 return Dimensionless.ofSi(1.0 / this.si());
196 }
197
198 }