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