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