View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.DimensionlessUnit;
9   import org.djunits.unit.ElectricalCurrentUnit;
10  import org.djunits.unit.ElectricalPotentialUnit;
11  import org.djunits.unit.ElectricalResistanceUnit;
12  import org.djunits.unit.MagneticFluxUnit;
13  import org.djunits.unit.PowerUnit;
14  import org.djunits.value.util.ValueUtil;
15  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
16  
17  /**
18   * Easy access methods for the ElectricalPotential DoubleScalar, which is relative by definition.
19   * <p>
20   * Copyright (c) 2013-2020 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 = "2020-01-19T15:21:24.964166400Z")
27  public class ElectricalPotential extends AbstractDoubleScalarRel<ElectricalPotentialUnit, ElectricalPotential>
28  {
29      /** */
30      private static final long serialVersionUID = 20150905L;
31  
32      /** Constant with value zero. */
33      public static final ElectricalPotentialctricalPotential.html#ElectricalPotential">ElectricalPotential ZERO = new ElectricalPotential(0.0, ElectricalPotentialUnit.SI);
34  
35      /** Constant with value one. */
36      public static final ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotential ONE = new ElectricalPotential(1.0, ElectricalPotentialUnit.SI);
37  
38      /** Constant with value NaN. */
39      @SuppressWarnings("checkstyle:constantname")
40      public static final ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotential NaN = new ElectricalPotential(Double.NaN, ElectricalPotentialUnit.SI);
41  
42      /** Constant with value POSITIVE_INFINITY. */
43      public static final ElectricalPotential POSITIVE_INFINITY =
44              new ElectricalPotential(Double.POSITIVE_INFINITY, ElectricalPotentialUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final ElectricalPotential NEGATIVE_INFINITY =
48              new ElectricalPotential(Double.NEGATIVE_INFINITY, ElectricalPotentialUnit.SI);
49  
50      /** Constant with value MAX_VALUE. */
51      public static final ElectricalPotential POS_MAXVALUE =
52              new ElectricalPotential(Double.MAX_VALUE, ElectricalPotentialUnit.SI);
53  
54      /** Constant with value -MAX_VALUE. */
55      public static final ElectricalPotential NEG_MAXVALUE =
56              new ElectricalPotential(-Double.MAX_VALUE, ElectricalPotentialUnit.SI);
57  
58      /**
59       * Construct ElectricalPotential scalar.
60       * @param value double; the double value
61       * @param unit ElectricalPotentialUnit; unit for the double value
62       */
63      public ElectricalPotential(final double value, final ElectricalPotentialUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct ElectricalPotential scalar.
70       * @param value ElectricalPotential; Scalar from which to construct this instance
71       */
72      public ElectricalPotentialr/ElectricalPotential.html#ElectricalPotential">ElectricalPotential(final ElectricalPotential value)
73      {
74          super(value);
75      }
76  
77      /** {@inheritDoc} */
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 ElectricalPotentialtricalPotential.html#ElectricalPotential">ElectricalPotentialPotential.html#ElectricalPotential">ElectricalPotential interpolate(final ElectricalPotentialtricalPotential.html#ElectricalPotential">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 ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotential max(final ElectricalPotentialectricalPotential.html#ElectricalPotential">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 ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotential max(final ElectricalPotentialectricalPotential.html#ElectricalPotential">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 ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotential min(final ElectricalPotentialectricalPotential.html#ElectricalPotential">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 ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotentialectricalPotential.html#ElectricalPotential">ElectricalPotential min(final ElectricalPotentialectricalPotential.html#ElectricalPotential">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 the official abbreviation of the unit.
175      * 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         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
187         if (matcher.find())
188         {
189             int index = matcher.end();
190             String unitString = text.substring(index).trim();
191             String valueString = text.substring(0, index).trim();
192             ElectricalPotentialUnit unit = ElectricalPotentialUnit.BASE.getUnitByAbbreviation(unitString);
193             if (unit != null)
194             {
195                 double d = Double.parseDouble(valueString);
196                 return new ElectricalPotential(d, unit);
197             }
198         }
199         throw new IllegalArgumentException("Error parsing ElectricalPotential from " + text);
200     }
201 
202     /**
203      * Returns a ElectricalPotential based on a value and the textual representation of the unit.
204      * @param value double; the value to use
205      * @param unitString String; the textual representation of the unit
206      * @return ElectricalPotential; 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 ElectricalPotential of(final double value, final String unitString)
211     {
212         Throw.whenNull(unitString, "Error parsing ElectricalPotential: unitString is null");
213         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
214                 "Error parsing ElectricalPotential: empty unitString");
215         ElectricalPotentialUnit unit = ElectricalPotentialUnit.BASE.getUnitByAbbreviation(unitString);
216         if (unit != null)
217         {
218             return new ElectricalPotential(value, unit);
219         }
220         throw new IllegalArgumentException("Error parsing ElectricalPotential with unit " + unitString);
221     }
222 
223     /**
224      * Calculate the division of ElectricalPotential and ElectricalPotential, which results in a Dimensionless scalar.
225      * @param v ElectricalPotential scalar
226      * @return Dimensionless scalar as a division of ElectricalPotential and ElectricalPotential
227      */
228     public final Dimensionless divide(final ElectricalPotential v)
229     {
230         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
231     }
232 
233     /**
234      * Calculate the multiplication of ElectricalPotential and ElectricalCurrent, which results in a Power scalar.
235      * @param v ElectricalPotential scalar
236      * @return Power scalar as a multiplication of ElectricalPotential and ElectricalCurrent
237      */
238     public final Power times(final ElectricalCurrent v)
239     {
240         return new Power(this.si * v.si, PowerUnit.SI);
241     }
242 
243     /**
244      * Calculate the division of ElectricalPotential and ElectricalCurrent, which results in a ElectricalResistance scalar.
245      * @param v ElectricalPotential scalar
246      * @return ElectricalResistance scalar as a division of ElectricalPotential and ElectricalCurrent
247      */
248     public final ElectricalResistance divide(final ElectricalCurrent v)
249     {
250         return new ElectricalResistance(this.si / v.si, ElectricalResistanceUnit.SI);
251     }
252 
253     /**
254      * Calculate the division of ElectricalPotential and ElectricalResistance, which results in a ElectricalCurrent scalar.
255      * @param v ElectricalPotential scalar
256      * @return ElectricalCurrent scalar as a division of ElectricalPotential and ElectricalResistance
257      */
258     public final ElectricalCurrent divide(final ElectricalResistance v)
259     {
260         return new ElectricalCurrent(this.si / v.si, ElectricalCurrentUnit.SI);
261     }
262 
263     /**
264      * Calculate the multiplication of ElectricalPotential and Duration, which results in a MagneticFlux scalar.
265      * @param v ElectricalPotential scalar
266      * @return MagneticFlux scalar as a multiplication of ElectricalPotential and Duration
267      */
268     public final MagneticFlux times(final Duration v)
269     {
270         return new MagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
271     }
272 
273 }