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