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