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