|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectucar.units.UnitImpl
ucar.units.OffsetUnit
public final class OffsetUnit
Provides support for units that are offset from reference units (ex: as the unit "degree Celsius" is offset from the reference unit "kelvin"). Instances of this class are immutable.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ucar.units.UnitImpl |
---|
UnitImpl.MyConverter |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
Unit |
clone(UnitName id)
Clones this unit, changing the identifier. |
boolean |
equals(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. |
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. |
static void |
main(String[] args)
Tests this class. |
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. |
String |
toString()
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 |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
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.Method Detail |
---|
public Unit getUnit()
public double getOffset()
public Unit clone(UnitName id)
clone
in interface Unit
id
- The identifier for the new unit.
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.
shiftTo
in interface Unit
shiftTo
in class UnitImpl
origin
- The new origin in units of this instance.
origin
of this instance.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(Object object)
equals
in interface Unit
equals
in class Object
object
- The object.
true
if and only if this unit is semantically
identical to object
.public int hashCode()
hashCode
in class UnitImpl
public boolean isDimensionless()
isDimensionless
in interface Unit
true
if and only if this unit is dimensionless.public String toString()
toString
in interface Unit
toString
in class UnitImpl
public String getCanonicalString()
getCanonicalString
in interface Unit
public static void main(String[] args) throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |