@Immutable public final class OffsetUnit extends UnitImpl implements DerivableUnit
UnitImpl.MyConverter
Constructor and Description |
---|
OffsetUnit(Unit unit,
double offset)
Constructs from a reference unit and an offset.
|
OffsetUnit(Unit unit,
double offset,
UnitName id)
Constructs from a reference unit, and offset, and a unit 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 value in the convertible derived unit to the equivalent value
in this unit.
|
double[] |
fromDerivedUnit(double[] input,
double[] output)
Converts values in the convertible derived unit to the equivalent values
in this unit.
|
float |
fromDerivedUnit(float amount)
Converts a value in the convertible derived unit to the equivalent value
in this unit.
|
float[] |
fromDerivedUnit(float[] input,
float[] output)
Converts values in the convertible derived unit to the equivalent values
in this unit.
|
java.lang.String |
getCanonicalString()
Returns the canonical string representation of the unit.
|
DerivedUnit |
getDerivedUnit()
Returns the derived unit that is convertible with this unit.
|
double |
getOffset()
Returns the offset.
|
Unit |
getUnit()
Returns the reference unit.
|
int |
hashCode()
Returns the hash code of this instance.
|
boolean |
isDimensionless()
Indicates if this unit is dimensionless.
|
Unit |
multiplyBy(double scale)
Multiplies this unit by a scale factor.
|
protected Unit |
myDivideBy(Unit that)
Divide this unit by another unit.
|
protected Unit |
myDivideInto(Unit that)
Divide this unit into another unit.
|
protected Unit |
myMultiplyBy(Unit that)
Multiply this unit by another unit.
|
protected Unit |
myRaiseTo(int power)
Raise this unit to a power.
|
Unit |
shiftTo(double origin)
Returns a unit identical to this instance but whose origin (i.e., zero
value) has been shifted to the given value.
|
double |
toDerivedUnit(double amount)
Converts a value in this unit to the equivalent value in the convertible
derived unit.
|
double[] |
toDerivedUnit(double[] input,
double[] output)
Converts values in this unit to the equivalent values in the convertible
derived unit.
|
float |
toDerivedUnit(float amount)
Converts a value in this unit to the equivalent value in the convertible
derived unit.
|
float[] |
toDerivedUnit(float[] input,
float[] output)
Converts values in this unit to the equivalent values in the convertible
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
public OffsetUnit(Unit unit, double offset)
unit
- The reference unit.offset
- The origin of this unit in terms of the reference unit. For
example, a degree Celsius unit would be created as "new
OffsetUnit(kelvin, 273.15)
.public OffsetUnit(Unit unit, double offset, UnitName id)
unit
- The reference unit.offset
- The origin of this unit in terms of the reference unit. For
example, a degree Celsius unit would be created as "new
OffsetUnit(kelvin, 273.15)
.id
- The identifier for the new unit.public Unit getUnit()
public double getOffset()
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.public Unit shiftTo(double origin)
Unit
degK
is a Kelvin unit, then degK.shiftTo(273.15)
is a Celsius unit.protected Unit myMultiplyBy(Unit that) throws MultiplyException
myMultiplyBy
in class UnitImpl
that
- The unit to multiply this unit by.that
. The offset of
this unit will be ignored; thus, for example
"celsius.myMultiplyBy(day)" is equivalent to
"kelvin.myMultiplyBy(day)".MultiplyException
- Can't multiply these units together.protected Unit myDivideBy(Unit that) throws OperationException
myDivideBy
in class UnitImpl
that
- The unit to divide this unit by.that
. The offset of
this unit will be ignored; thus, for example
"celsius.myDivideBy(day)" is equivalent to
"kelvin.myDivideBy(day)".OperationException
- Can't divide these units.protected Unit myDivideInto(Unit that) throws OperationException
myDivideInto
in class UnitImpl
that
- The unit to divide this unit into.that
unit and this unit. The offset
of this unit will be ignored; thus, for example
"celsius.myDivideInto(day)" is equivalent to
"kelvin.myDivideInto(day)".OperationException
- Can't divide these units.protected Unit myRaiseTo(int power) throws RaiseException
myRaiseTo
in class UnitImpl
power
- The power to raise this unit by.power
.
The offset of this unit will be ignored; thus, for example
"celsius.myRaiseTo(2)" is equivalent to "kelvin.myRaiseTo(2)".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 value in this unit.ConversionException
- Can't convert between units.public double toDerivedUnit(double amount) throws ConversionException
toDerivedUnit
in interface DerivableUnit
amount
- The value in this unit.ConversionException
- Can't convert between units.public float[] toDerivedUnit(float[] input, float[] output) throws ConversionException
toDerivedUnit
in interface DerivableUnit
input
- The values in this unit.output
- The equivalent values in the convertible derived unit. May be
the same array as input
.output
.ConversionException
- Can't convert between units.public double[] toDerivedUnit(double[] input, double[] output) throws ConversionException
toDerivedUnit
in interface DerivableUnit
input
- The values in this unit.output
- The equivalent values in the convertible derived unit. May be
the same array as input
.output
.ConversionException
- Can't convert between units.public float fromDerivedUnit(float amount) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
amount
- The value in the convertible derived unit.ConversionException
- Can't convert between units.public double fromDerivedUnit(double amount) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
amount
- The value in the convertible derived unit.ConversionException
- Can't convert between units.public float[] fromDerivedUnit(float[] input, float[] output) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
input
- The values in the convertible derived unit.output
- The equivalent values in this unit. May be the same array as
input
.output
.ConversionException
- Can't convert between units.public double[] fromDerivedUnit(double[] input, double[] output) throws ConversionException
fromDerivedUnit
in interface DerivableUnit
input
- The values in the convertible derived unit.output
- The equivalent values in this unit. May be the same array as
input
.output
.ConversionException
- Can't convert between units.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