SIScalar.java

  1. package org.djunits.value.vdouble.scalar;

  2. import java.util.Locale;

  3. import org.djunits.unit.AbsorbedDoseUnit;
  4. import org.djunits.unit.AccelerationUnit;
  5. import org.djunits.unit.AmountOfSubstanceUnit;
  6. import org.djunits.unit.AngleUnit;
  7. import org.djunits.unit.AngularAccelerationUnit;
  8. import org.djunits.unit.AngularVelocityUnit;
  9. import org.djunits.unit.AreaUnit;
  10. import org.djunits.unit.CatalyticActivityUnit;
  11. import org.djunits.unit.DensityUnit;
  12. import org.djunits.unit.DimensionlessUnit;
  13. import org.djunits.unit.DurationUnit;
  14. import org.djunits.unit.ElectricalCapacitanceUnit;
  15. import org.djunits.unit.ElectricalChargeUnit;
  16. import org.djunits.unit.ElectricalConductanceUnit;
  17. import org.djunits.unit.ElectricalCurrentUnit;
  18. import org.djunits.unit.ElectricalInductanceUnit;
  19. import org.djunits.unit.ElectricalPotentialUnit;
  20. import org.djunits.unit.ElectricalResistanceUnit;
  21. import org.djunits.unit.EnergyUnit;
  22. import org.djunits.unit.EquivalentDoseUnit;
  23. import org.djunits.unit.FlowMassUnit;
  24. import org.djunits.unit.FlowVolumeUnit;
  25. import org.djunits.unit.ForceUnit;
  26. import org.djunits.unit.FrequencyUnit;
  27. import org.djunits.unit.IlluminanceUnit;
  28. import org.djunits.unit.LengthUnit;
  29. import org.djunits.unit.LinearDensityUnit;
  30. import org.djunits.unit.LuminousFluxUnit;
  31. import org.djunits.unit.LuminousIntensityUnit;
  32. import org.djunits.unit.MagneticFluxDensityUnit;
  33. import org.djunits.unit.MagneticFluxUnit;
  34. import org.djunits.unit.MassUnit;
  35. import org.djunits.unit.MomentumUnit;
  36. import org.djunits.unit.PowerUnit;
  37. import org.djunits.unit.PressureUnit;
  38. import org.djunits.unit.RadioActivityUnit;
  39. import org.djunits.unit.SIUnit;
  40. import org.djunits.unit.SolidAngleUnit;
  41. import org.djunits.unit.SpeedUnit;
  42. import org.djunits.unit.TemperatureUnit;
  43. import org.djunits.unit.TorqueUnit;
  44. import org.djunits.unit.Unit;
  45. import org.djunits.unit.VolumeUnit;
  46. import org.djunits.unit.si.SIDimensions;
  47. import org.djunits.unit.util.UnitRuntimeException;
  48. import org.djunits.value.vdouble.scalar.base.DoubleScalar;
  49. import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
  50. import org.djutils.base.NumberParser;
  51. import org.djutils.exceptions.Throw;

  52. import jakarta.annotation.Generated;

  53. /**
  54.  * Easy access methods for the generic Relative SI DoubleScalar.
  55.  * <p>
  56.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
  57.  * All rights reserved. <br>
  58.  * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
  59.  * </p>
  60.  * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  61.  * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
  62.  */
  63. @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
  64. public class SIScalar extends DoubleScalarRel<SIUnit, SIScalar>
  65. {
  66.     /** */
  67.     private static final long serialVersionUID = 20150901L;

  68.     /**
  69.      * Construct SI scalar.
  70.      * @param value double; the double value
  71.      * @param unit SIUnit; unit for the double value
  72.      */
  73.     public SIScalar(final double value, final SIUnit unit)
  74.     {
  75.         super(value, unit);
  76.     }

  77.     /**
  78.      * Construct SI scalar.
  79.      * @param value SIScalar; Scalar from which to construct this instance
  80.      */
  81.     public SIScalar(final SIScalar value)
  82.     {
  83.         super(value);
  84.     }

  85.     @Override
  86.     public final SIScalar instantiateRel(final double value, final SIUnit unit)
  87.     {
  88.         return new SIScalar(value, unit);
  89.     }

  90.     /**
  91.      * Construct SI scalar.
  92.      * @param value double; the double value in SI units
  93.      * @param unit SIUnit; the unit to use for the SI scalar
  94.      * @return SIScalar; the new scalar with the SI value
  95.      */
  96.     public static final SIScalar instantiateSI(final double value, final SIUnit unit)
  97.     {
  98.         return new SIScalar(value, unit);
  99.     }

  100.     /**
  101.      * Interpolate between two values.
  102.      * @param zero SIScalar; the low value
  103.      * @param one SIScalar; the high value
  104.      * @param ratio double; the ratio between 0 and 1, inclusive
  105.      * @return SIScalar; a Scalar at the ratio between
  106.      */
  107.     public static SIScalar interpolate(final SIScalar zero, final SIScalar one, final double ratio)
  108.     {
  109.         return new SIScalar(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
  110.                 zero.getDisplayUnit());
  111.     }

  112.     /**
  113.      * Return the maximum value of two relative scalars.
  114.      * @param r1 SIScalar; the first scalar
  115.      * @param r2 SIScalar; the second scalar
  116.      * @return SIScalar; the maximum value of two relative scalars
  117.      */
  118.     public static SIScalar max(final SIScalar r1, final SIScalar r2)
  119.     {
  120.         return r1.gt(r2) ? r1 : r2;
  121.     }

  122.     /**
  123.      * Return the maximum value of more than two relative scalars.
  124.      * @param r1 SIScalar; the first scalar
  125.      * @param r2 SIScalar; the second scalar
  126.      * @param rn SIScalar...; the other scalars
  127.      * @return SIScalar; the maximum value of more than two relative scalars
  128.      */
  129.     public static SIScalar max(final SIScalar r1, final SIScalar r2, final SIScalar... rn)
  130.     {
  131.         SIScalar maxr = r1.gt(r2) ? r1 : r2;
  132.         for (SIScalar r : rn)
  133.         {
  134.             if (r.gt(maxr))
  135.             {
  136.                 maxr = r;
  137.             }
  138.         }
  139.         return maxr;
  140.     }

  141.     /**
  142.      * Return the minimum value of two relative scalars.
  143.      * @param r1 SIScalar; the first scalar
  144.      * @param r2 SIScalar; the second scalar
  145.      * @return SIScalar; the minimum value of two relative scalars
  146.      */
  147.     public static SIScalar min(final SIScalar r1, final SIScalar r2)
  148.     {
  149.         return r1.lt(r2) ? r1 : r2;
  150.     }

  151.     /**
  152.      * Return the minimum value of more than two relative scalars.
  153.      * @param r1 SIScalar; the first scalar
  154.      * @param r2 SIScalar; the second scalar
  155.      * @param rn SIScalar...; the other scalars
  156.      * @return SIScalar; the minimum value of more than two relative scalars
  157.      */
  158.     public static SIScalar min(final SIScalar r1, final SIScalar r2, final SIScalar... rn)
  159.     {
  160.         SIScalar minr = r1.lt(r2) ? r1 : r2;
  161.         for (SIScalar r : rn)
  162.         {
  163.             if (r.lt(minr))
  164.             {
  165.                 minr = r;
  166.             }
  167.         }
  168.         return minr;
  169.     }

  170.     @Override
  171.     public SIScalar reciprocal()
  172.     {
  173.         return DoubleScalar.divide(Dimensionless.ONE, this);
  174.     }

  175.     /**
  176.      * Returns an SIScalar representation of a textual representation of a value with a unit. The String representation that can
  177.      * be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but not
  178.      * required, between the value and the unit.
  179.      * @param text String; the textual representation to parse into a SIScalar
  180.      * @return SIScalar; the Scalar representation of the value in its unit
  181.      * @throws IllegalArgumentException when the text cannot be parsed
  182.      * @throws NullPointerException when the text argument is null
  183.      */
  184.     public static SIScalar valueOf(final String text)
  185.     {
  186.         Throw.whenNull(text, "Error parsing SIScalar: unitString is null");
  187.         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing SIScalar: empty string to parse");
  188.         try
  189.         {
  190.             NumberParser numberParser = new NumberParser().lenient().trailing();
  191.             double d = numberParser.parseDouble(text);
  192.             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
  193.             SIUnit unit = Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(unitString));
  194.             if (unit == null)
  195.                 throw new IllegalArgumentException("Unit " + unitString + " for SIScalar not found");
  196.             return new SIScalar(d, unit);
  197.         }
  198.         catch (Exception exception)
  199.         {
  200.             throw new IllegalArgumentException(
  201.                     "Error parsing SIScalar from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
  202.                     exception);
  203.         }
  204.     }

  205.     /**
  206.      * Returns an SIScalar based on a value and the textual representation of the unit.
  207.      * @param value double; the value to use
  208.      * @param unitString String; the textual representation of the unit
  209.      * @return SIScalar; the Scalar representation of the value in its unit
  210.      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
  211.      * @throws NullPointerException when the unitString argument is null
  212.      */
  213.     public static SIScalar of(final double value, final String unitString)
  214.     {
  215.         Throw.whenNull(unitString, "Error parsing SIScalar: unitString is null");
  216.         try
  217.         {
  218.             SIUnit unit = Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(unitString));
  219.             if (unit != null)
  220.             {
  221.                 return new SIScalar(value, unit);
  222.             }
  223.         }
  224.         catch (Exception exception)
  225.         {
  226.             throw new IllegalArgumentException("Error parsing SIUnit from " + unitString, exception);
  227.         }
  228.         throw new IllegalArgumentException("Error parsing SIScalar with unit " + unitString);
  229.     }

  230.     @Override
  231.     public String toString(final SIUnit displayUnit, final boolean verbose, final boolean withUnit)
  232.     {
  233.         return super.toString(displayUnit, verbose, withUnit).replaceAll("!", "");
  234.     }

  235.     /**********************************************************************************/
  236.     /******************************** 'CAST AS' METHODS *******************************/
  237.     /**********************************************************************************/

  238.     /**
  239.      * Return the current scalar transformed to a scalar in the given unit. Of course the SI dimensionality has to match,
  240.      * otherwise the scalar cannot be transformed. The compiler will check the alignment between the return value and the unit.
  241.      * @param displayUnit KU; the unit in which the scalar needs to be expressed
  242.      * @return S; the scalar that has been transformed into the right scalar type and unit
  243.      * @param <U> the unit type
  244.      * @param <S> the scalar type
  245.      */
  246.     public final <U extends Unit<U>, S extends DoubleScalarRel<U, S>> S as(final U displayUnit)
  247.     {
  248.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(displayUnit.getQuantity().getSiDimensions())),
  249.                 UnitRuntimeException.class, "SIScalar with unit %s cannot be converted to a scalar with unit %s",
  250.                 getDisplayUnit(), displayUnit);
  251.         S result = DoubleScalar.instantiate(this.si, displayUnit.getStandardUnit());
  252.         result.setDisplayUnit(displayUnit);
  253.         return result;
  254.     }

  255.     /**
  256.      * Return the current scalar as a absorbeddose.
  257.      * @return AbsorbedDose; the current scalar as a absorbeddose
  258.      */
  259.     public final AbsorbedDose asAbsorbedDose()
  260.     {
  261.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AbsorbedDoseUnit.BASE.getSiDimensions())),
  262.                 UnitRuntimeException.class, "cannot cast %s to AbsorbedDose", this.toString());
  263.         return new AbsorbedDose(getSI(), AbsorbedDoseUnit.SI);
  264.     }

  265.     /**
  266.      * Return the current scalar as a absorbeddose, and provide a display unit.
  267.      * @param displayUnit the unit in which the value will be displayed
  268.      * @return AbsorbedDose; the current scalar as a absorbeddose
  269.      */
  270.     public final AbsorbedDose asAbsorbedDose(final AbsorbedDoseUnit displayUnit)
  271.     {
  272.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AbsorbedDoseUnit.BASE.getSiDimensions())),
  273.                 UnitRuntimeException.class, "cannot cast %s to AbsorbedDose", this.toString());
  274.         AbsorbedDose result = new AbsorbedDose(getSI(), displayUnit.getStandardUnit());
  275.         result.setDisplayUnit(displayUnit);
  276.         return result;
  277.     }

  278.     /**
  279.      * Return the current scalar as a acceleration.
  280.      * @return Acceleration; the current scalar as a acceleration
  281.      */
  282.     public final Acceleration asAcceleration()
  283.     {
  284.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AccelerationUnit.BASE.getSiDimensions())),
  285.                 UnitRuntimeException.class, "cannot cast %s to Acceleration", this.toString());
  286.         return new Acceleration(getSI(), AccelerationUnit.SI);
  287.     }

  288.     /**
  289.      * Return the current scalar as a acceleration, and provide a display unit.
  290.      * @param displayUnit the unit in which the value will be displayed
  291.      * @return Acceleration; the current scalar as a acceleration
  292.      */
  293.     public final Acceleration asAcceleration(final AccelerationUnit displayUnit)
  294.     {
  295.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AccelerationUnit.BASE.getSiDimensions())),
  296.                 UnitRuntimeException.class, "cannot cast %s to Acceleration", this.toString());
  297.         Acceleration result = new Acceleration(getSI(), displayUnit.getStandardUnit());
  298.         result.setDisplayUnit(displayUnit);
  299.         return result;
  300.     }

  301.     /**
  302.      * Return the current scalar as a amountofsubstance.
  303.      * @return AmountOfSubstance; the current scalar as a amountofsubstance
  304.      */
  305.     public final AmountOfSubstance asAmountOfSubstance()
  306.     {
  307.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AmountOfSubstanceUnit.BASE.getSiDimensions())),
  308.                 UnitRuntimeException.class, "cannot cast %s to AmountOfSubstance", this.toString());
  309.         return new AmountOfSubstance(getSI(), AmountOfSubstanceUnit.SI);
  310.     }

  311.     /**
  312.      * Return the current scalar as a amountofsubstance, and provide a display unit.
  313.      * @param displayUnit the unit in which the value will be displayed
  314.      * @return AmountOfSubstance; the current scalar as a amountofsubstance
  315.      */
  316.     public final AmountOfSubstance asAmountOfSubstance(final AmountOfSubstanceUnit displayUnit)
  317.     {
  318.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AmountOfSubstanceUnit.BASE.getSiDimensions())),
  319.                 UnitRuntimeException.class, "cannot cast %s to AmountOfSubstance", this.toString());
  320.         AmountOfSubstance result = new AmountOfSubstance(getSI(), displayUnit.getStandardUnit());
  321.         result.setDisplayUnit(displayUnit);
  322.         return result;
  323.     }

  324.     /**
  325.      * Return the current scalar as a angularacceleration.
  326.      * @return AngularAcceleration; the current scalar as a angularacceleration
  327.      */
  328.     public final AngularAcceleration asAngularAcceleration()
  329.     {
  330.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularAccelerationUnit.BASE.getSiDimensions())),
  331.                 UnitRuntimeException.class, "cannot cast %s to AngularAcceleration", this.toString());
  332.         return new AngularAcceleration(getSI(), AngularAccelerationUnit.SI);
  333.     }

  334.     /**
  335.      * Return the current scalar as a angularacceleration, and provide a display unit.
  336.      * @param displayUnit the unit in which the value will be displayed
  337.      * @return AngularAcceleration; the current scalar as a angularacceleration
  338.      */
  339.     public final AngularAcceleration asAngularAcceleration(final AngularAccelerationUnit displayUnit)
  340.     {
  341.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularAccelerationUnit.BASE.getSiDimensions())),
  342.                 UnitRuntimeException.class, "cannot cast %s to AngularAcceleration", this.toString());
  343.         AngularAcceleration result = new AngularAcceleration(getSI(), displayUnit.getStandardUnit());
  344.         result.setDisplayUnit(displayUnit);
  345.         return result;
  346.     }

  347.     /**
  348.      * Return the current scalar as a angularvelocity.
  349.      * @return AngularVelocity; the current scalar as a angularvelocity
  350.      */
  351.     public final AngularVelocity asAngularVelocity()
  352.     {
  353.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularVelocityUnit.BASE.getSiDimensions())),
  354.                 UnitRuntimeException.class, "cannot cast %s to AngularVelocity", this.toString());
  355.         return new AngularVelocity(getSI(), AngularVelocityUnit.SI);
  356.     }

  357.     /**
  358.      * Return the current scalar as a angularvelocity, and provide a display unit.
  359.      * @param displayUnit the unit in which the value will be displayed
  360.      * @return AngularVelocity; the current scalar as a angularvelocity
  361.      */
  362.     public final AngularVelocity asAngularVelocity(final AngularVelocityUnit displayUnit)
  363.     {
  364.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngularVelocityUnit.BASE.getSiDimensions())),
  365.                 UnitRuntimeException.class, "cannot cast %s to AngularVelocity", this.toString());
  366.         AngularVelocity result = new AngularVelocity(getSI(), displayUnit.getStandardUnit());
  367.         result.setDisplayUnit(displayUnit);
  368.         return result;
  369.     }

  370.     /**
  371.      * Return the current scalar as a area.
  372.      * @return Area; the current scalar as a area
  373.      */
  374.     public final Area asArea()
  375.     {
  376.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AreaUnit.BASE.getSiDimensions())),
  377.                 UnitRuntimeException.class, "cannot cast %s to Area", this.toString());
  378.         return new Area(getSI(), AreaUnit.SI);
  379.     }

  380.     /**
  381.      * Return the current scalar as a area, and provide a display unit.
  382.      * @param displayUnit the unit in which the value will be displayed
  383.      * @return Area; the current scalar as a area
  384.      */
  385.     public final Area asArea(final AreaUnit displayUnit)
  386.     {
  387.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AreaUnit.BASE.getSiDimensions())),
  388.                 UnitRuntimeException.class, "cannot cast %s to Area", this.toString());
  389.         Area result = new Area(getSI(), displayUnit.getStandardUnit());
  390.         result.setDisplayUnit(displayUnit);
  391.         return result;
  392.     }

  393.     /**
  394.      * Return the current scalar as a catalyticactivity.
  395.      * @return CatalyticActivity; the current scalar as a catalyticactivity
  396.      */
  397.     public final CatalyticActivity asCatalyticActivity()
  398.     {
  399.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(CatalyticActivityUnit.BASE.getSiDimensions())),
  400.                 UnitRuntimeException.class, "cannot cast %s to CatalyticActivity", this.toString());
  401.         return new CatalyticActivity(getSI(), CatalyticActivityUnit.SI);
  402.     }

  403.     /**
  404.      * Return the current scalar as a catalyticactivity, and provide a display unit.
  405.      * @param displayUnit the unit in which the value will be displayed
  406.      * @return CatalyticActivity; the current scalar as a catalyticactivity
  407.      */
  408.     public final CatalyticActivity asCatalyticActivity(final CatalyticActivityUnit displayUnit)
  409.     {
  410.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(CatalyticActivityUnit.BASE.getSiDimensions())),
  411.                 UnitRuntimeException.class, "cannot cast %s to CatalyticActivity", this.toString());
  412.         CatalyticActivity result = new CatalyticActivity(getSI(), displayUnit.getStandardUnit());
  413.         result.setDisplayUnit(displayUnit);
  414.         return result;
  415.     }

  416.     /**
  417.      * Return the current scalar as a density.
  418.      * @return Density; the current scalar as a density
  419.      */
  420.     public final Density asDensity()
  421.     {
  422.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DensityUnit.BASE.getSiDimensions())),
  423.                 UnitRuntimeException.class, "cannot cast %s to Density", this.toString());
  424.         return new Density(getSI(), DensityUnit.SI);
  425.     }

  426.     /**
  427.      * Return the current scalar as a density, and provide a display unit.
  428.      * @param displayUnit the unit in which the value will be displayed
  429.      * @return Density; the current scalar as a density
  430.      */
  431.     public final Density asDensity(final DensityUnit displayUnit)
  432.     {
  433.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DensityUnit.BASE.getSiDimensions())),
  434.                 UnitRuntimeException.class, "cannot cast %s to Density", this.toString());
  435.         Density result = new Density(getSI(), displayUnit.getStandardUnit());
  436.         result.setDisplayUnit(displayUnit);
  437.         return result;
  438.     }

  439.     /**
  440.      * Return the current scalar as a dimensionless.
  441.      * @return Dimensionless; the current scalar as a dimensionless
  442.      */
  443.     public final Dimensionless asDimensionless()
  444.     {
  445.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DimensionlessUnit.BASE.getSiDimensions())),
  446.                 UnitRuntimeException.class, "cannot cast %s to Dimensionless", this.toString());
  447.         return new Dimensionless(getSI(), DimensionlessUnit.SI);
  448.     }

  449.     /**
  450.      * Return the current scalar as a dimensionless, and provide a display unit.
  451.      * @param displayUnit the unit in which the value will be displayed
  452.      * @return Dimensionless; the current scalar as a dimensionless
  453.      */
  454.     public final Dimensionless asDimensionless(final DimensionlessUnit displayUnit)
  455.     {
  456.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DimensionlessUnit.BASE.getSiDimensions())),
  457.                 UnitRuntimeException.class, "cannot cast %s to Dimensionless", this.toString());
  458.         Dimensionless result = new Dimensionless(getSI(), displayUnit.getStandardUnit());
  459.         result.setDisplayUnit(displayUnit);
  460.         return result;
  461.     }

  462.     /**
  463.      * Return the current scalar as a electricalcapacitance.
  464.      * @return ElectricalCapacitance; the current scalar as a electricalcapacitance
  465.      */
  466.     public final ElectricalCapacitance asElectricalCapacitance()
  467.     {
  468.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCapacitanceUnit.BASE.getSiDimensions())),
  469.                 UnitRuntimeException.class, "cannot cast %s to ElectricalCapacitance", this.toString());
  470.         return new ElectricalCapacitance(getSI(), ElectricalCapacitanceUnit.SI);
  471.     }

  472.     /**
  473.      * Return the current scalar as a electricalcapacitance, and provide a display unit.
  474.      * @param displayUnit the unit in which the value will be displayed
  475.      * @return ElectricalCapacitance; the current scalar as a electricalcapacitance
  476.      */
  477.     public final ElectricalCapacitance asElectricalCapacitance(final ElectricalCapacitanceUnit displayUnit)
  478.     {
  479.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCapacitanceUnit.BASE.getSiDimensions())),
  480.                 UnitRuntimeException.class, "cannot cast %s to ElectricalCapacitance", this.toString());
  481.         ElectricalCapacitance result = new ElectricalCapacitance(getSI(), displayUnit.getStandardUnit());
  482.         result.setDisplayUnit(displayUnit);
  483.         return result;
  484.     }

  485.     /**
  486.      * Return the current scalar as a electricalcharge.
  487.      * @return ElectricalCharge; the current scalar as a electricalcharge
  488.      */
  489.     public final ElectricalCharge asElectricalCharge()
  490.     {
  491.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalChargeUnit.BASE.getSiDimensions())),
  492.                 UnitRuntimeException.class, "cannot cast %s to ElectricalCharge", this.toString());
  493.         return new ElectricalCharge(getSI(), ElectricalChargeUnit.SI);
  494.     }

  495.     /**
  496.      * Return the current scalar as a electricalcharge, and provide a display unit.
  497.      * @param displayUnit the unit in which the value will be displayed
  498.      * @return ElectricalCharge; the current scalar as a electricalcharge
  499.      */
  500.     public final ElectricalCharge asElectricalCharge(final ElectricalChargeUnit displayUnit)
  501.     {
  502.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalChargeUnit.BASE.getSiDimensions())),
  503.                 UnitRuntimeException.class, "cannot cast %s to ElectricalCharge", this.toString());
  504.         ElectricalCharge result = new ElectricalCharge(getSI(), displayUnit.getStandardUnit());
  505.         result.setDisplayUnit(displayUnit);
  506.         return result;
  507.     }

  508.     /**
  509.      * Return the current scalar as a electricalconductance.
  510.      * @return ElectricalConductance; the current scalar as a electricalconductance
  511.      */
  512.     public final ElectricalConductance asElectricalConductance()
  513.     {
  514.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalConductanceUnit.BASE.getSiDimensions())),
  515.                 UnitRuntimeException.class, "cannot cast %s to ElectricalConductance", this.toString());
  516.         return new ElectricalConductance(getSI(), ElectricalConductanceUnit.SI);
  517.     }

  518.     /**
  519.      * Return the current scalar as a electricalconductance, and provide a display unit.
  520.      * @param displayUnit the unit in which the value will be displayed
  521.      * @return ElectricalConductance; the current scalar as a electricalconductance
  522.      */
  523.     public final ElectricalConductance asElectricalConductance(final ElectricalConductanceUnit displayUnit)
  524.     {
  525.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalConductanceUnit.BASE.getSiDimensions())),
  526.                 UnitRuntimeException.class, "cannot cast %s to ElectricalConductance", this.toString());
  527.         ElectricalConductance result = new ElectricalConductance(getSI(), displayUnit.getStandardUnit());
  528.         result.setDisplayUnit(displayUnit);
  529.         return result;
  530.     }

  531.     /**
  532.      * Return the current scalar as a electricalcurrent.
  533.      * @return ElectricalCurrent; the current scalar as a electricalcurrent
  534.      */
  535.     public final ElectricalCurrent asElectricalCurrent()
  536.     {
  537.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCurrentUnit.BASE.getSiDimensions())),
  538.                 UnitRuntimeException.class, "cannot cast %s to ElectricalCurrent", this.toString());
  539.         return new ElectricalCurrent(getSI(), ElectricalCurrentUnit.SI);
  540.     }

  541.     /**
  542.      * Return the current scalar as a electricalcurrent, and provide a display unit.
  543.      * @param displayUnit the unit in which the value will be displayed
  544.      * @return ElectricalCurrent; the current scalar as a electricalcurrent
  545.      */
  546.     public final ElectricalCurrent asElectricalCurrent(final ElectricalCurrentUnit displayUnit)
  547.     {
  548.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalCurrentUnit.BASE.getSiDimensions())),
  549.                 UnitRuntimeException.class, "cannot cast %s to ElectricalCurrent", this.toString());
  550.         ElectricalCurrent result = new ElectricalCurrent(getSI(), displayUnit.getStandardUnit());
  551.         result.setDisplayUnit(displayUnit);
  552.         return result;
  553.     }

  554.     /**
  555.      * Return the current scalar as a electricalinductance.
  556.      * @return ElectricalInductance; the current scalar as a electricalinductance
  557.      */
  558.     public final ElectricalInductance asElectricalInductance()
  559.     {
  560.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalInductanceUnit.BASE.getSiDimensions())),
  561.                 UnitRuntimeException.class, "cannot cast %s to ElectricalInductance", this.toString());
  562.         return new ElectricalInductance(getSI(), ElectricalInductanceUnit.SI);
  563.     }

  564.     /**
  565.      * Return the current scalar as a electricalinductance, and provide a display unit.
  566.      * @param displayUnit the unit in which the value will be displayed
  567.      * @return ElectricalInductance; the current scalar as a electricalinductance
  568.      */
  569.     public final ElectricalInductance asElectricalInductance(final ElectricalInductanceUnit displayUnit)
  570.     {
  571.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalInductanceUnit.BASE.getSiDimensions())),
  572.                 UnitRuntimeException.class, "cannot cast %s to ElectricalInductance", this.toString());
  573.         ElectricalInductance result = new ElectricalInductance(getSI(), displayUnit.getStandardUnit());
  574.         result.setDisplayUnit(displayUnit);
  575.         return result;
  576.     }

  577.     /**
  578.      * Return the current scalar as a electricalpotential.
  579.      * @return ElectricalPotential; the current scalar as a electricalpotential
  580.      */
  581.     public final ElectricalPotential asElectricalPotential()
  582.     {
  583.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalPotentialUnit.BASE.getSiDimensions())),
  584.                 UnitRuntimeException.class, "cannot cast %s to ElectricalPotential", this.toString());
  585.         return new ElectricalPotential(getSI(), ElectricalPotentialUnit.SI);
  586.     }

  587.     /**
  588.      * Return the current scalar as a electricalpotential, and provide a display unit.
  589.      * @param displayUnit the unit in which the value will be displayed
  590.      * @return ElectricalPotential; the current scalar as a electricalpotential
  591.      */
  592.     public final ElectricalPotential asElectricalPotential(final ElectricalPotentialUnit displayUnit)
  593.     {
  594.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalPotentialUnit.BASE.getSiDimensions())),
  595.                 UnitRuntimeException.class, "cannot cast %s to ElectricalPotential", this.toString());
  596.         ElectricalPotential result = new ElectricalPotential(getSI(), displayUnit.getStandardUnit());
  597.         result.setDisplayUnit(displayUnit);
  598.         return result;
  599.     }

  600.     /**
  601.      * Return the current scalar as a electricalresistance.
  602.      * @return ElectricalResistance; the current scalar as a electricalresistance
  603.      */
  604.     public final ElectricalResistance asElectricalResistance()
  605.     {
  606.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalResistanceUnit.BASE.getSiDimensions())),
  607.                 UnitRuntimeException.class, "cannot cast %s to ElectricalResistance", this.toString());
  608.         return new ElectricalResistance(getSI(), ElectricalResistanceUnit.SI);
  609.     }

  610.     /**
  611.      * Return the current scalar as a electricalresistance, and provide a display unit.
  612.      * @param displayUnit the unit in which the value will be displayed
  613.      * @return ElectricalResistance; the current scalar as a electricalresistance
  614.      */
  615.     public final ElectricalResistance asElectricalResistance(final ElectricalResistanceUnit displayUnit)
  616.     {
  617.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ElectricalResistanceUnit.BASE.getSiDimensions())),
  618.                 UnitRuntimeException.class, "cannot cast %s to ElectricalResistance", this.toString());
  619.         ElectricalResistance result = new ElectricalResistance(getSI(), displayUnit.getStandardUnit());
  620.         result.setDisplayUnit(displayUnit);
  621.         return result;
  622.     }

  623.     /**
  624.      * Return the current scalar as a energy.
  625.      * @return Energy; the current scalar as a energy
  626.      */
  627.     public final Energy asEnergy()
  628.     {
  629.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EnergyUnit.BASE.getSiDimensions())),
  630.                 UnitRuntimeException.class, "cannot cast %s to Energy", this.toString());
  631.         return new Energy(getSI(), EnergyUnit.SI);
  632.     }

  633.     /**
  634.      * Return the current scalar as a energy, and provide a display unit.
  635.      * @param displayUnit the unit in which the value will be displayed
  636.      * @return Energy; the current scalar as a energy
  637.      */
  638.     public final Energy asEnergy(final EnergyUnit displayUnit)
  639.     {
  640.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EnergyUnit.BASE.getSiDimensions())),
  641.                 UnitRuntimeException.class, "cannot cast %s to Energy", this.toString());
  642.         Energy result = new Energy(getSI(), displayUnit.getStandardUnit());
  643.         result.setDisplayUnit(displayUnit);
  644.         return result;
  645.     }

  646.     /**
  647.      * Return the current scalar as a equivalentdose.
  648.      * @return EquivalentDose; the current scalar as a equivalentdose
  649.      */
  650.     public final EquivalentDose asEquivalentDose()
  651.     {
  652.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EquivalentDoseUnit.BASE.getSiDimensions())),
  653.                 UnitRuntimeException.class, "cannot cast %s to EquivalentDose", this.toString());
  654.         return new EquivalentDose(getSI(), EquivalentDoseUnit.SI);
  655.     }

  656.     /**
  657.      * Return the current scalar as a equivalentdose, and provide a display unit.
  658.      * @param displayUnit the unit in which the value will be displayed
  659.      * @return EquivalentDose; the current scalar as a equivalentdose
  660.      */
  661.     public final EquivalentDose asEquivalentDose(final EquivalentDoseUnit displayUnit)
  662.     {
  663.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(EquivalentDoseUnit.BASE.getSiDimensions())),
  664.                 UnitRuntimeException.class, "cannot cast %s to EquivalentDose", this.toString());
  665.         EquivalentDose result = new EquivalentDose(getSI(), displayUnit.getStandardUnit());
  666.         result.setDisplayUnit(displayUnit);
  667.         return result;
  668.     }

  669.     /**
  670.      * Return the current scalar as a flowmass.
  671.      * @return FlowMass; the current scalar as a flowmass
  672.      */
  673.     public final FlowMass asFlowMass()
  674.     {
  675.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FlowMassUnit.BASE.getSiDimensions())),
  676.                 UnitRuntimeException.class, "cannot cast %s to FlowMass", this.toString());
  677.         return new FlowMass(getSI(), FlowMassUnit.SI);
  678.     }

  679.     /**
  680.      * Return the current scalar as a flowmass, and provide a display unit.
  681.      * @param displayUnit the unit in which the value will be displayed
  682.      * @return FlowMass; the current scalar as a flowmass
  683.      */
  684.     public final FlowMass asFlowMass(final FlowMassUnit displayUnit)
  685.     {
  686.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FlowMassUnit.BASE.getSiDimensions())),
  687.                 UnitRuntimeException.class, "cannot cast %s to FlowMass", this.toString());
  688.         FlowMass result = new FlowMass(getSI(), displayUnit.getStandardUnit());
  689.         result.setDisplayUnit(displayUnit);
  690.         return result;
  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.      * Return the current scalar as a flowvolume, and provide a display unit.
  704.      * @param displayUnit the unit in which the value will be displayed
  705.      * @return FlowVolume; the current scalar as a flowvolume
  706.      */
  707.     public final FlowVolume asFlowVolume(final FlowVolumeUnit displayUnit)
  708.     {
  709.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FlowVolumeUnit.BASE.getSiDimensions())),
  710.                 UnitRuntimeException.class, "cannot cast %s to FlowVolume", this.toString());
  711.         FlowVolume result = new FlowVolume(getSI(), displayUnit.getStandardUnit());
  712.         result.setDisplayUnit(displayUnit);
  713.         return result;
  714.     }

  715.     /**
  716.      * Return the current scalar as a force.
  717.      * @return Force; the current scalar as a force
  718.      */
  719.     public final Force asForce()
  720.     {
  721.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ForceUnit.BASE.getSiDimensions())),
  722.                 UnitRuntimeException.class, "cannot cast %s to Force", this.toString());
  723.         return new Force(getSI(), ForceUnit.SI);
  724.     }

  725.     /**
  726.      * Return the current scalar as a force, and provide a display unit.
  727.      * @param displayUnit the unit in which the value will be displayed
  728.      * @return Force; the current scalar as a force
  729.      */
  730.     public final Force asForce(final ForceUnit displayUnit)
  731.     {
  732.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(ForceUnit.BASE.getSiDimensions())),
  733.                 UnitRuntimeException.class, "cannot cast %s to Force", this.toString());
  734.         Force result = new Force(getSI(), displayUnit.getStandardUnit());
  735.         result.setDisplayUnit(displayUnit);
  736.         return result;
  737.     }

  738.     /**
  739.      * Return the current scalar as a frequency.
  740.      * @return Frequency; the current scalar as a frequency
  741.      */
  742.     public final Frequency asFrequency()
  743.     {
  744.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FrequencyUnit.BASE.getSiDimensions())),
  745.                 UnitRuntimeException.class, "cannot cast %s to Frequency", this.toString());
  746.         return new Frequency(getSI(), FrequencyUnit.SI);
  747.     }

  748.     /**
  749.      * Return the current scalar as a frequency, and provide a display unit.
  750.      * @param displayUnit the unit in which the value will be displayed
  751.      * @return Frequency; the current scalar as a frequency
  752.      */
  753.     public final Frequency asFrequency(final FrequencyUnit displayUnit)
  754.     {
  755.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(FrequencyUnit.BASE.getSiDimensions())),
  756.                 UnitRuntimeException.class, "cannot cast %s to Frequency", this.toString());
  757.         Frequency result = new Frequency(getSI(), displayUnit.getStandardUnit());
  758.         result.setDisplayUnit(displayUnit);
  759.         return result;
  760.     }

  761.     /**
  762.      * Return the current scalar as a illuminance.
  763.      * @return Illuminance; the current scalar as a illuminance
  764.      */
  765.     public final Illuminance asIlluminance()
  766.     {
  767.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(IlluminanceUnit.BASE.getSiDimensions())),
  768.                 UnitRuntimeException.class, "cannot cast %s to Illuminance", this.toString());
  769.         return new Illuminance(getSI(), IlluminanceUnit.SI);
  770.     }

  771.     /**
  772.      * Return the current scalar as a illuminance, and provide a display unit.
  773.      * @param displayUnit the unit in which the value will be displayed
  774.      * @return Illuminance; the current scalar as a illuminance
  775.      */
  776.     public final Illuminance asIlluminance(final IlluminanceUnit displayUnit)
  777.     {
  778.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(IlluminanceUnit.BASE.getSiDimensions())),
  779.                 UnitRuntimeException.class, "cannot cast %s to Illuminance", this.toString());
  780.         Illuminance result = new Illuminance(getSI(), displayUnit.getStandardUnit());
  781.         result.setDisplayUnit(displayUnit);
  782.         return result;
  783.     }

  784.     /**
  785.      * Return the current scalar as a lineardensity.
  786.      * @return LinearDensity; the current scalar as a lineardensity
  787.      */
  788.     public final LinearDensity asLinearDensity()
  789.     {
  790.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LinearDensityUnit.BASE.getSiDimensions())),
  791.                 UnitRuntimeException.class, "cannot cast %s to LinearDensity", this.toString());
  792.         return new LinearDensity(getSI(), LinearDensityUnit.SI);
  793.     }

  794.     /**
  795.      * Return the current scalar as a lineardensity, and provide a display unit.
  796.      * @param displayUnit the unit in which the value will be displayed
  797.      * @return LinearDensity; the current scalar as a lineardensity
  798.      */
  799.     public final LinearDensity asLinearDensity(final LinearDensityUnit displayUnit)
  800.     {
  801.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LinearDensityUnit.BASE.getSiDimensions())),
  802.                 UnitRuntimeException.class, "cannot cast %s to LinearDensity", this.toString());
  803.         LinearDensity result = new LinearDensity(getSI(), displayUnit.getStandardUnit());
  804.         result.setDisplayUnit(displayUnit);
  805.         return result;
  806.     }

  807.     /**
  808.      * Return the current scalar as a luminousflux.
  809.      * @return LuminousFlux; the current scalar as a luminousflux
  810.      */
  811.     public final LuminousFlux asLuminousFlux()
  812.     {
  813.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousFluxUnit.BASE.getSiDimensions())),
  814.                 UnitRuntimeException.class, "cannot cast %s to LuminousFlux", this.toString());
  815.         return new LuminousFlux(getSI(), LuminousFluxUnit.SI);
  816.     }

  817.     /**
  818.      * Return the current scalar as a luminousflux, and provide a display unit.
  819.      * @param displayUnit the unit in which the value will be displayed
  820.      * @return LuminousFlux; the current scalar as a luminousflux
  821.      */
  822.     public final LuminousFlux asLuminousFlux(final LuminousFluxUnit displayUnit)
  823.     {
  824.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousFluxUnit.BASE.getSiDimensions())),
  825.                 UnitRuntimeException.class, "cannot cast %s to LuminousFlux", this.toString());
  826.         LuminousFlux result = new LuminousFlux(getSI(), displayUnit.getStandardUnit());
  827.         result.setDisplayUnit(displayUnit);
  828.         return result;
  829.     }

  830.     /**
  831.      * Return the current scalar as a luminousintensity.
  832.      * @return LuminousIntensity; the current scalar as a luminousintensity
  833.      */
  834.     public final LuminousIntensity asLuminousIntensity()
  835.     {
  836.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousIntensityUnit.BASE.getSiDimensions())),
  837.                 UnitRuntimeException.class, "cannot cast %s to LuminousIntensity", this.toString());
  838.         return new LuminousIntensity(getSI(), LuminousIntensityUnit.SI);
  839.     }

  840.     /**
  841.      * Return the current scalar as a luminousintensity, and provide a display unit.
  842.      * @param displayUnit the unit in which the value will be displayed
  843.      * @return LuminousIntensity; the current scalar as a luminousintensity
  844.      */
  845.     public final LuminousIntensity asLuminousIntensity(final LuminousIntensityUnit displayUnit)
  846.     {
  847.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LuminousIntensityUnit.BASE.getSiDimensions())),
  848.                 UnitRuntimeException.class, "cannot cast %s to LuminousIntensity", this.toString());
  849.         LuminousIntensity result = new LuminousIntensity(getSI(), displayUnit.getStandardUnit());
  850.         result.setDisplayUnit(displayUnit);
  851.         return result;
  852.     }

  853.     /**
  854.      * Return the current scalar as a magneticfluxdensity.
  855.      * @return MagneticFluxDensity; the current scalar as a magneticfluxdensity
  856.      */
  857.     public final MagneticFluxDensity asMagneticFluxDensity()
  858.     {
  859.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxDensityUnit.BASE.getSiDimensions())),
  860.                 UnitRuntimeException.class, "cannot cast %s to MagneticFluxDensity", this.toString());
  861.         return new MagneticFluxDensity(getSI(), MagneticFluxDensityUnit.SI);
  862.     }

  863.     /**
  864.      * Return the current scalar as a magneticfluxdensity, and provide a display unit.
  865.      * @param displayUnit the unit in which the value will be displayed
  866.      * @return MagneticFluxDensity; the current scalar as a magneticfluxdensity
  867.      */
  868.     public final MagneticFluxDensity asMagneticFluxDensity(final MagneticFluxDensityUnit displayUnit)
  869.     {
  870.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxDensityUnit.BASE.getSiDimensions())),
  871.                 UnitRuntimeException.class, "cannot cast %s to MagneticFluxDensity", this.toString());
  872.         MagneticFluxDensity result = new MagneticFluxDensity(getSI(), displayUnit.getStandardUnit());
  873.         result.setDisplayUnit(displayUnit);
  874.         return result;
  875.     }

  876.     /**
  877.      * Return the current scalar as a magneticflux.
  878.      * @return MagneticFlux; the current scalar as a magneticflux
  879.      */
  880.     public final MagneticFlux asMagneticFlux()
  881.     {
  882.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxUnit.BASE.getSiDimensions())),
  883.                 UnitRuntimeException.class, "cannot cast %s to MagneticFlux", this.toString());
  884.         return new MagneticFlux(getSI(), MagneticFluxUnit.SI);
  885.     }

  886.     /**
  887.      * Return the current scalar as a magneticflux, and provide a display unit.
  888.      * @param displayUnit the unit in which the value will be displayed
  889.      * @return MagneticFlux; the current scalar as a magneticflux
  890.      */
  891.     public final MagneticFlux asMagneticFlux(final MagneticFluxUnit displayUnit)
  892.     {
  893.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MagneticFluxUnit.BASE.getSiDimensions())),
  894.                 UnitRuntimeException.class, "cannot cast %s to MagneticFlux", this.toString());
  895.         MagneticFlux result = new MagneticFlux(getSI(), displayUnit.getStandardUnit());
  896.         result.setDisplayUnit(displayUnit);
  897.         return result;
  898.     }

  899.     /**
  900.      * Return the current scalar as a mass.
  901.      * @return Mass; the current scalar as a mass
  902.      */
  903.     public final Mass asMass()
  904.     {
  905.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MassUnit.BASE.getSiDimensions())),
  906.                 UnitRuntimeException.class, "cannot cast %s to Mass", this.toString());
  907.         return new Mass(getSI(), MassUnit.SI);
  908.     }

  909.     /**
  910.      * Return the current scalar as a mass, and provide a display unit.
  911.      * @param displayUnit the unit in which the value will be displayed
  912.      * @return Mass; the current scalar as a mass
  913.      */
  914.     public final Mass asMass(final MassUnit displayUnit)
  915.     {
  916.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MassUnit.BASE.getSiDimensions())),
  917.                 UnitRuntimeException.class, "cannot cast %s to Mass", this.toString());
  918.         Mass result = new Mass(getSI(), displayUnit.getStandardUnit());
  919.         result.setDisplayUnit(displayUnit);
  920.         return result;
  921.     }

  922.     /**
  923.      * Return the current scalar as a momentum.
  924.      * @return Momentum; the current scalar as a momentum
  925.      */
  926.     public final Momentum asMomentum()
  927.     {
  928.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MomentumUnit.BASE.getSiDimensions())),
  929.                 UnitRuntimeException.class, "cannot cast %s to Momentum", this.toString());
  930.         return new Momentum(getSI(), MomentumUnit.SI);
  931.     }

  932.     /**
  933.      * Return the current scalar as a momentum, and provide a display unit.
  934.      * @param displayUnit the unit in which the value will be displayed
  935.      * @return Momentum; the current scalar as a momentum
  936.      */
  937.     public final Momentum asMomentum(final MomentumUnit displayUnit)
  938.     {
  939.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(MomentumUnit.BASE.getSiDimensions())),
  940.                 UnitRuntimeException.class, "cannot cast %s to Momentum", this.toString());
  941.         Momentum result = new Momentum(getSI(), displayUnit.getStandardUnit());
  942.         result.setDisplayUnit(displayUnit);
  943.         return result;
  944.     }

  945.     /**
  946.      * Return the current scalar as a power.
  947.      * @return Power; the current scalar as a power
  948.      */
  949.     public final Power asPower()
  950.     {
  951.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(PowerUnit.BASE.getSiDimensions())),
  952.                 UnitRuntimeException.class, "cannot cast %s to Power", this.toString());
  953.         return new Power(getSI(), PowerUnit.SI);
  954.     }

  955.     /**
  956.      * Return the current scalar as a power, and provide a display unit.
  957.      * @param displayUnit the unit in which the value will be displayed
  958.      * @return Power; the current scalar as a power
  959.      */
  960.     public final Power asPower(final PowerUnit displayUnit)
  961.     {
  962.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(PowerUnit.BASE.getSiDimensions())),
  963.                 UnitRuntimeException.class, "cannot cast %s to Power", this.toString());
  964.         Power result = new Power(getSI(), displayUnit.getStandardUnit());
  965.         result.setDisplayUnit(displayUnit);
  966.         return result;
  967.     }

  968.     /**
  969.      * Return the current scalar as a pressure.
  970.      * @return Pressure; the current scalar as a pressure
  971.      */
  972.     public final Pressure asPressure()
  973.     {
  974.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(PressureUnit.BASE.getSiDimensions())),
  975.                 UnitRuntimeException.class, "cannot cast %s to Pressure", this.toString());
  976.         return new Pressure(getSI(), PressureUnit.SI);
  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.         Pressure result = new Pressure(getSI(), displayUnit.getStandardUnit());
  988.         result.setDisplayUnit(displayUnit);
  989.         return result;
  990.     }

  991.     /**
  992.      * Return the current scalar as a radioactivity.
  993.      * @return RadioActivity; the current scalar as a radioactivity
  994.      */
  995.     public final RadioActivity asRadioActivity()
  996.     {
  997.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(RadioActivityUnit.BASE.getSiDimensions())),
  998.                 UnitRuntimeException.class, "cannot cast %s to RadioActivity", this.toString());
  999.         return new RadioActivity(getSI(), RadioActivityUnit.SI);
  1000.     }

  1001.     /**
  1002.      * Return the current scalar as a radioactivity, and provide a display unit.
  1003.      * @param displayUnit the unit in which the value will be displayed
  1004.      * @return RadioActivity; the current scalar as a radioactivity
  1005.      */
  1006.     public final RadioActivity asRadioActivity(final RadioActivityUnit displayUnit)
  1007.     {
  1008.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(RadioActivityUnit.BASE.getSiDimensions())),
  1009.                 UnitRuntimeException.class, "cannot cast %s to RadioActivity", this.toString());
  1010.         RadioActivity result = new RadioActivity(getSI(), displayUnit.getStandardUnit());
  1011.         result.setDisplayUnit(displayUnit);
  1012.         return result;
  1013.     }

  1014.     /**
  1015.      * Return the current scalar as a solidangle.
  1016.      * @return SolidAngle; the current scalar as a solidangle
  1017.      */
  1018.     public final SolidAngle asSolidAngle()
  1019.     {
  1020.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SolidAngleUnit.BASE.getSiDimensions())),
  1021.                 UnitRuntimeException.class, "cannot cast %s to SolidAngle", this.toString());
  1022.         return new SolidAngle(getSI(), SolidAngleUnit.SI);
  1023.     }

  1024.     /**
  1025.      * Return the current scalar as a solidangle, and provide a display unit.
  1026.      * @param displayUnit the unit in which the value will be displayed
  1027.      * @return SolidAngle; the current scalar as a solidangle
  1028.      */
  1029.     public final SolidAngle asSolidAngle(final SolidAngleUnit displayUnit)
  1030.     {
  1031.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SolidAngleUnit.BASE.getSiDimensions())),
  1032.                 UnitRuntimeException.class, "cannot cast %s to SolidAngle", this.toString());
  1033.         SolidAngle result = new SolidAngle(getSI(), displayUnit.getStandardUnit());
  1034.         result.setDisplayUnit(displayUnit);
  1035.         return result;
  1036.     }

  1037.     /**
  1038.      * Return the current scalar as a speed.
  1039.      * @return Speed; the current scalar as a speed
  1040.      */
  1041.     public final Speed asSpeed()
  1042.     {
  1043.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SpeedUnit.BASE.getSiDimensions())),
  1044.                 UnitRuntimeException.class, "cannot cast %s to Speed", this.toString());
  1045.         return new Speed(getSI(), SpeedUnit.SI);
  1046.     }

  1047.     /**
  1048.      * Return the current scalar as a speed, and provide a display unit.
  1049.      * @param displayUnit the unit in which the value will be displayed
  1050.      * @return Speed; the current scalar as a speed
  1051.      */
  1052.     public final Speed asSpeed(final SpeedUnit displayUnit)
  1053.     {
  1054.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(SpeedUnit.BASE.getSiDimensions())),
  1055.                 UnitRuntimeException.class, "cannot cast %s to Speed", this.toString());
  1056.         Speed result = new Speed(getSI(), displayUnit.getStandardUnit());
  1057.         result.setDisplayUnit(displayUnit);
  1058.         return result;
  1059.     }

  1060.     /**
  1061.      * Return the current scalar as a torque.
  1062.      * @return Torque; the current scalar as a torque
  1063.      */
  1064.     public final Torque asTorque()
  1065.     {
  1066.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TorqueUnit.BASE.getSiDimensions())),
  1067.                 UnitRuntimeException.class, "cannot cast %s to Torque", this.toString());
  1068.         return new Torque(getSI(), TorqueUnit.SI);
  1069.     }

  1070.     /**
  1071.      * Return the current scalar as a torque, and provide a display unit.
  1072.      * @param displayUnit the unit in which the value will be displayed
  1073.      * @return Torque; the current scalar as a torque
  1074.      */
  1075.     public final Torque asTorque(final TorqueUnit displayUnit)
  1076.     {
  1077.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TorqueUnit.BASE.getSiDimensions())),
  1078.                 UnitRuntimeException.class, "cannot cast %s to Torque", this.toString());
  1079.         Torque result = new Torque(getSI(), displayUnit.getStandardUnit());
  1080.         result.setDisplayUnit(displayUnit);
  1081.         return result;
  1082.     }

  1083.     /**
  1084.      * Return the current scalar as a volume.
  1085.      * @return Volume; the current scalar as a volume
  1086.      */
  1087.     public final Volume asVolume()
  1088.     {
  1089.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(VolumeUnit.BASE.getSiDimensions())),
  1090.                 UnitRuntimeException.class, "cannot cast %s to Volume", this.toString());
  1091.         return new Volume(getSI(), VolumeUnit.SI);
  1092.     }

  1093.     /**
  1094.      * Return the current scalar as a volume, and provide a display unit.
  1095.      * @param displayUnit the unit in which the value will be displayed
  1096.      * @return Volume; the current scalar as a volume
  1097.      */
  1098.     public final Volume asVolume(final VolumeUnit displayUnit)
  1099.     {
  1100.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(VolumeUnit.BASE.getSiDimensions())),
  1101.                 UnitRuntimeException.class, "cannot cast %s to Volume", this.toString());
  1102.         Volume result = new Volume(getSI(), displayUnit.getStandardUnit());
  1103.         result.setDisplayUnit(displayUnit);
  1104.         return result;
  1105.     }

  1106.     /**
  1107.      * Return the current scalar as a angle.
  1108.      * @return Angle; the current scalar as a angle
  1109.      */
  1110.     public final Angle asAngle()
  1111.     {
  1112.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngleUnit.BASE.getSiDimensions())),
  1113.                 UnitRuntimeException.class, "cannot cast %s to Angle", this.toString());
  1114.         return new Angle(getSI(), AngleUnit.SI);
  1115.     }

  1116.     /**
  1117.      * Return the current scalar as a angle, and provide a display unit.
  1118.      * @param displayUnit the unit in which the value will be displayed
  1119.      * @return Angle; the current scalar as a angle
  1120.      */
  1121.     public final Angle asAngle(final AngleUnit displayUnit)
  1122.     {
  1123.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(AngleUnit.BASE.getSiDimensions())),
  1124.                 UnitRuntimeException.class, "cannot cast %s to Angle", this.toString());
  1125.         Angle result = new Angle(getSI(), displayUnit.getStandardUnit());
  1126.         result.setDisplayUnit(displayUnit);
  1127.         return result;
  1128.     }

  1129.     /**
  1130.      * Return the current scalar as a length.
  1131.      * @return Length; the current scalar as a length
  1132.      */
  1133.     public final Length asLength()
  1134.     {
  1135.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LengthUnit.BASE.getSiDimensions())),
  1136.                 UnitRuntimeException.class, "cannot cast %s to Length", this.toString());
  1137.         return new Length(getSI(), LengthUnit.SI);
  1138.     }

  1139.     /**
  1140.      * Return the current scalar as a length, and provide a display unit.
  1141.      * @param displayUnit the unit in which the value will be displayed
  1142.      * @return Length; the current scalar as a length
  1143.      */
  1144.     public final Length asLength(final LengthUnit displayUnit)
  1145.     {
  1146.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(LengthUnit.BASE.getSiDimensions())),
  1147.                 UnitRuntimeException.class, "cannot cast %s to Length", this.toString());
  1148.         Length result = new Length(getSI(), displayUnit.getStandardUnit());
  1149.         result.setDisplayUnit(displayUnit);
  1150.         return result;
  1151.     }

  1152.     /**
  1153.      * Return the current scalar as a temperature.
  1154.      * @return Temperature; the current scalar as a temperature
  1155.      */
  1156.     public final Temperature asTemperature()
  1157.     {
  1158.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TemperatureUnit.BASE.getSiDimensions())),
  1159.                 UnitRuntimeException.class, "cannot cast %s to Temperature", this.toString());
  1160.         return new Temperature(getSI(), TemperatureUnit.SI);
  1161.     }

  1162.     /**
  1163.      * Return the current scalar as a temperature, and provide a display unit.
  1164.      * @param displayUnit the unit in which the value will be displayed
  1165.      * @return Temperature; the current scalar as a temperature
  1166.      */
  1167.     public final Temperature asTemperature(final TemperatureUnit displayUnit)
  1168.     {
  1169.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(TemperatureUnit.BASE.getSiDimensions())),
  1170.                 UnitRuntimeException.class, "cannot cast %s to Temperature", this.toString());
  1171.         Temperature result = new Temperature(getSI(), displayUnit.getStandardUnit());
  1172.         result.setDisplayUnit(displayUnit);
  1173.         return result;
  1174.     }

  1175.     /**
  1176.      * Return the current scalar as a duration.
  1177.      * @return Duration; the current scalar as a duration
  1178.      */
  1179.     public final Duration asDuration()
  1180.     {
  1181.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DurationUnit.BASE.getSiDimensions())),
  1182.                 UnitRuntimeException.class, "cannot cast %s to Duration", this.toString());
  1183.         return new Duration(getSI(), DurationUnit.SI);
  1184.     }

  1185.     /**
  1186.      * Return the current scalar as a duration, and provide a display unit.
  1187.      * @param displayUnit the unit in which the value will be displayed
  1188.      * @return Duration; the current scalar as a duration
  1189.      */
  1190.     public final Duration asDuration(final DurationUnit displayUnit)
  1191.     {
  1192.         Throw.when(!(getDisplayUnit().getQuantity().getSiDimensions().equals(DurationUnit.BASE.getSiDimensions())),
  1193.                 UnitRuntimeException.class, "cannot cast %s to Duration", this.toString());
  1194.         Duration result = new Duration(getSI(), displayUnit.getStandardUnit());
  1195.         result.setDisplayUnit(displayUnit);
  1196.         return result;
  1197.     }

  1198. }