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