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.AbsorbedDoseUnit;
9   import org.djunits.unit.AccelerationUnit;
10  import org.djunits.unit.AmountOfSubstanceUnit;
11  import org.djunits.unit.AngleUnit;
12  import org.djunits.unit.AngularAccelerationUnit;
13  import org.djunits.unit.AngularVelocityUnit;
14  import org.djunits.unit.AreaUnit;
15  import org.djunits.unit.CatalyticActivityUnit;
16  import org.djunits.unit.DensityUnit;
17  import org.djunits.unit.DimensionlessUnit;
18  import org.djunits.unit.DurationUnit;
19  import org.djunits.unit.ElectricalCapacitanceUnit;
20  import org.djunits.unit.ElectricalChargeUnit;
21  import org.djunits.unit.ElectricalConductanceUnit;
22  import org.djunits.unit.ElectricalCurrentUnit;
23  import org.djunits.unit.ElectricalInductanceUnit;
24  import org.djunits.unit.ElectricalPotentialUnit;
25  import org.djunits.unit.ElectricalResistanceUnit;
26  import org.djunits.unit.EnergyUnit;
27  import org.djunits.unit.EquivalentDoseUnit;
28  import org.djunits.unit.FlowMassUnit;
29  import org.djunits.unit.FlowVolumeUnit;
30  import org.djunits.unit.ForceUnit;
31  import org.djunits.unit.FrequencyUnit;
32  import org.djunits.unit.IlluminanceUnit;
33  import org.djunits.unit.LengthUnit;
34  import org.djunits.unit.LinearDensityUnit;
35  import org.djunits.unit.LuminousFluxUnit;
36  import org.djunits.unit.LuminousIntensityUnit;
37  import org.djunits.unit.MagneticFluxDensityUnit;
38  import org.djunits.unit.MagneticFluxUnit;
39  import org.djunits.unit.MassUnit;
40  import org.djunits.unit.MomentumUnit;
41  import org.djunits.unit.PowerUnit;
42  import org.djunits.unit.PressureUnit;
43  import org.djunits.unit.RadioActivityUnit;
44  import org.djunits.unit.SIUnit;
45  import org.djunits.unit.SolidAngleUnit;
46  import org.djunits.unit.SpeedUnit;
47  import org.djunits.unit.TemperatureUnit;
48  import org.djunits.unit.TorqueUnit;
49  import org.djunits.unit.Unit;
50  import org.djunits.unit.VolumeUnit;
51  import org.djunits.unit.si.SIDimensions;
52  import org.djunits.unit.util.UnitRuntimeException;
53  import org.djunits.value.util.ValueUtil;
54  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
55  import org.djunits.value.vdouble.scalar.base.DoubleScalar;
56  
57  /**
58   * Easy access methods for the generic Relative SI DoubleScalar.
59   * <p>
60   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
61   * All rights reserved. <br>
62   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
63   * </p>
64   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
65   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
66   */
67  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2022-03-14T11:14:15.180987200Z")
68  public class SIScalar extends AbstractDoubleScalarRel<SIUnit, SIScalar>
69  {
70      /** */
71      private static final long serialVersionUID = 20150901L;
72  
73      /**
74       * Construct SI scalar.
75       * @param value double; the double value
76       * @param unit SIUnit; unit for the double value
77       */
78      public SIScalar(final double value, final SIUnit unit)
79      {
80          super(value, unit);
81      }
82  
83      /**
84       * Construct SI scalar.
85       * @param value SIScalar; Scalar from which to construct this instance
86       */
87      public SIScalarouble/scalar/SIScalar.html#SIScalar">SIScalar(final SIScalar value)
88      {
89          super(value);
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public final SIScalar instantiateRel(final double value, final SIUnit unit)
95      {
96          return new SIScalar(value, unit);
97      }
98  
99      /**
100      * Construct SI scalar.
101      * @param value double; the double value in SI units
102      * @param unit SIUnit; the unit to use for the SI scalar
103      * @return SIScalar; the new scalar with the SI value
104      */
105     public static final SIScalar instantiateSI(final double value, final SIUnit unit)
106     {
107         return new SIScalar(value, unit);
108     }
109 
110     /**
111      * Interpolate between two values.
112      * @param zero SIScalar; the low value
113      * @param one SIScalar; the high value
114      * @param ratio double; the ratio between 0 and 1, inclusive
115      * @return SIScalar; a Scalar at the ratio between
116      */
117     public static SIScalarscalar/SIScalar.html#SIScalar">SIScalar/SIScalar.html#SIScalar">SIScalar interpolate(final SIScalarscalar/SIScalar.html#SIScalar">SIScalar zero, final SIScalar one, final double ratio)
118     {
119         return new SIScalar(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
120                 zero.getDisplayUnit());
121     }
122 
123     /**
124      * Return the maximum value of two relative scalars.
125      * @param r1 SIScalar; the first scalar
126      * @param r2 SIScalar; the second scalar
127      * @return SIScalar; the maximum value of two relative scalars
128      */
129     public static SIScalare/scalar/SIScalar.html#SIScalar">SIScalare/scalar/SIScalar.html#SIScalar">SIScalar max(final SIScalare/scalar/SIScalar.html#SIScalar">SIScalar r1, final SIScalar r2)
130     {
131         return r1.gt(r2) ? r1 : r2;
132     }
133 
134     /**
135      * Return the maximum value of more than two relative scalars.
136      * @param r1 SIScalar; the first scalar
137      * @param r2 SIScalar; the second scalar
138      * @param rn SIScalar...; the other scalars
139      * @return SIScalar; the maximum value of more than two relative scalars
140      */
141     public static SIScalare/scalar/SIScalar.html#SIScalar">SIScalare/scalar/SIScalar.html#SIScalar">SIScalar max(final SIScalare/scalar/SIScalar.html#SIScalar">SIScalar r1, final SIScalar r2, final SIScalar... rn)
142     {
143         SIScalar maxr = r1.gt(r2) ? r1 : r2;
144         for (SIScalar r : rn)
145         {
146             if (r.gt(maxr))
147             {
148                 maxr = r;
149             }
150         }
151         return maxr;
152     }
153 
154     /**
155      * Return the minimum value of two relative scalars.
156      * @param r1 SIScalar; the first scalar
157      * @param r2 SIScalar; the second scalar
158      * @return SIScalar; the minimum value of two relative scalars
159      */
160     public static SIScalare/scalar/SIScalar.html#SIScalar">SIScalare/scalar/SIScalar.html#SIScalar">SIScalar min(final SIScalare/scalar/SIScalar.html#SIScalar">SIScalar r1, final SIScalar r2)
161     {
162         return r1.lt(r2) ? r1 : r2;
163     }
164 
165     /**
166      * Return the minimum value of more than two relative scalars.
167      * @param r1 SIScalar; the first scalar
168      * @param r2 SIScalar; the second scalar
169      * @param rn SIScalar...; the other scalars
170      * @return SIScalar; the minimum value of more than two relative scalars
171      */
172     public static SIScalare/scalar/SIScalar.html#SIScalar">SIScalare/scalar/SIScalar.html#SIScalar">SIScalar min(final SIScalare/scalar/SIScalar.html#SIScalar">SIScalar r1, final SIScalar r2, final SIScalar... rn)
173     {
174         SIScalar minr = r1.lt(r2) ? r1 : r2;
175         for (SIScalar r : rn)
176         {
177             if (r.lt(minr))
178             {
179                 minr = r;
180             }
181         }
182         return minr;
183     }
184 
185     /** {@inheritDoc} */
186     @Override
187     public SIScalar reciprocal()
188     {
189         return DoubleScalar.divide(Dimensionless.ONE, this);
190     }
191 
192     /**
193      * Returns an SIScalar representation of a textual representation of a value with a unit. The String representation that can
194      * be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but not
195      * required, between the value and the unit.
196      * @param text String; the textual representation to parse into a SIScalar
197      * @return SIScalar; the Scalar representation of the value in its unit
198      * @throws IllegalArgumentException when the text cannot be parsed
199      * @throws NullPointerException when the text argument is null
200      */
201     public static SIScalar valueOf(final String text)
202     {
203         Throw.whenNull(text, "Error parsing SIScalar: unitString is null");
204         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing SIScalar: empty unitString");
205         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
206         if (matcher.find())
207         {
208             int index = matcher.end();
209             try
210             {
211                 String unitString = text.substring(index).trim();
212                 String valueString = text.substring(0, index).trim();
213                 SIUnit unit = Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(unitString));
214                 if (unit != null)
215                 {
216                     double d = Double.parseDouble(valueString);
217                     return new SIScalar(d, unit);
218                 }
219             }
220             catch (Exception exception)
221             {
222                 throw new IllegalArgumentException("Error parsing SIScalar from " + text, exception);
223             }
224         }
225         throw new IllegalArgumentException("Error parsing SIScalar from " + text);
226     }
227 
228     /**
229      * Returns an SIScalar based on a value and the textual representation of the unit.
230      * @param value double; the value to use
231      * @param unitString String; the textual representation of the unit
232      * @return SIScalar; the Scalar representation of the value in its unit
233      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
234      * @throws NullPointerException when the unitString argument is null
235      */
236     public static SIScalar of(final double value, final String unitString)
237     {
238         Throw.whenNull(unitString, "Error parsing SIScalar: unitString is null");
239         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing SIScalar: empty unitString");
240         try
241         {
242             SIUnit unit = Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(unitString));
243             if (unit != null)
244             {
245                 return new SIScalar(value, unit);
246             }
247         }
248         catch (Exception exception)
249         {
250             throw new IllegalArgumentException("Error parsing SIUnit from " + unitString, exception);
251         }
252         throw new IllegalArgumentException("Error parsing SIScalar with unit " + unitString);
253     }
254 
255     /**********************************************************************************/
256     /******************************** 'CAST AS' METHODS *******************************/
257     /**********************************************************************************/
258 
259     /**
260      * Return the current scalar transformed to a scalar in the given unit. Of course the SI dimensionality has to match,
261      * otherwise the scalar cannot be transformed. The compiler will check the alignment between the return value and the unit.
262      * @param displayUnit KU; the unit in which the scalar needs to be expressed
263      * @return S; the scalar that has been transformed into the right scalar type and unit
264      * @param <U> the unit type
265      * @param <S> the scalar type
266      */
267     public final <U extends Unit<U>, S extends AbstractDoubleScalarRel<U, S>> S as(final U displayUnit)
268     {
269         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(displayUnit.getQuantity().getSiDimensions())),
270                 UnitRuntimeException.class, "SIScalar with unit %s cannot be converted to a scalar with unit %s",
271                 getDisplayUnit(), displayUnit);
272         S result = DoubleScalar.instantiate(this.si, displayUnit.getStandardUnit());
273         result.setDisplayUnit(displayUnit);
274         return result;
275     }
276 
277     /**
278      * Return the current scalar as a absorbeddose.
279      * @return AbsorbedDose; the current scalar as a absorbeddose
280      */
281     public final AbsorbedDose asAbsorbedDose()
282     {
283         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AbsorbedDoseUnit.BASE.getSiDimensions())),
284                 UnitRuntimeException.class, "cannot cast %s to AbsorbedDose", this.toString());
285         return new AbsorbedDose(getSI(), AbsorbedDoseUnit.SI);
286     }
287 
288     /**
289      * Return the current scalar as a absorbeddose, and provide a display unit.
290      * @param displayUnit the unit in which the value will be displayed
291      * @return AbsorbedDose; the current scalar as a absorbeddose
292      */
293     public final AbsorbedDose asAbsorbedDose(final AbsorbedDoseUnit displayUnit)
294     {
295         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AbsorbedDoseUnit.BASE.getSiDimensions())),
296                 UnitRuntimeException.class, "cannot cast %s to AbsorbedDose", this.toString());
297         AbsorbedDoser/AbsorbedDose.html#AbsorbedDose">AbsorbedDose result = new AbsorbedDose(getSI(), displayUnit.getStandardUnit());
298         result.setDisplayUnit(displayUnit);
299         return result;
300     }
301 
302     /**
303      * Return the current scalar as a acceleration.
304      * @return Acceleration; the current scalar as a acceleration
305      */
306     public final Acceleration asAcceleration()
307     {
308         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AccelerationUnit.BASE.getSiDimensions())),
309                 UnitRuntimeException.class, "cannot cast %s to Acceleration", this.toString());
310         return new Acceleration(getSI(), AccelerationUnit.SI);
311     }
312 
313     /**
314      * Return the current scalar as a acceleration, and provide a display unit.
315      * @param displayUnit the unit in which the value will be displayed
316      * @return Acceleration; the current scalar as a acceleration
317      */
318     public final Acceleration asAcceleration(final AccelerationUnit displayUnit)
319     {
320         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AccelerationUnit.BASE.getSiDimensions())),
321                 UnitRuntimeException.class, "cannot cast %s to Acceleration", this.toString());
322         Accelerationr/Acceleration.html#Acceleration">Acceleration result = new Acceleration(getSI(), displayUnit.getStandardUnit());
323         result.setDisplayUnit(displayUnit);
324         return result;
325     }
326 
327     /**
328      * Return the current scalar as a amountofsubstance.
329      * @return AmountOfSubstance; the current scalar as a amountofsubstance
330      */
331     public final AmountOfSubstance asAmountOfSubstance()
332     {
333         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AmountOfSubstanceUnit.BASE.getSiDimensions())),
334                 UnitRuntimeException.class, "cannot cast %s to AmountOfSubstance", this.toString());
335         return new AmountOfSubstance(getSI(), AmountOfSubstanceUnit.SI);
336     }
337 
338     /**
339      * Return the current scalar as a amountofsubstance, and provide a display unit.
340      * @param displayUnit the unit in which the value will be displayed
341      * @return AmountOfSubstance; the current scalar as a amountofsubstance
342      */
343     public final AmountOfSubstance asAmountOfSubstance(final AmountOfSubstanceUnit displayUnit)
344     {
345         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AmountOfSubstanceUnit.BASE.getSiDimensions())),
346                 UnitRuntimeException.class, "cannot cast %s to AmountOfSubstance", this.toString());
347         AmountOfSubstanceuntOfSubstance.html#AmountOfSubstance">AmountOfSubstance result = new AmountOfSubstance(getSI(), displayUnit.getStandardUnit());
348         result.setDisplayUnit(displayUnit);
349         return result;
350     }
351 
352     /**
353      * Return the current scalar as a angularacceleration.
354      * @return AngularAcceleration; the current scalar as a angularacceleration
355      */
356     public final AngularAcceleration asAngularAcceleration()
357     {
358         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularAccelerationUnit.BASE.getSiDimensions())),
359                 UnitRuntimeException.class, "cannot cast %s to AngularAcceleration", this.toString());
360         return new AngularAcceleration(getSI(), AngularAccelerationUnit.SI);
361     }
362 
363     /**
364      * Return the current scalar as a angularacceleration, and provide a display unit.
365      * @param displayUnit the unit in which the value will be displayed
366      * @return AngularAcceleration; the current scalar as a angularacceleration
367      */
368     public final AngularAcceleration asAngularAcceleration(final AngularAccelerationUnit displayUnit)
369     {
370         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularAccelerationUnit.BASE.getSiDimensions())),
371                 UnitRuntimeException.class, "cannot cast %s to AngularAcceleration", this.toString());
372         AngularAccelerationarAcceleration.html#AngularAcceleration">AngularAcceleration result = new AngularAcceleration(getSI(), displayUnit.getStandardUnit());
373         result.setDisplayUnit(displayUnit);
374         return result;
375     }
376 
377     /**
378      * Return the current scalar as a angularvelocity.
379      * @return AngularVelocity; the current scalar as a angularvelocity
380      */
381     public final AngularVelocity asAngularVelocity()
382     {
383         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularVelocityUnit.BASE.getSiDimensions())),
384                 UnitRuntimeException.class, "cannot cast %s to AngularVelocity", this.toString());
385         return new AngularVelocity(getSI(), AngularVelocityUnit.SI);
386     }
387 
388     /**
389      * Return the current scalar as a angularvelocity, and provide a display unit.
390      * @param displayUnit the unit in which the value will be displayed
391      * @return AngularVelocity; the current scalar as a angularvelocity
392      */
393     public final AngularVelocity asAngularVelocity(final AngularVelocityUnit displayUnit)
394     {
395         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularVelocityUnit.BASE.getSiDimensions())),
396                 UnitRuntimeException.class, "cannot cast %s to AngularVelocity", this.toString());
397         AngularVelocityngularVelocity.html#AngularVelocity">AngularVelocity result = new AngularVelocity(getSI(), displayUnit.getStandardUnit());
398         result.setDisplayUnit(displayUnit);
399         return result;
400     }
401 
402     /**
403      * Return the current scalar as a area.
404      * @return Area; the current scalar as a area
405      */
406     public final Area asArea()
407     {
408         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AreaUnit.BASE.getSiDimensions())),
409                 UnitRuntimeException.class, "cannot cast %s to Area", this.toString());
410         return new Area(getSI(), AreaUnit.SI);
411     }
412 
413     /**
414      * Return the current scalar as a area, and provide a display unit.
415      * @param displayUnit the unit in which the value will be displayed
416      * @return Area; the current scalar as a area
417      */
418     public final Area asArea(final AreaUnit displayUnit)
419     {
420         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AreaUnit.BASE.getSiDimensions())),
421                 UnitRuntimeException.class, "cannot cast %s to Area", this.toString());
422         Areale/scalar/Area.html#Area">Area result = new Area(getSI(), displayUnit.getStandardUnit());
423         result.setDisplayUnit(displayUnit);
424         return result;
425     }
426 
427     /**
428      * Return the current scalar as a catalyticactivity.
429      * @return CatalyticActivity; the current scalar as a catalyticactivity
430      */
431     public final CatalyticActivity asCatalyticActivity()
432     {
433         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(CatalyticActivityUnit.BASE.getSiDimensions())),
434                 UnitRuntimeException.class, "cannot cast %s to CatalyticActivity", this.toString());
435         return new CatalyticActivity(getSI(), CatalyticActivityUnit.SI);
436     }
437 
438     /**
439      * Return the current scalar as a catalyticactivity, and provide a display unit.
440      * @param displayUnit the unit in which the value will be displayed
441      * @return CatalyticActivity; the current scalar as a catalyticactivity
442      */
443     public final CatalyticActivity asCatalyticActivity(final CatalyticActivityUnit displayUnit)
444     {
445         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(CatalyticActivityUnit.BASE.getSiDimensions())),
446                 UnitRuntimeException.class, "cannot cast %s to CatalyticActivity", this.toString());
447         CatalyticActivityalyticActivity.html#CatalyticActivity">CatalyticActivity result = new CatalyticActivity(getSI(), displayUnit.getStandardUnit());
448         result.setDisplayUnit(displayUnit);
449         return result;
450     }
451 
452     /**
453      * Return the current scalar as a density.
454      * @return Density; the current scalar as a density
455      */
456     public final Density asDensity()
457     {
458         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DensityUnit.BASE.getSiDimensions())),
459                 UnitRuntimeException.class, "cannot cast %s to Density", this.toString());
460         return new Density(getSI(), DensityUnit.SI);
461     }
462 
463     /**
464      * Return the current scalar as a density, and provide a display unit.
465      * @param displayUnit the unit in which the value will be displayed
466      * @return Density; the current scalar as a density
467      */
468     public final Density asDensity(final DensityUnit displayUnit)
469     {
470         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DensityUnit.BASE.getSiDimensions())),
471                 UnitRuntimeException.class, "cannot cast %s to Density", this.toString());
472         Densityscalar/Density.html#Density">Density result = new Density(getSI(), displayUnit.getStandardUnit());
473         result.setDisplayUnit(displayUnit);
474         return result;
475     }
476 
477     /**
478      * Return the current scalar as a dimensionless.
479      * @return Dimensionless; the current scalar as a dimensionless
480      */
481     public final Dimensionless asDimensionless()
482     {
483         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DimensionlessUnit.BASE.getSiDimensions())),
484                 UnitRuntimeException.class, "cannot cast %s to Dimensionless", this.toString());
485         return new Dimensionless(getSI(), DimensionlessUnit.SI);
486     }
487 
488     /**
489      * Return the current scalar as a dimensionless, and provide a display unit.
490      * @param displayUnit the unit in which the value will be displayed
491      * @return Dimensionless; the current scalar as a dimensionless
492      */
493     public final Dimensionless asDimensionless(final DimensionlessUnit displayUnit)
494     {
495         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DimensionlessUnit.BASE.getSiDimensions())),
496                 UnitRuntimeException.class, "cannot cast %s to Dimensionless", this.toString());
497         Dimensionless/Dimensionless.html#Dimensionless">Dimensionless result = new Dimensionless(getSI(), displayUnit.getStandardUnit());
498         result.setDisplayUnit(displayUnit);
499         return result;
500     }
501 
502     /**
503      * Return the current scalar as a electricalcapacitance.
504      * @return ElectricalCapacitance; the current scalar as a electricalcapacitance
505      */
506     public final ElectricalCapacitance asElectricalCapacitance()
507     {
508         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCapacitanceUnit.BASE.getSiDimensions())),
509                 UnitRuntimeException.class, "cannot cast %s to ElectricalCapacitance", this.toString());
510         return new ElectricalCapacitance(getSI(), ElectricalCapacitanceUnit.SI);
511     }
512 
513     /**
514      * Return the current scalar as a electricalcapacitance, and provide a display unit.
515      * @param displayUnit the unit in which the value will be displayed
516      * @return ElectricalCapacitance; the current scalar as a electricalcapacitance
517      */
518     public final ElectricalCapacitance asElectricalCapacitance(final ElectricalCapacitanceUnit displayUnit)
519     {
520         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCapacitanceUnit.BASE.getSiDimensions())),
521                 UnitRuntimeException.class, "cannot cast %s to ElectricalCapacitance", this.toString());
522         ElectricalCapacitancecalCapacitance.html#ElectricalCapacitance">ElectricalCapacitance result = new ElectricalCapacitance(getSI(), displayUnit.getStandardUnit());
523         result.setDisplayUnit(displayUnit);
524         return result;
525     }
526 
527     /**
528      * Return the current scalar as a electricalcharge.
529      * @return ElectricalCharge; the current scalar as a electricalcharge
530      */
531     public final ElectricalCharge asElectricalCharge()
532     {
533         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalChargeUnit.BASE.getSiDimensions())),
534                 UnitRuntimeException.class, "cannot cast %s to ElectricalCharge", this.toString());
535         return new ElectricalCharge(getSI(), ElectricalChargeUnit.SI);
536     }
537 
538     /**
539      * Return the current scalar as a electricalcharge, and provide a display unit.
540      * @param displayUnit the unit in which the value will be displayed
541      * @return ElectricalCharge; the current scalar as a electricalcharge
542      */
543     public final ElectricalCharge asElectricalCharge(final ElectricalChargeUnit displayUnit)
544     {
545         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalChargeUnit.BASE.getSiDimensions())),
546                 UnitRuntimeException.class, "cannot cast %s to ElectricalCharge", this.toString());
547         ElectricalChargeectricalCharge.html#ElectricalCharge">ElectricalCharge result = new ElectricalCharge(getSI(), displayUnit.getStandardUnit());
548         result.setDisplayUnit(displayUnit);
549         return result;
550     }
551 
552     /**
553      * Return the current scalar as a electricalconductance.
554      * @return ElectricalConductance; the current scalar as a electricalconductance
555      */
556     public final ElectricalConductance asElectricalConductance()
557     {
558         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalConductanceUnit.BASE.getSiDimensions())),
559                 UnitRuntimeException.class, "cannot cast %s to ElectricalConductance", this.toString());
560         return new ElectricalConductance(getSI(), ElectricalConductanceUnit.SI);
561     }
562 
563     /**
564      * Return the current scalar as a electricalconductance, and provide a display unit.
565      * @param displayUnit the unit in which the value will be displayed
566      * @return ElectricalConductance; the current scalar as a electricalconductance
567      */
568     public final ElectricalConductance asElectricalConductance(final ElectricalConductanceUnit displayUnit)
569     {
570         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalConductanceUnit.BASE.getSiDimensions())),
571                 UnitRuntimeException.class, "cannot cast %s to ElectricalConductance", this.toString());
572         ElectricalConductancecalConductance.html#ElectricalConductance">ElectricalConductance result = new ElectricalConductance(getSI(), displayUnit.getStandardUnit());
573         result.setDisplayUnit(displayUnit);
574         return result;
575     }
576 
577     /**
578      * Return the current scalar as a electricalcurrent.
579      * @return ElectricalCurrent; the current scalar as a electricalcurrent
580      */
581     public final ElectricalCurrent asElectricalCurrent()
582     {
583         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCurrentUnit.BASE.getSiDimensions())),
584                 UnitRuntimeException.class, "cannot cast %s to ElectricalCurrent", this.toString());
585         return new ElectricalCurrent(getSI(), ElectricalCurrentUnit.SI);
586     }
587 
588     /**
589      * Return the current scalar as a electricalcurrent, and provide a display unit.
590      * @param displayUnit the unit in which the value will be displayed
591      * @return ElectricalCurrent; the current scalar as a electricalcurrent
592      */
593     public final ElectricalCurrent asElectricalCurrent(final ElectricalCurrentUnit displayUnit)
594     {
595         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCurrentUnit.BASE.getSiDimensions())),
596                 UnitRuntimeException.class, "cannot cast %s to ElectricalCurrent", this.toString());
597         ElectricalCurrentctricalCurrent.html#ElectricalCurrent">ElectricalCurrent result = new ElectricalCurrent(getSI(), displayUnit.getStandardUnit());
598         result.setDisplayUnit(displayUnit);
599         return result;
600     }
601 
602     /**
603      * Return the current scalar as a electricalinductance.
604      * @return ElectricalInductance; the current scalar as a electricalinductance
605      */
606     public final ElectricalInductance asElectricalInductance()
607     {
608         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalInductanceUnit.BASE.getSiDimensions())),
609                 UnitRuntimeException.class, "cannot cast %s to ElectricalInductance", this.toString());
610         return new ElectricalInductance(getSI(), ElectricalInductanceUnit.SI);
611     }
612 
613     /**
614      * Return the current scalar as a electricalinductance, and provide a display unit.
615      * @param displayUnit the unit in which the value will be displayed
616      * @return ElectricalInductance; the current scalar as a electricalinductance
617      */
618     public final ElectricalInductance asElectricalInductance(final ElectricalInductanceUnit displayUnit)
619     {
620         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalInductanceUnit.BASE.getSiDimensions())),
621                 UnitRuntimeException.class, "cannot cast %s to ElectricalInductance", this.toString());
622         ElectricalInductanceicalInductance.html#ElectricalInductance">ElectricalInductance result = new ElectricalInductance(getSI(), displayUnit.getStandardUnit());
623         result.setDisplayUnit(displayUnit);
624         return result;
625     }
626 
627     /**
628      * Return the current scalar as a electricalpotential.
629      * @return ElectricalPotential; the current scalar as a electricalpotential
630      */
631     public final ElectricalPotential asElectricalPotential()
632     {
633         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalPotentialUnit.BASE.getSiDimensions())),
634                 UnitRuntimeException.class, "cannot cast %s to ElectricalPotential", this.toString());
635         return new ElectricalPotential(getSI(), ElectricalPotentialUnit.SI);
636     }
637 
638     /**
639      * Return the current scalar as a electricalpotential, and provide a display unit.
640      * @param displayUnit the unit in which the value will be displayed
641      * @return ElectricalPotential; the current scalar as a electricalpotential
642      */
643     public final ElectricalPotential asElectricalPotential(final ElectricalPotentialUnit displayUnit)
644     {
645         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalPotentialUnit.BASE.getSiDimensions())),
646                 UnitRuntimeException.class, "cannot cast %s to ElectricalPotential", this.toString());
647         ElectricalPotentialricalPotential.html#ElectricalPotential">ElectricalPotential result = new ElectricalPotential(getSI(), displayUnit.getStandardUnit());
648         result.setDisplayUnit(displayUnit);
649         return result;
650     }
651 
652     /**
653      * Return the current scalar as a electricalresistance.
654      * @return ElectricalResistance; the current scalar as a electricalresistance
655      */
656     public final ElectricalResistance asElectricalResistance()
657     {
658         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalResistanceUnit.BASE.getSiDimensions())),
659                 UnitRuntimeException.class, "cannot cast %s to ElectricalResistance", this.toString());
660         return new ElectricalResistance(getSI(), ElectricalResistanceUnit.SI);
661     }
662 
663     /**
664      * Return the current scalar as a electricalresistance, and provide a display unit.
665      * @param displayUnit the unit in which the value will be displayed
666      * @return ElectricalResistance; the current scalar as a electricalresistance
667      */
668     public final ElectricalResistance asElectricalResistance(final ElectricalResistanceUnit displayUnit)
669     {
670         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalResistanceUnit.BASE.getSiDimensions())),
671                 UnitRuntimeException.class, "cannot cast %s to ElectricalResistance", this.toString());
672         ElectricalResistanceicalResistance.html#ElectricalResistance">ElectricalResistance result = new ElectricalResistance(getSI(), displayUnit.getStandardUnit());
673         result.setDisplayUnit(displayUnit);
674         return result;
675     }
676 
677     /**
678      * Return the current scalar as a energy.
679      * @return Energy; the current scalar as a energy
680      */
681     public final Energy asEnergy()
682     {
683         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EnergyUnit.BASE.getSiDimensions())),
684                 UnitRuntimeException.class, "cannot cast %s to Energy", this.toString());
685         return new Energy(getSI(), EnergyUnit.SI);
686     }
687 
688     /**
689      * Return the current scalar as a energy, and provide a display unit.
690      * @param displayUnit the unit in which the value will be displayed
691      * @return Energy; the current scalar as a energy
692      */
693     public final Energy asEnergy(final EnergyUnit displayUnit)
694     {
695         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EnergyUnit.BASE.getSiDimensions())),
696                 UnitRuntimeException.class, "cannot cast %s to Energy", this.toString());
697         Energy/scalar/Energy.html#Energy">Energy result = new Energy(getSI(), displayUnit.getStandardUnit());
698         result.setDisplayUnit(displayUnit);
699         return result;
700     }
701 
702     /**
703      * Return the current scalar as a equivalentdose.
704      * @return EquivalentDose; the current scalar as a equivalentdose
705      */
706     public final EquivalentDose asEquivalentDose()
707     {
708         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EquivalentDoseUnit.BASE.getSiDimensions())),
709                 UnitRuntimeException.class, "cannot cast %s to EquivalentDose", this.toString());
710         return new EquivalentDose(getSI(), EquivalentDoseUnit.SI);
711     }
712 
713     /**
714      * Return the current scalar as a equivalentdose, and provide a display unit.
715      * @param displayUnit the unit in which the value will be displayed
716      * @return EquivalentDose; the current scalar as a equivalentdose
717      */
718     public final EquivalentDose asEquivalentDose(final EquivalentDoseUnit displayUnit)
719     {
720         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EquivalentDoseUnit.BASE.getSiDimensions())),
721                 UnitRuntimeException.class, "cannot cast %s to EquivalentDose", this.toString());
722         EquivalentDoseEquivalentDose.html#EquivalentDose">EquivalentDose result = new EquivalentDose(getSI(), displayUnit.getStandardUnit());
723         result.setDisplayUnit(displayUnit);
724         return result;
725     }
726 
727     /**
728      * Return the current scalar as a flowmass.
729      * @return FlowMass; the current scalar as a flowmass
730      */
731     public final FlowMass asFlowMass()
732     {
733         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FlowMassUnit.BASE.getSiDimensions())),
734                 UnitRuntimeException.class, "cannot cast %s to FlowMass", this.toString());
735         return new FlowMass(getSI(), FlowMassUnit.SI);
736     }
737 
738     /**
739      * Return the current scalar as a flowmass, and provide a display unit.
740      * @param displayUnit the unit in which the value will be displayed
741      * @return FlowMass; the current scalar as a flowmass
742      */
743     public final FlowMass asFlowMass(final FlowMassUnit displayUnit)
744     {
745         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FlowMassUnit.BASE.getSiDimensions())),
746                 UnitRuntimeException.class, "cannot cast %s to FlowMass", this.toString());
747         FlowMasscalar/FlowMass.html#FlowMass">FlowMass result = new FlowMass(getSI(), displayUnit.getStandardUnit());
748         result.setDisplayUnit(displayUnit);
749         return result;
750     }
751 
752     /**
753      * Return the current scalar as a flowvolume.
754      * @return FlowVolume; the current scalar as a flowvolume
755      */
756     public final FlowVolume asFlowVolume()
757     {
758         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FlowVolumeUnit.BASE.getSiDimensions())),
759                 UnitRuntimeException.class, "cannot cast %s to FlowVolume", this.toString());
760         return new FlowVolume(getSI(), FlowVolumeUnit.SI);
761     }
762 
763     /**
764      * Return the current scalar as a flowvolume, and provide a display unit.
765      * @param displayUnit the unit in which the value will be displayed
766      * @return FlowVolume; the current scalar as a flowvolume
767      */
768     public final FlowVolume asFlowVolume(final FlowVolumeUnit displayUnit)
769     {
770         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FlowVolumeUnit.BASE.getSiDimensions())),
771                 UnitRuntimeException.class, "cannot cast %s to FlowVolume", this.toString());
772         FlowVolumelar/FlowVolume.html#FlowVolume">FlowVolume result = new FlowVolume(getSI(), displayUnit.getStandardUnit());
773         result.setDisplayUnit(displayUnit);
774         return result;
775     }
776 
777     /**
778      * Return the current scalar as a force.
779      * @return Force; the current scalar as a force
780      */
781     public final Force asForce()
782     {
783         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ForceUnit.BASE.getSiDimensions())),
784                 UnitRuntimeException.class, "cannot cast %s to Force", this.toString());
785         return new Force(getSI(), ForceUnit.SI);
786     }
787 
788     /**
789      * Return the current scalar as a force, and provide a display unit.
790      * @param displayUnit the unit in which the value will be displayed
791      * @return Force; the current scalar as a force
792      */
793     public final Force asForce(final ForceUnit displayUnit)
794     {
795         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ForceUnit.BASE.getSiDimensions())),
796                 UnitRuntimeException.class, "cannot cast %s to Force", this.toString());
797         Forcee/scalar/Force.html#Force">Force result = new Force(getSI(), displayUnit.getStandardUnit());
798         result.setDisplayUnit(displayUnit);
799         return result;
800     }
801 
802     /**
803      * Return the current scalar as a frequency.
804      * @return Frequency; the current scalar as a frequency
805      */
806     public final Frequency asFrequency()
807     {
808         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FrequencyUnit.BASE.getSiDimensions())),
809                 UnitRuntimeException.class, "cannot cast %s to Frequency", this.toString());
810         return new Frequency(getSI(), FrequencyUnit.SI);
811     }
812 
813     /**
814      * Return the current scalar as a frequency, and provide a display unit.
815      * @param displayUnit the unit in which the value will be displayed
816      * @return Frequency; the current scalar as a frequency
817      */
818     public final Frequency asFrequency(final FrequencyUnit displayUnit)
819     {
820         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FrequencyUnit.BASE.getSiDimensions())),
821                 UnitRuntimeException.class, "cannot cast %s to Frequency", this.toString());
822         Frequencyalar/Frequency.html#Frequency">Frequency result = new Frequency(getSI(), displayUnit.getStandardUnit());
823         result.setDisplayUnit(displayUnit);
824         return result;
825     }
826 
827     /**
828      * Return the current scalar as a illuminance.
829      * @return Illuminance; the current scalar as a illuminance
830      */
831     public final Illuminance asIlluminance()
832     {
833         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(IlluminanceUnit.BASE.getSiDimensions())),
834                 UnitRuntimeException.class, "cannot cast %s to Illuminance", this.toString());
835         return new Illuminance(getSI(), IlluminanceUnit.SI);
836     }
837 
838     /**
839      * Return the current scalar as a illuminance, and provide a display unit.
840      * @param displayUnit the unit in which the value will be displayed
841      * @return Illuminance; the current scalar as a illuminance
842      */
843     public final Illuminance asIlluminance(final IlluminanceUnit displayUnit)
844     {
845         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(IlluminanceUnit.BASE.getSiDimensions())),
846                 UnitRuntimeException.class, "cannot cast %s to Illuminance", this.toString());
847         Illuminancear/Illuminance.html#Illuminance">Illuminance result = new Illuminance(getSI(), displayUnit.getStandardUnit());
848         result.setDisplayUnit(displayUnit);
849         return result;
850     }
851 
852     /**
853      * Return the current scalar as a lineardensity.
854      * @return LinearDensity; the current scalar as a lineardensity
855      */
856     public final LinearDensity asLinearDensity()
857     {
858         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LinearDensityUnit.BASE.getSiDimensions())),
859                 UnitRuntimeException.class, "cannot cast %s to LinearDensity", this.toString());
860         return new LinearDensity(getSI(), LinearDensityUnit.SI);
861     }
862 
863     /**
864      * Return the current scalar as a lineardensity, and provide a display unit.
865      * @param displayUnit the unit in which the value will be displayed
866      * @return LinearDensity; the current scalar as a lineardensity
867      */
868     public final LinearDensity asLinearDensity(final LinearDensityUnit displayUnit)
869     {
870         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LinearDensityUnit.BASE.getSiDimensions())),
871                 UnitRuntimeException.class, "cannot cast %s to LinearDensity", this.toString());
872         LinearDensity/LinearDensity.html#LinearDensity">LinearDensity result = new LinearDensity(getSI(), displayUnit.getStandardUnit());
873         result.setDisplayUnit(displayUnit);
874         return result;
875     }
876 
877     /**
878      * Return the current scalar as a luminousflux.
879      * @return LuminousFlux; the current scalar as a luminousflux
880      */
881     public final LuminousFlux asLuminousFlux()
882     {
883         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousFluxUnit.BASE.getSiDimensions())),
884                 UnitRuntimeException.class, "cannot cast %s to LuminousFlux", this.toString());
885         return new LuminousFlux(getSI(), LuminousFluxUnit.SI);
886     }
887 
888     /**
889      * Return the current scalar as a luminousflux, and provide a display unit.
890      * @param displayUnit the unit in which the value will be displayed
891      * @return LuminousFlux; the current scalar as a luminousflux
892      */
893     public final LuminousFlux asLuminousFlux(final LuminousFluxUnit displayUnit)
894     {
895         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousFluxUnit.BASE.getSiDimensions())),
896                 UnitRuntimeException.class, "cannot cast %s to LuminousFlux", this.toString());
897         LuminousFluxr/LuminousFlux.html#LuminousFlux">LuminousFlux result = new LuminousFlux(getSI(), displayUnit.getStandardUnit());
898         result.setDisplayUnit(displayUnit);
899         return result;
900     }
901 
902     /**
903      * Return the current scalar as a luminousintensity.
904      * @return LuminousIntensity; the current scalar as a luminousintensity
905      */
906     public final LuminousIntensity asLuminousIntensity()
907     {
908         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousIntensityUnit.BASE.getSiDimensions())),
909                 UnitRuntimeException.class, "cannot cast %s to LuminousIntensity", this.toString());
910         return new LuminousIntensity(getSI(), LuminousIntensityUnit.SI);
911     }
912 
913     /**
914      * Return the current scalar as a luminousintensity, and provide a display unit.
915      * @param displayUnit the unit in which the value will be displayed
916      * @return LuminousIntensity; the current scalar as a luminousintensity
917      */
918     public final LuminousIntensity asLuminousIntensity(final LuminousIntensityUnit displayUnit)
919     {
920         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousIntensityUnit.BASE.getSiDimensions())),
921                 UnitRuntimeException.class, "cannot cast %s to LuminousIntensity", this.toString());
922         LuminousIntensityinousIntensity.html#LuminousIntensity">LuminousIntensity result = new LuminousIntensity(getSI(), displayUnit.getStandardUnit());
923         result.setDisplayUnit(displayUnit);
924         return result;
925     }
926 
927     /**
928      * Return the current scalar as a magneticfluxdensity.
929      * @return MagneticFluxDensity; the current scalar as a magneticfluxdensity
930      */
931     public final MagneticFluxDensity asMagneticFluxDensity()
932     {
933         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxDensityUnit.BASE.getSiDimensions())),
934                 UnitRuntimeException.class, "cannot cast %s to MagneticFluxDensity", this.toString());
935         return new MagneticFluxDensity(getSI(), MagneticFluxDensityUnit.SI);
936     }
937 
938     /**
939      * Return the current scalar as a magneticfluxdensity, and provide a display unit.
940      * @param displayUnit the unit in which the value will be displayed
941      * @return MagneticFluxDensity; the current scalar as a magneticfluxdensity
942      */
943     public final MagneticFluxDensity asMagneticFluxDensity(final MagneticFluxDensityUnit displayUnit)
944     {
945         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxDensityUnit.BASE.getSiDimensions())),
946                 UnitRuntimeException.class, "cannot cast %s to MagneticFluxDensity", this.toString());
947         MagneticFluxDensityticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity result = new MagneticFluxDensity(getSI(), displayUnit.getStandardUnit());
948         result.setDisplayUnit(displayUnit);
949         return result;
950     }
951 
952     /**
953      * Return the current scalar as a magneticflux.
954      * @return MagneticFlux; the current scalar as a magneticflux
955      */
956     public final MagneticFlux asMagneticFlux()
957     {
958         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxUnit.BASE.getSiDimensions())),
959                 UnitRuntimeException.class, "cannot cast %s to MagneticFlux", this.toString());
960         return new MagneticFlux(getSI(), MagneticFluxUnit.SI);
961     }
962 
963     /**
964      * Return the current scalar as a magneticflux, and provide a display unit.
965      * @param displayUnit the unit in which the value will be displayed
966      * @return MagneticFlux; the current scalar as a magneticflux
967      */
968     public final MagneticFlux asMagneticFlux(final MagneticFluxUnit displayUnit)
969     {
970         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxUnit.BASE.getSiDimensions())),
971                 UnitRuntimeException.class, "cannot cast %s to MagneticFlux", this.toString());
972         MagneticFluxr/MagneticFlux.html#MagneticFlux">MagneticFlux result = new MagneticFlux(getSI(), displayUnit.getStandardUnit());
973         result.setDisplayUnit(displayUnit);
974         return result;
975     }
976 
977     /**
978      * Return the current scalar as a mass.
979      * @return Mass; the current scalar as a mass
980      */
981     public final Mass asMass()
982     {
983         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MassUnit.BASE.getSiDimensions())),
984                 UnitRuntimeException.class, "cannot cast %s to Mass", this.toString());
985         return new Mass(getSI(), MassUnit.SI);
986     }
987 
988     /**
989      * Return the current scalar as a mass, and provide a display unit.
990      * @param displayUnit the unit in which the value will be displayed
991      * @return Mass; the current scalar as a mass
992      */
993     public final Mass asMass(final MassUnit displayUnit)
994     {
995         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MassUnit.BASE.getSiDimensions())),
996                 UnitRuntimeException.class, "cannot cast %s to Mass", this.toString());
997         Massle/scalar/Mass.html#Mass">Mass result = new Mass(getSI(), displayUnit.getStandardUnit());
998         result.setDisplayUnit(displayUnit);
999         return result;
1000     }
1001 
1002     /**
1003      * Return the current scalar as a momentum.
1004      * @return Momentum; the current scalar as a momentum
1005      */
1006     public final Momentum asMomentum()
1007     {
1008         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MomentumUnit.BASE.getSiDimensions())),
1009                 UnitRuntimeException.class, "cannot cast %s to Momentum", this.toString());
1010         return new Momentum(getSI(), MomentumUnit.SI);
1011     }
1012 
1013     /**
1014      * Return the current scalar as a momentum, and provide a display unit.
1015      * @param displayUnit the unit in which the value will be displayed
1016      * @return Momentum; the current scalar as a momentum
1017      */
1018     public final Momentum asMomentum(final MomentumUnit displayUnit)
1019     {
1020         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MomentumUnit.BASE.getSiDimensions())),
1021                 UnitRuntimeException.class, "cannot cast %s to Momentum", this.toString());
1022         Momentumcalar/Momentum.html#Momentum">Momentum result = new Momentum(getSI(), displayUnit.getStandardUnit());
1023         result.setDisplayUnit(displayUnit);
1024         return result;
1025     }
1026 
1027     /**
1028      * Return the current scalar as a power.
1029      * @return Power; the current scalar as a power
1030      */
1031     public final Power asPower()
1032     {
1033         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(PowerUnit.BASE.getSiDimensions())),
1034                 UnitRuntimeException.class, "cannot cast %s to Power", this.toString());
1035         return new Power(getSI(), PowerUnit.SI);
1036     }
1037 
1038     /**
1039      * Return the current scalar as a power, and provide a display unit.
1040      * @param displayUnit the unit in which the value will be displayed
1041      * @return Power; the current scalar as a power
1042      */
1043     public final Power asPower(final PowerUnit displayUnit)
1044     {
1045         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(PowerUnit.BASE.getSiDimensions())),
1046                 UnitRuntimeException.class, "cannot cast %s to Power", this.toString());
1047         Powere/scalar/Power.html#Power">Power result = new Power(getSI(), displayUnit.getStandardUnit());
1048         result.setDisplayUnit(displayUnit);
1049         return result;
1050     }
1051 
1052     /**
1053      * Return the current scalar as a pressure.
1054      * @return Pressure; the current scalar as a pressure
1055      */
1056     public final Pressure asPressure()
1057     {
1058         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(PressureUnit.BASE.getSiDimensions())),
1059                 UnitRuntimeException.class, "cannot cast %s to Pressure", this.toString());
1060         return new Pressure(getSI(), PressureUnit.SI);
1061     }
1062 
1063     /**
1064      * Return the current scalar as a pressure, and provide a display unit.
1065      * @param displayUnit the unit in which the value will be displayed
1066      * @return Pressure; the current scalar as a pressure
1067      */
1068     public final Pressure asPressure(final PressureUnit displayUnit)
1069     {
1070         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(PressureUnit.BASE.getSiDimensions())),
1071                 UnitRuntimeException.class, "cannot cast %s to Pressure", this.toString());
1072         Pressurecalar/Pressure.html#Pressure">Pressure result = new Pressure(getSI(), displayUnit.getStandardUnit());
1073         result.setDisplayUnit(displayUnit);
1074         return result;
1075     }
1076 
1077     /**
1078      * Return the current scalar as a radioactivity.
1079      * @return RadioActivity; the current scalar as a radioactivity
1080      */
1081     public final RadioActivity asRadioActivity()
1082     {
1083         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(RadioActivityUnit.BASE.getSiDimensions())),
1084                 UnitRuntimeException.class, "cannot cast %s to RadioActivity", this.toString());
1085         return new RadioActivity(getSI(), RadioActivityUnit.SI);
1086     }
1087 
1088     /**
1089      * Return the current scalar as a radioactivity, and provide a display unit.
1090      * @param displayUnit the unit in which the value will be displayed
1091      * @return RadioActivity; the current scalar as a radioactivity
1092      */
1093     public final RadioActivity asRadioActivity(final RadioActivityUnit displayUnit)
1094     {
1095         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(RadioActivityUnit.BASE.getSiDimensions())),
1096                 UnitRuntimeException.class, "cannot cast %s to RadioActivity", this.toString());
1097         RadioActivity/RadioActivity.html#RadioActivity">RadioActivity result = new RadioActivity(getSI(), displayUnit.getStandardUnit());
1098         result.setDisplayUnit(displayUnit);
1099         return result;
1100     }
1101 
1102     /**
1103      * Return the current scalar as a solidangle.
1104      * @return SolidAngle; the current scalar as a solidangle
1105      */
1106     public final SolidAngle asSolidAngle()
1107     {
1108         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SolidAngleUnit.BASE.getSiDimensions())),
1109                 UnitRuntimeException.class, "cannot cast %s to SolidAngle", this.toString());
1110         return new SolidAngle(getSI(), SolidAngleUnit.SI);
1111     }
1112 
1113     /**
1114      * Return the current scalar as a solidangle, and provide a display unit.
1115      * @param displayUnit the unit in which the value will be displayed
1116      * @return SolidAngle; the current scalar as a solidangle
1117      */
1118     public final SolidAngle asSolidAngle(final SolidAngleUnit displayUnit)
1119     {
1120         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SolidAngleUnit.BASE.getSiDimensions())),
1121                 UnitRuntimeException.class, "cannot cast %s to SolidAngle", this.toString());
1122         SolidAnglelar/SolidAngle.html#SolidAngle">SolidAngle result = new SolidAngle(getSI(), displayUnit.getStandardUnit());
1123         result.setDisplayUnit(displayUnit);
1124         return result;
1125     }
1126 
1127     /**
1128      * Return the current scalar as a speed.
1129      * @return Speed; the current scalar as a speed
1130      */
1131     public final Speed asSpeed()
1132     {
1133         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SpeedUnit.BASE.getSiDimensions())),
1134                 UnitRuntimeException.class, "cannot cast %s to Speed", this.toString());
1135         return new Speed(getSI(), SpeedUnit.SI);
1136     }
1137 
1138     /**
1139      * Return the current scalar as a speed, and provide a display unit.
1140      * @param displayUnit the unit in which the value will be displayed
1141      * @return Speed; the current scalar as a speed
1142      */
1143     public final Speed asSpeed(final SpeedUnit displayUnit)
1144     {
1145         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SpeedUnit.BASE.getSiDimensions())),
1146                 UnitRuntimeException.class, "cannot cast %s to Speed", this.toString());
1147         Speede/scalar/Speed.html#Speed">Speed result = new Speed(getSI(), displayUnit.getStandardUnit());
1148         result.setDisplayUnit(displayUnit);
1149         return result;
1150     }
1151 
1152     /**
1153      * Return the current scalar as a torque.
1154      * @return Torque; the current scalar as a torque
1155      */
1156     public final Torque asTorque()
1157     {
1158         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TorqueUnit.BASE.getSiDimensions())),
1159                 UnitRuntimeException.class, "cannot cast %s to Torque", this.toString());
1160         return new Torque(getSI(), TorqueUnit.SI);
1161     }
1162 
1163     /**
1164      * Return the current scalar as a torque, and provide a display unit.
1165      * @param displayUnit the unit in which the value will be displayed
1166      * @return Torque; the current scalar as a torque
1167      */
1168     public final Torque asTorque(final TorqueUnit displayUnit)
1169     {
1170         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TorqueUnit.BASE.getSiDimensions())),
1171                 UnitRuntimeException.class, "cannot cast %s to Torque", this.toString());
1172         Torque/scalar/Torque.html#Torque">Torque result = new Torque(getSI(), displayUnit.getStandardUnit());
1173         result.setDisplayUnit(displayUnit);
1174         return result;
1175     }
1176 
1177     /**
1178      * Return the current scalar as a volume.
1179      * @return Volume; the current scalar as a volume
1180      */
1181     public final Volume asVolume()
1182     {
1183         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(VolumeUnit.BASE.getSiDimensions())),
1184                 UnitRuntimeException.class, "cannot cast %s to Volume", this.toString());
1185         return new Volume(getSI(), VolumeUnit.SI);
1186     }
1187 
1188     /**
1189      * Return the current scalar as a volume, and provide a display unit.
1190      * @param displayUnit the unit in which the value will be displayed
1191      * @return Volume; the current scalar as a volume
1192      */
1193     public final Volume asVolume(final VolumeUnit displayUnit)
1194     {
1195         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(VolumeUnit.BASE.getSiDimensions())),
1196                 UnitRuntimeException.class, "cannot cast %s to Volume", this.toString());
1197         Volume/scalar/Volume.html#Volume">Volume result = new Volume(getSI(), displayUnit.getStandardUnit());
1198         result.setDisplayUnit(displayUnit);
1199         return result;
1200     }
1201 
1202     /**
1203      * Return the current scalar as a angle.
1204      * @return Angle; the current scalar as a angle
1205      */
1206     public final Angle asAngle()
1207     {
1208         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngleUnit.BASE.getSiDimensions())),
1209                 UnitRuntimeException.class, "cannot cast %s to Angle", this.toString());
1210         return new Angle(getSI(), AngleUnit.SI);
1211     }
1212 
1213     /**
1214      * Return the current scalar as a angle, and provide a display unit.
1215      * @param displayUnit the unit in which the value will be displayed
1216      * @return Angle; the current scalar as a angle
1217      */
1218     public final Angle asAngle(final AngleUnit displayUnit)
1219     {
1220         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngleUnit.BASE.getSiDimensions())),
1221                 UnitRuntimeException.class, "cannot cast %s to Angle", this.toString());
1222         Anglee/scalar/Angle.html#Angle">Angle result = new Angle(getSI(), displayUnit.getStandardUnit());
1223         result.setDisplayUnit(displayUnit);
1224         return result;
1225     }
1226 
1227     /**
1228      * Return the current scalar as a length.
1229      * @return Length; the current scalar as a length
1230      */
1231     public final Length asLength()
1232     {
1233         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LengthUnit.BASE.getSiDimensions())),
1234                 UnitRuntimeException.class, "cannot cast %s to Length", this.toString());
1235         return new Length(getSI(), LengthUnit.SI);
1236     }
1237 
1238     /**
1239      * Return the current scalar as a length, and provide a display unit.
1240      * @param displayUnit the unit in which the value will be displayed
1241      * @return Length; the current scalar as a length
1242      */
1243     public final Length asLength(final LengthUnit displayUnit)
1244     {
1245         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LengthUnit.BASE.getSiDimensions())),
1246                 UnitRuntimeException.class, "cannot cast %s to Length", this.toString());
1247         Length/scalar/Length.html#Length">Length result = new Length(getSI(), displayUnit.getStandardUnit());
1248         result.setDisplayUnit(displayUnit);
1249         return result;
1250     }
1251 
1252     /**
1253      * Return the current scalar as a temperature.
1254      * @return Temperature; the current scalar as a temperature
1255      */
1256     public final Temperature asTemperature()
1257     {
1258         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TemperatureUnit.BASE.getSiDimensions())),
1259                 UnitRuntimeException.class, "cannot cast %s to Temperature", this.toString());
1260         return new Temperature(getSI(), TemperatureUnit.SI);
1261     }
1262 
1263     /**
1264      * Return the current scalar as a temperature, and provide a display unit.
1265      * @param displayUnit the unit in which the value will be displayed
1266      * @return Temperature; the current scalar as a temperature
1267      */
1268     public final Temperature asTemperature(final TemperatureUnit displayUnit)
1269     {
1270         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TemperatureUnit.BASE.getSiDimensions())),
1271                 UnitRuntimeException.class, "cannot cast %s to Temperature", this.toString());
1272         Temperaturear/Temperature.html#Temperature">Temperature result = new Temperature(getSI(), displayUnit.getStandardUnit());
1273         result.setDisplayUnit(displayUnit);
1274         return result;
1275     }
1276 
1277     /**
1278      * Return the current scalar as a duration.
1279      * @return Duration; the current scalar as a duration
1280      */
1281     public final Duration asDuration()
1282     {
1283         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DurationUnit.BASE.getSiDimensions())),
1284                 UnitRuntimeException.class, "cannot cast %s to Duration", this.toString());
1285         return new Duration(getSI(), DurationUnit.SI);
1286     }
1287 
1288     /**
1289      * Return the current scalar as a duration, and provide a display unit.
1290      * @param displayUnit the unit in which the value will be displayed
1291      * @return Duration; the current scalar as a duration
1292      */
1293     public final Duration asDuration(final DurationUnit displayUnit)
1294     {
1295         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DurationUnit.BASE.getSiDimensions())),
1296                 UnitRuntimeException.class, "cannot cast %s to Duration", this.toString());
1297         Durationcalar/Duration.html#Duration">Duration result = new Duration(getSI(), displayUnit.getStandardUnit());
1298         result.setDisplayUnit(displayUnit);
1299         return result;
1300     }
1301 
1302 }