Package ucar.units

Class ScaledUnit

    • Constructor Detail

      • ScaledUnit

        public ScaledUnit​(double scale)
        Constructs from a multiplicative factor. Returns a dimensionless unit whose value is the multiplicative factor rather than unity.
        Parameters:
        scale - The multiplicative factor.
      • ScaledUnit

        public ScaledUnit​(double scale,
                          Unit unit)
        Constructs from a multiplicative factor and a reference unit.
        Parameters:
        scale - The multiplicative factor.
        unit - The reference unit.
      • ScaledUnit

        public ScaledUnit​(double scale,
                          Unit unit,
                          UnitName id)
        Constructs from a multiplicative factor, a reference unit, and an identifier.
        Parameters:
        scale - The multiplicative factor.
        unit - The reference unit.
        id - The identifier for the unit.
    • Method Detail

      • getScale

        public double getScale()
        Returns the multiplicative factor.
        Returns:
        The multiplicative factor.
      • getUnit

        public Unit getUnit()
        Returns the reference unit.
        Returns:
        The reference unit.
      • clone

        public Unit clone​(UnitName id)
        Clones this unit, changing the identifier.
        Specified by:
        clone in interface Unit
        Parameters:
        id - The new identifier.
        Returns:
        A ScaledUnit with the new identifier.
      • multiplyBy

        public Unit multiplyBy​(double scale)
                        throws MultiplyException
        Description copied from interface: Unit
        Multiplies this unit by a scale factor. For example, if m is a meter unit, then m.multiplyBy(1e-2) returns a centimeter unit.
        Specified by:
        multiplyBy in interface Unit
        Overrides:
        multiplyBy in class UnitImpl
        Parameters:
        scale - The scale factor.
        Returns:
        The result of multiplying this unit by the scale factor.
        Throws:
        MultiplyException - if scale is zero.
      • myMultiplyBy

        protected Unit myMultiplyBy​(Unit that)
                             throws MultiplyException
        Multiplies this unit by another unit.
        Specified by:
        myMultiplyBy in class UnitImpl
        Parameters:
        that - The other unit.
        Returns:
        The product of this unit and the other unit.
        Throws:
        MultiplyException - Can't multiply these units together.
      • myDivideBy

        protected Unit myDivideBy​(Unit that)
                           throws OperationException
        Divides this unit by another unit.
        Specified by:
        myDivideBy in class UnitImpl
        Parameters:
        that - The other unit.
        Returns:
        The quotient of this unit divided by the other unit.
        Throws:
        OperationException - Can't divide these units.
      • myDivideInto

        protected Unit myDivideInto​(Unit that)
                             throws OperationException
        Divides this unit into another unit.
        Specified by:
        myDivideInto in class UnitImpl
        Parameters:
        that - The other unit.
        Returns:
        The quotient of this unit divided into the other unit.
        Throws:
        OperationException - Can't divide these units.
      • myRaiseTo

        protected Unit myRaiseTo​(int power)
                          throws RaiseException
        Raises this unit to a power.
        Specified by:
        myRaiseTo in class UnitImpl
        Parameters:
        power - The power.
        Returns:
        The result of raising this unit to the power.
        Throws:
        RaiseException - Can't raise this unit to a power.
      • toDerivedUnit

        public float toDerivedUnit​(float amount)
                            throws ConversionException
        Converts a numeric value from this unit to the underlying derived unit.
        Specified by:
        toDerivedUnit in interface DerivableUnit
        Parameters:
        amount - The numeric value in this unit.
        Returns:
        The equivalent value in the underlying derived unit.
        Throws:
        ConversionException - Can't convert value to the underlying derived unit.
      • toDerivedUnit

        public double toDerivedUnit​(double amount)
                             throws ConversionException
        Converts a numeric value from this unit to the underlying derived unit.
        Specified by:
        toDerivedUnit in interface DerivableUnit
        Parameters:
        amount - The numeric value in this unit.
        Returns:
        The equivalent value in the underlying derived unit.
        Throws:
        ConversionException - Can't convert value to the underlying derived unit.
      • toDerivedUnit

        public float[] toDerivedUnit​(float[] input,
                                     float[] output)
                              throws ConversionException
        Converts numeric values from this unit to the underlying derived unit.
        Specified by:
        toDerivedUnit in interface DerivableUnit
        Parameters:
        input - The numeric values in this unit.
        output - The equivalent values in the underlying derived unit.
        Returns:
        output.
        Throws:
        ConversionException - Can't convert values to the underlying derived unit.
      • toDerivedUnit

        public double[] toDerivedUnit​(double[] input,
                                      double[] output)
                               throws ConversionException
        Converts numeric values from this unit to the underlying derived unit.
        Specified by:
        toDerivedUnit in interface DerivableUnit
        Parameters:
        input - The numeric values in this unit.
        output - The equivalent values in the underlying derived unit.
        Returns:
        output.
        Throws:
        ConversionException - Can't convert values to the underlying derived unit.
      • fromDerivedUnit

        public float fromDerivedUnit​(float amount)
                              throws ConversionException
        Converts a numeric value from the underlying derived unit to this unit.
        Specified by:
        fromDerivedUnit in interface DerivableUnit
        Parameters:
        amount - The numeric value in the underlying derived unit.
        Returns:
        The equivalent value in this unit.
        Throws:
        ConversionException - Can't convert value.
      • fromDerivedUnit

        public double fromDerivedUnit​(double amount)
                               throws ConversionException
        Converts a numeric value from the underlying derived unit to this unit.
        Specified by:
        fromDerivedUnit in interface DerivableUnit
        Parameters:
        amount - The numeric value in the underlying derived unit.
        Returns:
        The equivalent value in this unit.
        Throws:
        ConversionException - Can't convert value.
      • fromDerivedUnit

        public float[] fromDerivedUnit​(float[] input,
                                       float[] output)
                                throws ConversionException
        Converts numeric values from the underlying derived unit to this unit.
        Specified by:
        fromDerivedUnit in interface DerivableUnit
        Parameters:
        input - The numeric values in the underlying derived unit.
        output - The equivalent values in this unit.
        Returns:
        output.
        Throws:
        ConversionException - Can't convert values.
      • fromDerivedUnit

        public double[] fromDerivedUnit​(double[] input,
                                        double[] output)
                                 throws ConversionException
        Converts numeric values from the underlying derived unit to this unit.
        Specified by:
        fromDerivedUnit in interface DerivableUnit
        Parameters:
        input - The numeric values in the underlying derived unit.
        output - The equivalent values in this unit.
        Returns:
        output.
        Throws:
        ConversionException - Can't convert values.
      • equals

        public boolean equals​(Object object)
        Indicates if this unit is semantically identical to an object.
        Specified by:
        equals in interface Unit
        Overrides:
        equals in class Object
        Parameters:
        object - The object.
        Returns:
        true if an only if this unit is semantically identical to object .
      • hashCode

        public int hashCode()
        Returns the hash code of this instance.
        Specified by:
        hashCode in class UnitImpl
        Returns:
        The hash code of this instance.
      • isDimensionless

        public boolean isDimensionless()
        Indicates if this unit is dimensionless. A ScaledUnit is dimensionless if and only if the reference unit is dimensionless.
        Specified by:
        isDimensionless in interface Unit
        Returns:
        true if and only if this unit is dimensionless.
      • toString

        public String toString()
        Returns the string representation of this unit.
        Specified by:
        toString in interface Unit
        Overrides:
        toString in class UnitImpl
        Returns:
        The string representation of this unit.
      • getCanonicalString

        public String getCanonicalString()
        Returns the canonical string representation of the unit.
        Specified by:
        getCanonicalString in interface Unit
        Returns:
        The canonical string representation.