@Immutable public final class ScaledUnit extends UnitImpl implements DerivableUnit
UnitImpl.MyConverter
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
Unit |
clone(UnitName id)
Clones this unit, changing the identifier.
|
boolean |
equals(java.lang.Object object)
Indicates if this unit is semantically identical to an object.
|
double |
fromDerivedUnit(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.
|
float |
fromDerivedUnit(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.
|
java.lang.String |
getCanonicalString()
Returns the canonical string representation of the unit.
|
DerivedUnit |
getDerivedUnit()
Gets the derived unit underlying this unit.
|
double |
getScale()
Returns the multiplicative factor.
|
Unit |
getUnit()
Returns the reference unit.
|
int |
hashCode()
Returns the hash code of this instance.
|
boolean |
isDimensionless()
Indicates if this unit is dimensionless.
|
static void |
main(java.lang.String[] args)
Tests this class.
|
Unit |
multiplyBy(double scale)
Multiplies this unit by a scale factor.
|
protected Unit |
myDivideBy(Unit that)
Divides this unit by another unit.
|
protected Unit |
myDivideInto(Unit that)
Divides this unit into another unit.
|
protected Unit |
myMultiplyBy(Unit that)
Multiplies this unit by another unit.
|
protected Unit |
myRaiseTo(int power)
Raises this unit to a power.
|
double |
toDerivedUnit(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.
|
float |
toDerivedUnit(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.
|
java.lang.String |
toString()
Returns the string representation of this unit.
|
convertTo, convertTo, convertTo, convertTo, convertTo, convertTo, divideBy, divideInto, getConverterTo, getName, getPlural, getSymbol, getUnitName, isCompatible, log, makeLabel, multiplyBy, raiseTo, shiftTo, shiftTo
public ScaledUnit(double scale)
scale
- The multiplicative factor.public ScaledUnit(double scale, Unit unit)
scale
- The multiplicative factor.unit
- The reference unit.public double getScale()
public Unit getUnit()
public Unit multiplyBy(double scale) throws MultiplyException
Unit
m
is a
meter unit, then m.multiplyBy(1e-2)
returns a centimeter unit.multiplyBy
in interface Unit
multiplyBy
in class UnitImpl
scale
- The scale factor.MultiplyException
- if scale
is zero.protected Unit myMultiplyBy(Unit that) throws MultiplyException
myMultiplyBy
in class UnitImpl
that
- The other unit.MultiplyException
- Can't multiply these units together.protected Unit myDivideBy(Unit that) throws OperationException
myDivideBy
in class UnitImpl
that
- The other unit.OperationException
- Can't divide these units.protected Unit myDivideInto(Unit that) throws OperationException
myDivideInto
in class UnitImpl
that
- The other unit.OperationException
- Can't divide these units.protected Unit myRaiseTo(int power) throws RaiseException
myRaiseTo
in class UnitImpl
power
- The power.RaiseException
- Can't raise this unit to a power.public DerivedUnit getDerivedUnit()
getDerivedUnit
in interface DerivableUnit
getDerivedUnit
in interface Unit
public float toDerivedUnit(float amount) throws ConversionException
toDerivedUnit
in interface DerivableUnit
amount
- The numeric value in this unit.ConversionException
- Can't convert value to the underlying derived unit.public double toDerivedUnit(double amount) throws ConversionException
toDerivedUnit
in interface DerivableUnit
amount
- The numeric value in this unit.ConversionException
- Can't convert value to the underlying derived unit.public float[] toDerivedUnit(float[] input, float[] output) throws ConversionException
toDerivedUnit
in interface DerivableUnit
input
- The numeric values in this unit.output
- The equivalent values in the underlying derived unit.output
.ConversionException
- Can't convert values to the underlying derived unit.public double[] toDerivedUnit(double[] input, double[] output) throws ConversionException
toDerivedUnit
in interface DerivableUnit
input
- The numeric values in this unit.output
- The equivalent values in the underlying derived unit.output
.ConversionException
- Can't convert values to the underlying derived unit.public float fromDerivedUnit(float amount) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
amount
- The numeric value in the underlying derived unit.ConversionException
- Can't convert value.public double fromDerivedUnit(double amount) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
amount
- The numeric value in the underlying derived unit.ConversionException
- Can't convert value.public float[] fromDerivedUnit(float[] input, float[] output) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
input
- The numeric values in the underlying derived unit.output
- The equivalent values in this unit.output
.ConversionException
- Can't convert values.public double[] fromDerivedUnit(double[] input, double[] output) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
input
- The numeric values in the underlying derived unit.output
- The equivalent values in this unit.output
.ConversionException
- Can't convert values.public boolean equals(java.lang.Object object)
public int hashCode()
public boolean isDimensionless()
isDimensionless
in interface Unit
true
if and only if this unit is dimensionless.public java.lang.String toString()
public java.lang.String getCanonicalString()
getCanonicalString
in interface Unit
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception