View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.unit.DurationUnit;
7   import org.djunits.unit.ElectricalCapacitanceUnit;
8   import org.djunits.unit.ElectricalChargeUnit;
9   import org.djunits.unit.ElectricalConductanceUnit;
10  import org.djunits.value.vdouble.scalar.base.DoubleScalar;
11  import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
12  import org.djutils.base.NumberParser;
13  import org.djutils.exceptions.Throw;
14  
15  import jakarta.annotation.Generated;
16  
17  /**
18   * Easy access methods for the ElectricalCapacitance DoubleScalar, which is relative by definition.
19   * <p>
20   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
22   * </p>
23   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
25   */
26  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
27  public class ElectricalCapacitance extends DoubleScalarRel<ElectricalCapacitanceUnit, ElectricalCapacitance>
28  {
29      /** */
30      private static final long serialVersionUID = 20150905L;
31  
32      /** Constant with value zero. */
33      public static final ElectricalCapacitance ZERO = new ElectricalCapacitance(0.0, ElectricalCapacitanceUnit.SI);
34  
35      /** Constant with value one. */
36      public static final ElectricalCapacitance ONE = new ElectricalCapacitance(1.0, ElectricalCapacitanceUnit.SI);
37  
38      /** Constant with value NaN. */
39      @SuppressWarnings("checkstyle:constantname")
40      public static final ElectricalCapacitance NaN = new ElectricalCapacitance(Double.NaN, ElectricalCapacitanceUnit.SI);
41  
42      /** Constant with value POSITIVE_INFINITY. */
43      public static final ElectricalCapacitance POSITIVE_INFINITY =
44              new ElectricalCapacitance(Double.POSITIVE_INFINITY, ElectricalCapacitanceUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final ElectricalCapacitance NEGATIVE_INFINITY =
48              new ElectricalCapacitance(Double.NEGATIVE_INFINITY, ElectricalCapacitanceUnit.SI);
49  
50      /** Constant with value MAX_VALUE. */
51      public static final ElectricalCapacitance POS_MAXVALUE =
52              new ElectricalCapacitance(Double.MAX_VALUE, ElectricalCapacitanceUnit.SI);
53  
54      /** Constant with value -MAX_VALUE. */
55      public static final ElectricalCapacitance NEG_MAXVALUE =
56              new ElectricalCapacitance(-Double.MAX_VALUE, ElectricalCapacitanceUnit.SI);
57  
58      /**
59       * Construct ElectricalCapacitance scalar.
60       * @param value double; the double value
61       * @param unit ElectricalCapacitanceUnit; unit for the double value
62       */
63      public ElectricalCapacitance(final double value, final ElectricalCapacitanceUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct ElectricalCapacitance scalar.
70       * @param value ElectricalCapacitance; Scalar from which to construct this instance
71       */
72      public ElectricalCapacitance(final ElectricalCapacitance value)
73      {
74          super(value);
75      }
76  
77      @Override
78      public final ElectricalCapacitance instantiateRel(final double value, final ElectricalCapacitanceUnit unit)
79      {
80          return new ElectricalCapacitance(value, unit);
81      }
82  
83      /**
84       * Construct ElectricalCapacitance scalar.
85       * @param value double; the double value in SI units
86       * @return ElectricalCapacitance; the new scalar with the SI value
87       */
88      public static final ElectricalCapacitance instantiateSI(final double value)
89      {
90          return new ElectricalCapacitance(value, ElectricalCapacitanceUnit.SI);
91      }
92  
93      /**
94       * Interpolate between two values.
95       * @param zero ElectricalCapacitance; the low value
96       * @param one ElectricalCapacitance; the high value
97       * @param ratio double; the ratio between 0 and 1, inclusive
98       * @return ElectricalCapacitance; a Scalar at the ratio between
99       */
100     public static ElectricalCapacitance interpolate(final ElectricalCapacitance zero, final ElectricalCapacitance one,
101             final double ratio)
102     {
103         return new ElectricalCapacitance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
104                 zero.getDisplayUnit());
105     }
106 
107     /**
108      * Return the maximum value of two relative scalars.
109      * @param r1 ElectricalCapacitance; the first scalar
110      * @param r2 ElectricalCapacitance; the second scalar
111      * @return ElectricalCapacitance; the maximum value of two relative scalars
112      */
113     public static ElectricalCapacitance max(final ElectricalCapacitance r1, final ElectricalCapacitance r2)
114     {
115         return r1.gt(r2) ? r1 : r2;
116     }
117 
118     /**
119      * Return the maximum value of more than two relative scalars.
120      * @param r1 ElectricalCapacitance; the first scalar
121      * @param r2 ElectricalCapacitance; the second scalar
122      * @param rn ElectricalCapacitance...; the other scalars
123      * @return ElectricalCapacitance; the maximum value of more than two relative scalars
124      */
125     public static ElectricalCapacitance max(final ElectricalCapacitance r1, final ElectricalCapacitance r2,
126             final ElectricalCapacitance... rn)
127     {
128         ElectricalCapacitance maxr = r1.gt(r2) ? r1 : r2;
129         for (ElectricalCapacitance r : rn)
130         {
131             if (r.gt(maxr))
132             {
133                 maxr = r;
134             }
135         }
136         return maxr;
137     }
138 
139     /**
140      * Return the minimum value of two relative scalars.
141      * @param r1 ElectricalCapacitance; the first scalar
142      * @param r2 ElectricalCapacitance; the second scalar
143      * @return ElectricalCapacitance; the minimum value of two relative scalars
144      */
145     public static ElectricalCapacitance min(final ElectricalCapacitance r1, final ElectricalCapacitance r2)
146     {
147         return r1.lt(r2) ? r1 : r2;
148     }
149 
150     /**
151      * Return the minimum value of more than two relative scalars.
152      * @param r1 ElectricalCapacitance; the first scalar
153      * @param r2 ElectricalCapacitance; the second scalar
154      * @param rn ElectricalCapacitance...; the other scalars
155      * @return ElectricalCapacitance; the minimum value of more than two relative scalars
156      */
157     public static ElectricalCapacitance min(final ElectricalCapacitance r1, final ElectricalCapacitance r2,
158             final ElectricalCapacitance... rn)
159     {
160         ElectricalCapacitance minr = r1.lt(r2) ? r1 : r2;
161         for (ElectricalCapacitance r : rn)
162         {
163             if (r.lt(minr))
164             {
165                 minr = r;
166             }
167         }
168         return minr;
169     }
170 
171     /**
172      * Returns a ElectricalCapacitance representation of a textual representation of a value with a unit. The String
173      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
174      * unit. Spaces are allowed, but not required, between the value and the unit.
175      * @param text String; the textual representation to parse into a ElectricalCapacitance
176      * @return ElectricalCapacitance; the Scalar representation of the value in its unit
177      * @throws IllegalArgumentException when the text cannot be parsed
178      * @throws NullPointerException when the text argument is null
179      */
180     public static ElectricalCapacitance valueOf(final String text)
181     {
182         Throw.whenNull(text, "Error parsing ElectricalCapacitance: text to parse is null");
183         Throw.when(text.length() == 0, IllegalArgumentException.class,
184                 "Error parsing ElectricalCapacitance: empty text to parse");
185         try
186         {
187             NumberParser numberParser = new NumberParser().lenient().trailing();
188             double d = numberParser.parseDouble(text);
189             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
190             ElectricalCapacitanceUnit unit = ElectricalCapacitanceUnit.BASE.getUnitByAbbreviation(unitString);
191             if (unit == null)
192                 throw new IllegalArgumentException("Unit " + unitString + " not found");
193             return new ElectricalCapacitance(d, unit);
194         }
195         catch (Exception exception)
196         {
197             throw new IllegalArgumentException("Error parsing ElectricalCapacitance from " + text + " using Locale "
198                     + Locale.getDefault(Locale.Category.FORMAT), exception);
199         }
200     }
201 
202     /**
203      * Returns a ElectricalCapacitance based on a value and the textual representation of the unit, which can be localized.
204      * @param value double; the value to use
205      * @param unitString String; the textual representation of the unit
206      * @return ElectricalCapacitance; the Scalar representation of the value in its unit
207      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
208      * @throws NullPointerException when the unitString argument is null
209      */
210     public static ElectricalCapacitance of(final double value, final String unitString)
211     {
212         Throw.whenNull(unitString, "Error parsing ElectricalCapacitance: unitString is null");
213         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
214                 "Error parsing ElectricalCapacitance: empty unitString");
215         ElectricalCapacitanceUnit unit = ElectricalCapacitanceUnit.BASE.getUnitByAbbreviation(unitString);
216         if (unit != null)
217         {
218             return new ElectricalCapacitance(value, unit);
219         }
220         throw new IllegalArgumentException("Error parsing ElectricalCapacitance with unit " + unitString);
221     }
222 
223     /**
224      * Calculate the division of ElectricalCapacitance and ElectricalCapacitance, which results in a Dimensionless scalar.
225      * @param v ElectricalCapacitance; scalar
226      * @return Dimensionless; scalar as a division of ElectricalCapacitance and ElectricalCapacitance
227      */
228     public final Dimensionless divide(final ElectricalCapacitance v)
229     {
230         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
231     }
232 
233     /**
234      * Calculate the multiplication of ElectricalCapacitance and ElectricalPotential, which results in a ElectricalCharge
235      * scalar.
236      * @param v ElectricalCapacitance; scalar
237      * @return ElectricalCharge; scalar as a multiplication of ElectricalCapacitance and ElectricalPotential
238      */
239     public final ElectricalCharge times(final ElectricalPotential v)
240     {
241         return new ElectricalCharge(this.si * v.si, ElectricalChargeUnit.SI);
242     }
243 
244     /**
245      * Calculate the division of ElectricalCapacitance and Duration, which results in a ElectricalConductance scalar.
246      * @param v ElectricalCapacitance; scalar
247      * @return ElectricalConductance; scalar as a division of ElectricalCapacitance and Duration
248      */
249     public final ElectricalConductance divide(final Duration v)
250     {
251         return new ElectricalConductance(this.si / v.si, ElectricalConductanceUnit.SI);
252     }
253 
254     /**
255      * Calculate the division of ElectricalCapacitance and ElectricalConductance, which results in a Duration scalar.
256      * @param v ElectricalCapacitance; scalar
257      * @return Duration; scalar as a division of ElectricalCapacitance and ElectricalConductance
258      */
259     public final Duration divide(final ElectricalConductance v)
260     {
261         return new Duration(this.si / v.si, DurationUnit.SI);
262     }
263 
264     @Override
265     public SIScalar reciprocal()
266     {
267         return DoubleScalar.divide(Dimensionless.ONE, this);
268     }
269 
270 }