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