|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvisad.Unit
public abstract class Unit
A class that represents a unit of a quantity.
Constructor Summary | |
---|---|
protected |
Unit()
Constructs from nothing. |
protected |
Unit(java.lang.String identifier)
Constructs from an identifier. |
Method Summary | |
---|---|
protected java.lang.String |
adjustCheckAndCache(java.lang.String identifier)
Adjusts, checks, and caches a unit identifier and its unit. |
static boolean |
canConvert(Unit unita,
Unit unitb)
Indicates if values in two units are convertible. |
static boolean |
canConvertArray(Unit[] unita,
Unit[] unitb)
Indicates whether or not two unit arrays are convertible. |
Unit |
clone(java.lang.String identifier)
Clones this unit, changing the identifier. |
static double[][] |
convertTuple(double[][] value,
Unit[] units_in,
Unit[] units_out)
Converts a tuple of double value arrays. |
static float[][] |
convertTuple(float[][] value,
Unit[] units_in,
Unit[] units_out)
Converts a tuple of float value arrays. |
static Unit[] |
copyUnitsArray(Unit[] units)
Copys an array of units. |
abstract Unit |
divide(Unit that)
Divide this unit by another unit. |
protected abstract Unit |
divideInto(Unit that)
Divide this unit into another unit. |
abstract boolean |
equals(Unit unit)
Indicates whether or not this instance is equal to a unit. |
Unit |
getAbsoluteUnit()
Gets the absolute unit of this unit. |
abstract java.lang.String |
getDefinition()
Returns the definition of this unit. |
java.lang.String |
getIdentifier()
Returns the identifier (name or abbreviation) of this unit. |
abstract boolean |
isConvertible(Unit unit)
Indicate whether this unit is convertible with another unit. |
abstract boolean |
isDimensionless()
Indicates if this instance is dimensionless. |
abstract Unit |
multiply(Unit that)
Multiply this unit by another unit. |
abstract Unit |
pow(double power)
Raise a unit to a power. |
abstract Unit |
pow(int power)
Raise this unit to a power. |
protected abstract Unit |
protectedClone(java.lang.String identifier)
Clones this unit, changing the identifier. |
abstract Unit |
root(int root)
Returns the N-th root of this unit. |
Unit |
scale(double amount)
Scale this unit by an amount. |
Unit |
shift(double offset)
Shift this unit by an amount. |
Unit |
sqrt()
Returns the square-root of this unit. |
java.lang.String |
toString()
Returns a string representation of this unit. |
abstract double[] |
toThat(double[] values,
Unit that)
Convert values from this unit to another unit. |
double |
toThat(double value,
Unit that)
Convert a value from this unit to another unit. |
abstract float[] |
toThat(float[] values,
Unit that)
Convert values from this unit to another unit. |
abstract double[] |
toThis(double[] values,
Unit that)
Convert values to this unit from another unit. |
double |
toThis(double value,
Unit that)
Convert a value to this unit from another unit. |
abstract float[] |
toThis(float[] values,
Unit that)
Convert values to this unit from another unit. |
static double[] |
transformUnits(Unit unit_out,
ErrorEstimate[] errors_out,
Unit unit_in,
ErrorEstimate error_in,
double[] value)
Transform double values and (optionally) error estimates. |
static float[] |
transformUnits(Unit unit_out,
ErrorEstimate[] errors_out,
Unit unit_in,
ErrorEstimate error_in,
float[] value)
Transform float values and (optionally) error estimates. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected Unit()
protected Unit(java.lang.String identifier)
identifier
- Name or abbreviation for the unit. May be
null
or empty.Method Detail |
---|
public static double[][] convertTuple(double[][] value, Unit[] units_in, Unit[] units_out) throws UnitException, VisADException
This implementation uses {@link #toThis(double[], unit) to convert the individual arrays.
value
- The tuple of numeric value arrays to convert.
value[i][j]
is the value of the
i
th component of sample-point
j
.units_in
- The units of the input numeric values.
units_in[i]
is the unit of the
i
th conponent.units_out
- The units of the output numeric values.
units_out[i]
is the unit for the
i
th conponent.
[i][j]
is the converted
value of value[i][j]
.
UnitException
- If an ouput unit is null
and the corresponding input unit is neither
null
nor a PromiscuousUnit
,
or if an input unit is not convertible with its
corresponding output unit.
VisADException
- if a VisAD failure occurs.public static float[][] convertTuple(float[][] value, Unit[] units_in, Unit[] units_out) throws UnitException, VisADException
Converts a tuple of float value arrays.
This implementation uses {@link #toThis(float[], unit) to convert the individual arrays.
value
- The tuple of numeric value arrays to convert.
value[i][j]
is the value of the
i
th component of sample-point
j
.units_in
- The units of the input numeric values.
units_in[i]
is the unit of the
i
th conponent.units_out
- The units of the output numeric values.
units_out[i]
is the unit for the
i
th conponent.
[i][j]
is the converted
value of value[i][j]
.
UnitException
- If an ouput unit is null
and the corresponding input unit is neither
null
nor a PromiscuousUnit
,
or if an input unit is not convertible with its
corresponding output unit.
VisADException
- if a VisAD failure occurs.public static boolean canConvert(Unit unita, Unit unitb)
null
or the promiscuous
unit, or if one unit is neither null
nor the promiscuous unit
and the other unit is either the promiscuous unit or a convertible unit.
unita
- One unit.unitb
- The other unit.
true
if and only if values in the
the two units are convertible.isConvertible(Unit)
public abstract boolean isConvertible(Unit unit)
toThis(...)
/ and
toThat(...)
methods will not throw a UnitException. Unit A
is convertible with unit B if and only if unit B is convertible with unit
A; hence, calling-order is irrelevant.
unit
- The other unit.
public static boolean canConvertArray(Unit[] unita, Unit[] unitb)
Indicates whether or not two unit arrays are convertible. Two such arrays are convertible if and only if the units of their corresponding elements are convertible.
This implementation uses canConvert(Unit, Unit)
to determine
convertibility of the element pairs.
unita
- One array of units. May be null
.unitb
- The other array of units. May be
null
.
true
if and only if both unit arrays
are null
or the two unit
arrays are element-by-element convertible.public static Unit[] copyUnitsArray(Unit[] units)
Set
, RealTupleType
, CoordinateSystem
, etc.
units
- The array of units or null
.
null
.
if the input array is null
.public abstract boolean equals(Unit unit)
unit
- The unit.
true
if and only if this instance
equals the unit.public static double[] transformUnits(Unit unit_out, ErrorEstimate[] errors_out, Unit unit_in, ErrorEstimate error_in, double[] value) throws UnitException, VisADException
unit_out
- The unit of the output numeric values or
null
.errors_out
- The output error estimate. errors_out[0]
will contain the output error estimate,
which may be null
.unit_in
- The unit of the input numeric values.error_in
- The input error estimate or null
.value
- The input numeric value.
null
; otherwise, a new array
is returned.
java.lang.NullPointerException
- if errors_out
is null
.
UnitException
- if the input and output unit aren't convertible.
VisADException
- if a VisAD failure occurs.public static float[] transformUnits(Unit unit_out, ErrorEstimate[] errors_out, Unit unit_in, ErrorEstimate error_in, float[] value) throws UnitException, VisADException
unit_out
- The unit of the output numeric values or
null
.errors_out
- The output error estimate. errors_out[0]
will contain the output error estimate,
which may be null
.unit_in
- The unit of the input numeric values.error_in
- The input error estimate or null
.value
- The input numeric value.
null
; otherwise, a new array
is returned.
java.lang.NullPointerException
- if errors_out
is null
.
UnitException
- if the input and output unit aren't convertible.
VisADException
- if a VisAD failure occurs.protected final java.lang.String adjustCheckAndCache(java.lang.String identifier) throws UnitExistsException
identifier
- Name or abbreviation for the unit. May be
null
or empty.
UnitExistsException
- A different unit with the same, non-null and
non-empty identifier already exists. The
identifier and unit are not cached.public abstract boolean isDimensionless()
Indicates if this instance is dimensionless. A unit is dimensionless if it is a measure of a dimensionless quantity like angle or concentration. Examples of dimensionless units include radian, degree, steradian, and "g/kg".
public Unit clone(java.lang.String identifier) throws UnitException
Clones this unit, changing the identifier.
This implementation uses the protectedClone(String)
method.
identifier
- The name or abbreviation for the cloned unit.
May be null
or empty.
UnitException
- The unit may not be cloned. This will only
occur if getIdentifier()!=null
.adjustCheckAndCache(String)
protected abstract Unit protectedClone(java.lang.String identifier) throws UnitException
identifier
- The name or abbreviation for the cloned unit.
May be null
or empty. It shall
have already passed the
#adjustCheckAndCache()
method.
UnitException
- if the unit may not be cloned. This will only
occur if getIdentifier()!=null
.public abstract Unit pow(int power) throws UnitException
power
- The power to raise this unit by.
UnitException
- It's meaningless to raise this unit
by a power.public abstract Unit root(int root) throws java.lang.IllegalArgumentException, UnitException
root
- The root to take (e.g. 2 means square root). Must not
be zero.
root
-th root
of this unit.
UnitException
- It's meaningless to raise this unit
by a power.
java.lang.IllegalArgumentException
- The root value is zero or the resulting unit would have
a non-integral unit dimension.public Unit sqrt() throws java.lang.IllegalArgumentException, UnitException
root(int root)
with a value of 2
.
java.lang.IllegalArgumentException
- The resulting unit would have a non-integral unit
dimension.
UnitException
- It is meaningless to take a root of this unit.public abstract Unit pow(double power) throws UnitException, java.lang.IllegalArgumentException
power
- The power to raise this unit by. If this unit is
not dimensionless, then the value must be integral.
power
.
UnitException
- It's meaningless to raise this unit by a power.
java.lang.IllegalArgumentException
- This unit is not dimensionless and power
has a non-integral value.public Unit scale(double amount) throws UnitException
amount
- The amount by which to scale this unit. E.g.
Unit yard = meter.scale(0.9144);
UnitException
- This unit cannot be scaled.public Unit shift(double offset) throws UnitException
offset
- The amount by which to shift this unit. E.g.
Unit celsius = kelvin.shift(273.15);
UnitException
- The unit subclass is unknown.public abstract Unit multiply(Unit that) throws UnitException
that
- The given unit to multiply this unit by.
UnitException
- It's meaningless to multiply these units.public abstract Unit divide(Unit that) throws UnitException
that
- The unit to divide into this unit.
UnitException
- It's meaningless to divide these units.protected abstract Unit divideInto(Unit that) throws UnitException
that
- The unit to be divided by this unit.
UnitException
- It's meaningless to divide these units.public double toThis(double value, Unit that) throws UnitException
value
- The value in units of the other unit.that
- The other unit.
UnitException
- The units are not convertible.public abstract double[] toThis(double[] values, Unit that) throws UnitException
values
- Values in units of the other unit.that
- The other unit.
UnitException
- The units are not convertible.public abstract float[] toThis(float[] values, Unit that) throws UnitException
values
- Values in units of the other unit.that
- The other unit.
UnitException
- The units are not convertible.public double toThat(double value, Unit that) throws UnitException
value
- The value in this unit.that
- The other unit.
UnitException
- The units are not convertible.public abstract double[] toThat(double[] values, Unit that) throws UnitException
values
- The values in this unit.that
- The other unit.
UnitException
- The units are not convertible.public abstract float[] toThat(float[] values, Unit that) throws UnitException
values
- The values in this unit.that
- The other unit.
UnitException
- The units are not convertible.public final java.lang.String toString()
toString
in class java.lang.Object
null
but may be empty.public final java.lang.String getIdentifier()
null
but won't be empty.public abstract java.lang.String getDefinition()
null
but may be empty.public Unit getAbsoluteUnit()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |