public class Datum
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable
A Datum is a number in the context of a Unit, for example "15 microseconds." A Datum object has methods for
Modifier and Type | Class and Description |
---|---|
static class |
Datum.Double
class backing Datums with a double.
|
static class |
Datum.Long
class backing Datums with a long, such as with CDF_TT2000.
|
Modifier and Type | Field and Description |
---|---|
protected Units |
units |
protected java.lang.Number |
value |
Modifier and Type | Method and Description |
---|---|
Datum |
abs()
return the absolute value (magnitude) of this Datum.
|
Datum |
add(Datum datum)
returns a Datum whose value is the sum of
this and datum , in this.getUnits() . |
Datum |
add(double d,
Units units)
returns a Datum whose value is the sum of
this and value in
the context of units , in this.getUnits() . |
Datum |
add(java.lang.Number value,
Units units)
returns a Datum whose value is the sum of
this and value in
the context of units , in this.getUnits() . |
int |
compareTo(Datum a)
compare this to another datum.
|
int |
compareTo(java.lang.Object a)
compare the datum to the object.
|
Datum |
convertTo(Units units)
creates an equivalent datum using a different unit.
|
static Datum |
create(double value)
convenient method for creating a dimensionless Datum with the given value.
|
static Datum |
create(double value,
Units units)
creates a datum with the given units and value, for example,
Datum.create( 54, Units.milliseconds ) |
static Datum |
create(double value,
Units units,
DatumFormatter formatter)
Returns a Datum with a specific DatumFormatter attached to
it.
|
static Datum |
create(double value,
Units units,
double resolution)
Returns a Datum with the given value and limited to the given resolution.
|
static Datum |
create(double value,
Units units,
double resolution,
DatumFormatter formatter)
Returns a Datum with the given value and limited to the given resolution.
|
static Datum |
create(int value)
creates a dimensionless datum backed by an int.
|
static Datum |
create(int value,
Units units)
creates a datum backed by an int with the given units.
|
static Datum |
create(long value)
convenient method for creating a dimensionless Datum with the given value.
|
static Datum |
create(long value,
Units units)
creates a datum with the given units and value, for example,
Datum.create( 54, Units.milliseconds ) |
static Datum |
create(long value,
Units units,
DatumFormatter formatter)
Returns a Datum with a specific DatumFormatter attached to
it.
|
Datum |
div(Datum datum)
Groovy scripting language uses this for overloading.
|
Datum |
divide(Datum a)
divide this by the datum
a . |
Datum |
divide(double d)
divide this by the dimensionless double.
|
Datum |
divide(java.lang.Number a,
Units units)
divide this by the Number provided in the context of units.
|
protected double |
doubleValue()
returns the datum's double value.
|
double |
doubleValue(Units units)
returns a double representing the datum in the context of
units . |
boolean |
equals(Datum a)
returns true if the two datums are equal.
|
boolean |
equals(java.lang.Object a)
returns true if the two datums are equal.
|
Datum |
exp10()
return Math.pow(10,v)
|
boolean |
ge(Datum a)
returns true if this is greater than or equal to
a . |
DatumFormatter |
getFormatter()
returns a formatter suitable for formatting this datum as a string.
|
double |
getResolution(Units units)
returns the resolution (or precision) of the datum.
|
Units |
getUnits()
returns the datum's units.
|
protected java.lang.Number |
getValue()
returns the Number representing the datum's location in the space identified by its units.
|
boolean |
gt(Datum a)
returns true if this is greater than
a . |
int |
hashCode()
returns a hashcode that is a function of the value and the units.
|
protected int |
intValue()
returns the datum's int value.
|
int |
intValue(Units units)
returns a int representing the datum in the context of
units . |
boolean |
isFill()
convenience method for checking to see if a datum is a fill datum.
|
boolean |
isFinite()
returns true if the value is finite, that is not INFINITY or NaN.
|
boolean |
le(Datum a)
returns true if this is less than or equal to
a . |
Datum |
log10()
return log10 of this datum.
|
boolean |
lt(Datum a)
returns true if this is less than
a . |
Datum |
minus(Datum datum)
Groovy scripting language uses this for overloading.
|
Datum |
multiply(Datum a)
multiply this by the datum
a . |
Datum |
multiply(double d)
multiply by a dimensionless number.
|
Datum |
multiply(java.lang.Number a,
Units units)
multiply this by the Number provided in the context of units.
|
Datum |
negative()
Groovy scripting language uses this negation operator.
|
Datum |
plus(Datum datum)
Groovy scripting language uses this for overloading.
|
Datum |
positive()
Groovy scripting language uses this positive operator.
|
Datum |
power(Datum datum)
Groovy scripting language uses this for overloading a**b.
|
Datum |
power(double b)
Groovy scripting language uses this for overloading a**b.
|
Datum |
subtract(Datum datum)
returns a Datum whose value is the difference of
this and value . |
Datum |
subtract(double d,
Units units)
returns a Datum whose value is the difference of
this and value in
the context of units . |
Datum |
subtract(java.lang.Number a,
Units units)
returns a Datum whose value is the difference of
this and value in
the context of units . |
java.lang.String |
toString()
returns a human readable String representation of the Datum, which should also be parseable with
Units.parse()
|
double |
value()
returns the double value without the unit, as long as the Units indicate this is a ratio measurement, and there is a meaningful 0.
|
protected Units units
protected java.lang.Number value
protected double doubleValue()
public double doubleValue(Units units)
units
.units
- the Units in which the double should be returnedpublic double value()
public Datum abs()
java.lang.IllegalArgumentException
- if the datum is not a ratio measurement (like a timetag).which returns the double value.
public double getResolution(Units units)
units
- the Units in which the double resolution should be returned. Note
the units must be convertible to this.getUnits().getOffsetUnits().protected int intValue()
public int intValue(Units units)
units
.units
- the Units in which the int should be returnedpublic Units getUnits()
protected java.lang.Number getValue()
public boolean isFill()
public Datum plus(Datum datum)
datum
- Datum to add, that is convertible to this.getUnits().public Datum minus(Datum datum)
datum
- Datum to subtract, that is convertible to this.getUnits().public Datum div(Datum datum)
datum
- Datum to divide, that is convertible to this.getUnits().public Datum power(double b)
b
- double to exponentiate, that is dimensionless.public Datum power(Datum datum)
datum
- Datum to exponentiate, that is dimensionless.public Datum log10()
public Datum exp10()
public Datum negative()
java.lang.IllegalArgumentException
- when the units are location units.public Datum positive()
public Datum add(Datum datum)
this
and datum
, in this.getUnits()
.datum
- Datum to add, that is convertible to this.getUnits().public Datum add(java.lang.Number value, Units units)
this
and value in
the context of units
, in this.getUnits()
.value
- a Number to add in the context of units.units
- units defining the context of value. There should be a converter from
units to this Datum's units.public Datum add(double d, Units units)
this
and value in
the context of units
, in this.getUnits()
.d
- a Number to add in the context of units.units
- units defining the context of value. There should be a converter from
units to this Datum's units.public Datum subtract(Datum datum)
this
and value
.
The returned Datum will have units according to the type of units subtracted.
For example, "1979-01-02T00:00" - "1979-01-01T00:00" = "24 hours" (this datum's unit's offset units),
while "1979-01-02T00:00" - "1 hour" = "1979-01-01T23:00" (this datum's units.)
Note also the resolution of the result is calculated.datum
- Datum to add, that is convertible to this.getUnits() or offset units.public Datum subtract(java.lang.Number a, Units units)
this
and value in
the context of units
.
The returned Datum will have units according to the type of units subtracted.
For example, "1979-01-02T00:00" - "1979-01-01T00:00" = "24 hours" (this datum's unit's offset units),
while "1979-01-02T00:00" - "1 hour" = "1979-01-01T23:00" (this datum's units.)a
- a Number to add in the context of units.units
- units defining the context of value. There should be a converter from
units to this Datum's units or offset units.public Datum subtract(double d, Units units)
this
and value in
the context of units
.
The returned Datum will have units according to the type of units subtracted.
For example, "1979-01-02T00:00" - "1979-01-01T00:00" = "24 hours" (this datum's unit's offset units),
while "1979-01-02T00:00" - "1 hour" = "1979-01-01T23:00" (this datum's units.)d
- a Number to add in the context of units.units
- units defining the context of value. There should be a converter from
units to this Datum's units or offset units.public Datum divide(Datum a)
a
. Currently, only division is only supported:between convertable units, resulting in a Units.dimensionless quantity, or by a Units.dimensionless quantity, and a datum with this datum's units is returned.This may change, as a generic SI units class is planned.
a
- the datum divisor.public Datum divide(java.lang.Number a, Units units)
between convertable units, resulting in a Units.dimensionless quantity, or by a Units.dimensionless quantity, and a datum with this datum's units is returned.This may change, as a generic SI units class is planned.
a
- the magnitude of the divisor.units
- the units of the divisor.public Datum divide(double d)
d
- the magnitude of the divisor.public Datum multiply(Datum a)
a
. Currently, only multiplication is only supported
by a dimensionless datum, or when this is dimensionless.
This may change, as a generic SI units class is planned.
This should also throw an IllegalArgumentException if the units are LocationUnits (e.g. UT time), but doesn't. This may
change.a
- the datum to multiplypublic Datum multiply(java.lang.Number a, Units units)
a
- the magnitude of the multiplier.units
- the units of the multiplier.public Datum multiply(double d)
d
- the multiplier.public Datum convertTo(Units units) throws java.lang.IllegalArgumentException
x= Datum.create( 5, Units.seconds );
System.err.println( x.convertTo( Units.seconds ) );
units
- the new Datum's unitsjava.lang.IllegalArgumentException
- if the datum cannot be converted to the given units.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object a) throws java.lang.IllegalArgumentException
equals
in class java.lang.Object
a
- the Object to compare to.java.lang.IllegalArgumentException
- if the Object is not a datum or the units are not convertable.public boolean equals(Datum a) throws java.lang.IllegalArgumentException
a
- the datum to comparejava.lang.IllegalArgumentException
- if the units are not convertable.public boolean lt(Datum a) throws java.lang.IllegalArgumentException
a
.a
- a datum convertible to this Datum's units.a
.java.lang.IllegalArgumentException
- if the two don't have convertible units.public boolean gt(Datum a) throws java.lang.IllegalArgumentException
a
.a
- a datum convertible to this Datum's units.a
.java.lang.IllegalArgumentException
- if the two don't have convertible units.public boolean le(Datum a) throws java.lang.IllegalArgumentException
a
.a
- a datum convertible to this Datum's units.a
.java.lang.IllegalArgumentException
- if the two don't have convertible units.public boolean ge(Datum a) throws java.lang.IllegalArgumentException
a
.a
- a datum convertible to this Datum's units.a
.java.lang.IllegalArgumentException
- if the two don't have convertible units.public int compareTo(java.lang.Object a) throws java.lang.IllegalArgumentException
compareTo
in interface java.lang.Comparable
a
- the Object to compare this datum to.java.lang.IllegalArgumentException
- if a is not a Datum or is not convertible to this Datum's units.public int compareTo(Datum a) throws java.lang.IllegalArgumentException
a
- the Datum to compare this datum to.java.lang.IllegalArgumentException
- if a is not convertible to this Datum's
units.public boolean isFinite()
public java.lang.String toString()
toString
in class java.lang.Object
public static Datum create(double value)
value
- the magnitude of the datum.public static Datum create(double value, Units units)
Datum.create( 54, Units.milliseconds )
value
- the magnitude of the datum.units
- the units of the datum.public static Datum create(double value, Units units, DatumFormatter formatter)
value
- the magnitude of the datum.units
- the units of the datum.formatter
- the DatumFormatter that should be used to format this datum, which will be
returned by getFormatter().public static Datum create(double value, Units units, double resolution)
value
- the magnitude of the datum, or value to be interpreted in the context of units.units
- the units of the datum.resolution
- the limit to which the datum's precision is known.public static Datum create(double value, Units units, double resolution, DatumFormatter formatter)
value
- the magnitude of the datum, or value to be interpreted in the context of units.units
- the units of the datum.resolution
- the limit to which the datum's precision is known.formatter
- the DatumFormatter that should be used to format this datum, which will be
returned by getFormatter().public static Datum create(long value)
value
- the magnitude of the datum.public static Datum create(long value, Units units)
Datum.create( 54, Units.milliseconds )
value
- the magnitude of the datum.units
- the units of the datum.public static Datum create(long value, Units units, DatumFormatter formatter)
value
- the magnitude of the datum.units
- the units of the datum.formatter
- the DatumFormatter that should be used to format this datum, which will be
returned by getFormatter().public static Datum create(int value)
value
- the magnitude of the dimensionless datum.public static Datum create(int value, Units units)
value
- the magnitude of the datumunits
- the units of the datumpublic DatumFormatter getFormatter()