1 package org.djunits.quantity;
2
3 import org.djunits.quantity.def.Quantity;
4 import org.djunits.unit.AbstractUnit;
5 import org.djunits.unit.UnitInterface;
6 import org.djunits.unit.UnitRuntimeException;
7 import org.djunits.unit.Unitless;
8 import org.djunits.unit.scale.IdentityScale;
9 import org.djunits.unit.scale.LinearScale;
10 import org.djunits.unit.scale.Scale;
11 import org.djunits.unit.si.SIPrefix;
12 import org.djunits.unit.si.SIPrefixes;
13 import org.djunits.unit.si.SIUnit;
14 import org.djunits.unit.system.UnitSystem;
15
16 /**
17 * Luminous intensity is the luminous flux emitted per unit solid angle, measured in candelas (cd).
18 * <p>
19 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
20 * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
21 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
22 * @author Alexander Verbraeck
23 */
24 public class LuminousIntensity extends Quantity<LuminousIntensity>
25 {
26 /** Constant with value zero. */
27 public static final LuminousIntensity ZERO = ofSi(0.0);
28
29 /** Constant with value one. */
30 public static final LuminousIntensity ONE = ofSi(1.0);
31
32 /** Constant with value NaN. */
33 @SuppressWarnings("checkstyle:constantname")
34 public static final LuminousIntensity NaN = ofSi(Double.NaN);
35
36 /** Constant with value POSITIVE_INFINITY. */
37 public static final LuminousIntensity POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
38
39 /** Constant with value NEGATIVE_INFINITY. */
40 public static final LuminousIntensity NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
41
42 /** Constant with value MAX_VALUE. */
43 public static final LuminousIntensity POS_MAXVALUE = ofSi(Double.MAX_VALUE);
44
45 /** Constant with value -MAX_VALUE. */
46 public static final LuminousIntensity NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
47
48 /** */
49 private static final long serialVersionUID = 600L;
50
51 /**
52 * Instantiate a LuminousIntensity quantity with an SI or base value and a display unit.
53 * @param value the quantity value expressed in the SI or base unit
54 * @param displayUnit the display unit to use
55 * @param useSi use SI value when true, use value in unit when false
56 */
57 public LuminousIntensity(final double value, final LuminousIntensity.Unit displayUnit, final boolean useSi)
58 {
59 super(value, displayUnit, useSi);
60 }
61
62 /**
63 * Instantiate a LuminousIntensity quantity expressed in the given unit.
64 * @param valueInUnit the quantity value expressed in the given unit
65 * @param unit the unit of the value, also acts as the display unit
66 */
67 public LuminousIntensity(final double valueInUnit, final LuminousIntensity.Unit unit)
68 {
69 this(valueInUnit, unit, false);
70 }
71
72 /**
73 * Return a LuminousIntensity instance based on an SI value.
74 * @param si the si value
75 * @return the LuminousIntensity instance based on an SI value
76 */
77 public static LuminousIntensity ofSi(final double si)
78 {
79 return new LuminousIntensity(si, LuminousIntensity.Unit.SI, true);
80 }
81
82 /**
83 * Instantiate a LuminousIntensity quantity with an SI or base value and a display unit.
84 * @param siValue the quantity value expressed in the SI or base unit
85 * @param displayUnit the display unit to use
86 * @return the LuminousIntensity instance based on an SI value with the given display unit
87 */
88 public static LuminousIntensity ofSi(final double siValue, final LuminousIntensity.Unit displayUnit)
89 {
90 return new LuminousIntensity(siValue, displayUnit, true);
91 }
92
93 @Override
94 public LuminousIntensity instantiateSi(final double siValue, final UnitInterface<LuminousIntensity> displayUnit)
95 {
96 return new LuminousIntensity(siValue, (LuminousIntensity.Unit) displayUnit, true);
97 }
98
99 /**
100 * Returns a LuminousIntensity representation of a textual representation of a value with a unit. The String representation
101 * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
102 * are allowed, but not required, between the value and the unit.
103 * @param text the textual representation to parse into a LuminousIntensity
104 * @return the Scalar representation of the value in its unit
105 * @throws IllegalArgumentException when the text cannot be parsed
106 * @throws NullPointerException when the text argument is null
107 */
108 public static LuminousIntensity valueOf(final String text)
109 {
110 return Quantity.valueOf(text, ZERO);
111 }
112
113 /**
114 * Returns a LuminousIntensity based on a value expressed in the unit.
115 * @param valueInUnit the value, expressed in the given unit
116 * @param unit the unit of the value, also acts as the display unit
117 * @return ab LuminousIntensity representation of the value in its unit
118 */
119 public static LuminousIntensity of(final double valueInUnit, final LuminousIntensity.Unit unit)
120 {
121 return new LuminousIntensity(valueInUnit, unit);
122 }
123
124 /**
125 * Returns a LuminousIntensity based on a value and the textual representation of the unit, which can be localized.
126 * @param valueInUnit the value, expressed in the unit as given by unitString
127 * @param unitString the textual representation of the unit
128 * @return the Scalar representation of the value in its unit
129 * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
130 * @throws NullPointerException when the unitString argument is null
131 */
132 public static LuminousIntensity of(final double valueInUnit, final String unitString)
133 {
134 return Quantity.of(valueInUnit, unitString, ZERO);
135 }
136
137 @Override
138 public LuminousIntensity.Unit getDisplayUnit()
139 {
140 return (LuminousIntensity.Unit) super.getDisplayUnit();
141 }
142
143 /**
144 * Calculate the division of LuminousIntensity and LuminousIntensity, which results in a Dimensionless quantity.
145 * @param v quantity
146 * @return quantity as a division of LuminousIntensity and LuminousIntensity
147 */
148 public Dimensionless divide(final LuminousIntensity v)
149 {
150 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
151 }
152
153 /**
154 * Calculate the multiplication of LuminousIntensity and SolidAngle, which results in a LuminousFlux scalar.
155 * @param v scalar
156 * @return scalar as a multiplication of LuminousIntensity and SolidAngle
157 */
158 public LuminousFlux multiply(final SolidAngle v)
159 {
160 return new LuminousFlux(this.si() * v.si(), LuminousFlux.Unit.SI);
161 }
162
163 /******************************************************************************************************/
164 /********************************************** UNIT CLASS ********************************************/
165 /******************************************************************************************************/
166
167 /**
168 * LuminousIntensity.Unit encodes the units of luminous flux emitted per unit solid angle.
169 * <p>
170 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
171 * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
172 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
173 * @author Alexander Verbraeck
174 */
175 @SuppressWarnings("checkstyle:constantname")
176 public static class Unit extends AbstractUnit<LuminousIntensity>
177 {
178 /** The dimensions of the luminous flux emitted per unit solid angle: cd. */
179 public static final SIUnit SI_UNIT = SIUnit.of("cd");
180
181 /** Candela. */
182 public static final LuminousIntensity.Unit cd = new LuminousIntensity.Unit("cd", "cd", "candela", IdentityScale.SCALE,
183 UnitSystem.SI_BASE, SIPrefixes.getSiPrefix(""));
184
185 /** The SI or BASE unit. */
186 public static final LuminousIntensity.Unit SI = (Unit) cd.generateSiPrefixes(false, false);
187
188 /**
189 * Create a new LuminousIntensity unit.
190 * @param id the id or main abbreviation of the unit
191 * @param name the full name of the unit
192 * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
193 * @param unitSystem the unit system such as SI or IMPERIAL
194 */
195 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
196 {
197 super(id, name, scaleFactorToBaseUnit, unitSystem);
198 }
199
200 /**
201 * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
202 * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
203 * @param displayAbbreviation the display abbreviation of the unit
204 * @param name the full name of the unit
205 * @param scale the scale to use to convert from this unit to the standard (e.g., SI, BASE) unit
206 * @param unitSystem unit system, e.g. SI or Imperial
207 * @param siPrefix the SI Prefix of this unit
208 */
209 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
210 final UnitSystem unitSystem, final SIPrefix siPrefix)
211 {
212 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem, siPrefix);
213 }
214
215 @Override
216 public SIUnit siUnit()
217 {
218 return SI_UNIT;
219 }
220
221 @Override
222 public Unit getBaseUnit()
223 {
224 return SI;
225 }
226
227 @Override
228 public LuminousIntensity ofSi(final double si, final UnitInterface<LuminousIntensity> displayUnit)
229 {
230 return new LuminousIntensity(si, (Unit) displayUnit, true);
231 }
232
233 @Override
234 public LuminousIntensity.Unit deriveUnit(final String abbreviation, final String name, final double scaleFactor,
235 final UnitSystem unitSystem)
236 {
237 return (Unit) super.deriveUnit(abbreviation, name, scaleFactor, unitSystem);
238 }
239
240 @Override
241 public LuminousIntensity.Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation,
242 final String name, final double scaleFactor, final UnitSystem unitSystem, final SIPrefix siPrefix)
243 {
244 if (getScale() instanceof LinearScale ls)
245 {
246 return new LuminousIntensity.Unit(textualAbbreviation, displayAbbreviation, name,
247 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem, siPrefix);
248 }
249 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
250 }
251
252 }
253
254 }