|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object visad.Unit
public abstract class Unit
A class that represents a unit of a quantity. Instances are immutable.
Field Summary | |
---|---|
protected int |
hashCode
|
Constructor Summary | |
---|---|
protected |
Unit()
Constructs from nothing. |
protected |
Unit(String identifier)
Constructs from an identifier. |
Method Summary | |
---|---|
protected String |
adjustCheckAndCache(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(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; returning a new tuple. |
static double[][] |
convertTuple(double[][] value,
Unit[] units_in,
Unit[] units_out,
boolean copy)
Converts a tuple of double value arrays, optionally returning a new tuple depending on the value of copy . |
static float[][] |
convertTuple(float[][] value,
Unit[] units_in,
Unit[] units_out)
Converts a tuple of float value arrays; returning a new tuple. |
static float[][] |
convertTuple(float[][] value,
Unit[] units_in,
Unit[] units_out,
boolean copy)
Converts a tuple of float value arrays, optionally returning a new tuple depending on the value of copy . |
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. |
boolean |
equals(Object that)
Indicates whether or not this instance is equal to an object. |
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 String |
getDefinition()
Returns the definition of this unit. |
abstract DerivedUnit |
getDerivedUnit()
Returns the derived unit that underlies this unit. |
String |
getIdentifier()
Returns the identifier (name or abbreviation) of this unit. |
abstract int |
hashCode()
Abstract method for computing hashcode |
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 |
log(double base)
Returns the logarithmic unit that has this unit as its reference level. |
static void |
main(String[] args)
Test this class. |
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(String identifier)
Clones this unit, changing the identifier. |
abstract Unit |
root(int root)
Returns the N-th root of this unit. |
abstract Unit |
scale(double amount)
Scale this unit by an amount. |
abstract Unit |
shift(double offset)
Shift this unit by an amount. |
Unit |
sqrt()
Returns the square-root of this unit. |
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[] values,
Unit that,
boolean copy)
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. |
float[] |
toThat(float[] values,
Unit that,
boolean copy)
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[] values,
Unit that,
boolean copy)
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. |
float[] |
toThis(float[] values,
Unit that,
boolean copy)
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 double[] |
transformUnits(Unit unit_out,
ErrorEstimate[] errors_out,
Unit unit_in,
ErrorEstimate error_in,
double[] value,
boolean copy)
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. |
static float[] |
transformUnits(Unit unit_out,
ErrorEstimate[] errors_out,
Unit unit_in,
ErrorEstimate error_in,
float[] value,
boolean copy)
Transform float values and (optionally) error estimates. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected transient int hashCode
Constructor Detail |
---|
protected Unit()
protected Unit(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
Converts a tuple of double value arrays; returning a new tuple.
This implementation uses 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 double[][] convertTuple(double[][] value, Unit[] units_in, Unit[] units_out, boolean copy) throws UnitException, VisADException
Converts a tuple of double value arrays, optionally returning a new tuple
depending on the value of copy
.
This implementation uses 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.copy
- If true, a new array is created, otherwise if a unit in
units_in
equals the unit at the corresponding
index in the units_out
, the input value array at
that index is returned instead of a new array.
units_in
equals units_out
copy is false, then this just returns the value argument.
Otherwise, returns the the converted values in a new array where
RETURN_VALUE [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; returning a new tuple.
This implementation uses 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 float[][] convertTuple(float[][] value, Unit[] units_in, Unit[] units_out, boolean copy) throws UnitException, VisADException
Converts a tuple of float value arrays, optionally returning a new tuple
depending on the value of copy
.
This implementation uses 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.copy
- If true, a new array is created, otherwise if a unit in
units_in
equals the unit at the corresponding
index in the units_out
, the input value array at
that index is returned instead of a new array.
units_in
equals units_out
copy is false, then this just returns the value argument.
Otherwise, returns the the converted values in a new array where
RETURN_VALUE [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 boolean equals(Object that)
equals
in class Object
that
- The object in question.
true
if and only if this instance equals the unit.public abstract int hashCode()
hashCode
in class Object
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.
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.
NullPointerException
- if errors_out
is null
.
UnitException
- if the input and output unit aren't convertible.
VisADException
- if a VisAD failure occurs.public static double[] transformUnits(Unit unit_out, ErrorEstimate[] errors_out, Unit unit_in, ErrorEstimate error_in, double[] value, boolean copy) 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.copy
- if false and unit_out
equals unit_in
, transform values in place.
null
;
otherwise, a new array is returned.
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, boolean copy) 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.copy
- if false and unit_out
equals unit_in
, transform values in place.
null
;
otherwise, a new array is returned.
NullPointerException
- if errors_out
is null
.
UnitException
- if the input and output unit aren't convertible.
VisADException
- if a VisAD failure occurs.protected final String adjustCheckAndCache(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(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(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(String)
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 IllegalArgumentException, UnitException
root
- The root to take (e.g. 2 means square root). Must not be zero.
root
-th root of this
unit.
require: The unit is not an offset unit.
promise: The unit has not been modified.
UnitException
- It's meaningless to raise this unit by a power.
IllegalArgumentException
- The root value is zero or the resulting unit would have a
non-integral unit dimension.public Unit sqrt() throws IllegalArgumentException, UnitException
root(int root)
with a value of 2
.
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, 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.
IllegalArgumentException
- This unit is not dimensionless and power
has a
non-integral value.
promise: The unit has not been modified.public abstract 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 abstract 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 log(double base) throws UnitException
base
- The logarithmic base: one of 2
, Math.E
, or
10
.
IllegalArgumentException
- if base
isn't one of the allowed values.
UnitException
- if this unit can't be used as a reference level for a
logarithmic unit.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[] toThis(double[] values, Unit that, boolean copy) throws UnitException
values
- Values in units of the other unit.that
- The other unit.copy
- true to make a copy if units are not equal. Ignored in this
class.
UnitException
- The units are not convertible.public float[] toThis(float[] values, Unit that, boolean copy) throws UnitException
values
- Values in units of the other unit.that
- The other unit.copy
- true to make a copy if units are not equal. Ignored in this
class.
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 double[] toThat(double[] values, Unit that, boolean copy) throws UnitException
values
- The values in this unit.that
- The other unit.copy
- true to make a copy if units are not equal. Ignored in this
class.
UnitException
- The units are not convertible.public float[] toThat(float[] values, Unit that, boolean copy) throws UnitException
values
- The values in this unit.that
- The other unit.copy
- true to make a copy if units are not equal. Ignored in this
class.
UnitException
- The units are not convertible.public final String toString()
toString
in class Object
null
but may be empty.public final String getIdentifier()
null
but won't
be empty.public abstract String getDefinition()
null
but may be empty.public Unit getAbsoluteUnit()
public abstract DerivedUnit getDerivedUnit()
public static void main(String[] args) throws UnitException
args
- Arguments (ignored).
UnitException
- A problem occurred.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |