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