Package ucar.units
Class ScaledUnit
- java.lang.Object
-
- ucar.units.UnitImpl
-
- ucar.units.ScaledUnit
-
- All Implemented Interfaces:
Serializable,DerivableUnit,Unit
@Immutable public final class ScaledUnit extends UnitImpl implements DerivableUnit
Provides support for a unit that is a mutiplicative factor of a reference unit. Instances of this class are immutable.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ucar.units.UnitImpl
UnitImpl.MyConverter
-
-
Constructor Summary
Constructors Constructor Description ScaledUnit(double scale)Constructs from a multiplicative factor.ScaledUnit(double scale, Unit unit)Constructs from a multiplicative factor and a reference unit.ScaledUnit(double scale, Unit unit, UnitName id)Constructs from a multiplicative factor, a reference unit, and an identifier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Unitclone(UnitName id)Clones this unit, changing the identifier.booleanequals(Object object)Indicates if this unit is semantically identical to an object.doublefromDerivedUnit(double amount)Converts a numeric value from the underlying derived unit to this unit.double[]fromDerivedUnit(double[] input, double[] output)Converts numeric values from the underlying derived unit to this unit.floatfromDerivedUnit(float amount)Converts a numeric value from the underlying derived unit to this unit.float[]fromDerivedUnit(float[] input, float[] output)Converts numeric values from the underlying derived unit to this unit.StringgetCanonicalString()Returns the canonical string representation of the unit.DerivedUnitgetDerivedUnit()Gets the derived unit underlying this unit.doublegetScale()Returns the multiplicative factor.UnitgetUnit()Returns the reference unit.inthashCode()Returns the hash code of this instance.booleanisDimensionless()Indicates if this unit is dimensionless.UnitmultiplyBy(double scale)Multiplies this unit by a scale factor.protected UnitmyDivideBy(Unit that)Divides this unit by another unit.protected UnitmyDivideInto(Unit that)Divides this unit into another unit.protected UnitmyMultiplyBy(Unit that)Multiplies this unit by another unit.protected UnitmyRaiseTo(int power)Raises this unit to a power.doubletoDerivedUnit(double amount)Converts a numeric value from this unit to the underlying derived unit.double[]toDerivedUnit(double[] input, double[] output)Converts numeric values from this unit to the underlying derived unit.floattoDerivedUnit(float amount)Converts a numeric value from this unit to the underlying derived unit.float[]toDerivedUnit(float[] input, float[] output)Converts numeric values from this unit to the underlying derived unit.StringtoString()Returns the string representation of this unit.-
Methods inherited from class ucar.units.UnitImpl
convertTo, convertTo, convertTo, convertTo, convertTo, convertTo, divideBy, divideInto, getConverterTo, getName, getPlural, getSymbol, getUnitName, isCompatible, log, makeLabel, multiplyBy, raiseTo, shiftTo, shiftTo
-
-
-
-
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.
-
-
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.
-
multiplyBy
public Unit multiplyBy(double scale) throws MultiplyException
Description copied from interface:UnitMultiplies this unit by a scale factor. For example, ifmis a meter unit, thenm.multiplyBy(1e-2)returns a centimeter unit.- Specified by:
multiplyByin interfaceUnit- Overrides:
multiplyByin classUnitImpl- Parameters:
scale- The scale factor.- Returns:
- The result of multiplying this unit by the scale factor.
- Throws:
MultiplyException- ifscaleis zero.
-
myMultiplyBy
protected Unit myMultiplyBy(Unit that) throws MultiplyException
Multiplies this unit by another unit.- Specified by:
myMultiplyByin classUnitImpl- 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:
myDivideByin classUnitImpl- 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:
myDivideIntoin classUnitImpl- 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:
myRaiseToin classUnitImpl- Parameters:
power- The power.- Returns:
- The result of raising this unit to the power.
- Throws:
RaiseException- Can't raise this unit to a power.
-
getDerivedUnit
public DerivedUnit getDerivedUnit()
Gets the derived unit underlying this unit.- Specified by:
getDerivedUnitin interfaceDerivableUnit- Specified by:
getDerivedUnitin interfaceUnit- Returns:
- The derived unit which underlies this unit.
-
toDerivedUnit
public float toDerivedUnit(float amount) throws ConversionExceptionConverts a numeric value from this unit to the underlying derived unit.- Specified by:
toDerivedUnitin interfaceDerivableUnit- 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 ConversionExceptionConverts a numeric value from this unit to the underlying derived unit.- Specified by:
toDerivedUnitin interfaceDerivableUnit- 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 ConversionExceptionConverts numeric values from this unit to the underlying derived unit.- Specified by:
toDerivedUnitin interfaceDerivableUnit- 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 ConversionExceptionConverts numeric values from this unit to the underlying derived unit.- Specified by:
toDerivedUnitin interfaceDerivableUnit- 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 ConversionExceptionConverts a numeric value from the underlying derived unit to this unit.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- 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 ConversionExceptionConverts a numeric value from the underlying derived unit to this unit.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- 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 ConversionExceptionConverts numeric values from the underlying derived unit to this unit.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- 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 ConversionExceptionConverts numeric values from the underlying derived unit to this unit.- Specified by:
fromDerivedUnitin interfaceDerivableUnit- 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.
-
hashCode
public int hashCode()
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:
isDimensionlessin interfaceUnit- Returns:
trueif and only if this unit is dimensionless.
-
toString
public String toString()
Returns the string representation of this unit.
-
getCanonicalString
public String getCanonicalString()
Returns the canonical string representation of the unit.- Specified by:
getCanonicalStringin interfaceUnit- Returns:
- The canonical string representation.
-
-