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