|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.util.Date
com.davisor.data.TimestampData
A TimestampData object represents a timestamp value.
TimestampType,
Serialized Form| Field Summary | |
protected DateFormatType |
M_type
The type of this data. |
static long |
NaT
Not-a-Time timestamp value (Long.MIN_VALUE). |
| Constructor Summary | |
TimestampData()
Creates a new timestamp data object with the current timestamp and default type. |
|
TimestampData(java.util.Date date)
Creates a new timestamp data object with the default type and given date. |
|
TimestampData(DateFormatType type)
Creates a new timestamp data object with the current timestamp and given type. |
|
TimestampData(DateFormatType type,
java.util.Date date)
Creates a new timestamp data object with the given type and date. |
|
TimestampData(DateFormatType type,
long milliseconds)
Creates a new timestamp data object with the given type and value. |
|
TimestampData(DateFormatType type,
java.lang.String stringValue,
java.text.ParsePosition status)
Creates a timestamp data value from a string value. |
|
TimestampData(long milliseconds)
Creates a new timestamp data object with the default type and given value. |
|
TimestampData(TimestampData td,
boolean deep)
Deep or shallow copy constructor. |
|
| Method Summary | |
DataValue |
abs()
Returns absolute data value of current value. |
DataValue |
add(DataValue value)
Adds given value to current value. |
DataValue |
ceil(DataValue precision)
Quantizes the current value up to an even value within given precision. |
DataValue |
ceil(java.util.Date precision)
Quantizes the current value up to an even value within given date precision. |
static int |
compareTo(java.util.Date data,
java.lang.Object o)
Compares this timestamp against other Date objects. |
int |
compareTo(java.lang.Object o)
Compares this timestamp against other Date objects. |
java.util.Calendar |
createCalendar()
Creates a new calendar set to the moment of time this object currently represents. |
double |
deinterpolate(DataValue min,
DataValue max)
De-interpolates the current data value to a scalar value, in respect, with given data value range. |
DataValue |
div(DataValue value)
Divides the current value with given number value. |
com.davisor.core.Dupable |
dup()
Makes a deep copy of this object. |
DataValue |
floor(DataValue precision)
Quantizes the current value down to an even value within given precision. |
DataValue |
floor(java.util.Date precision)
Quantizes the current value down to an even value within given precision. |
java.lang.String |
getFormat()
Gets the type specification optimal for this particular value. |
Type |
getType()
Gets the data type. |
protected static long |
initTime(DateFormatType type,
long milliseconds)
Makes a millisecond timestamp value suitable for given type. |
DataValue |
interpolate(double value,
DataValue max)
Interpolates the given scalar value to data value, in respect, with the range defined by this value and the given maximum value. |
boolean |
isNull()
Tests if this data object value is undetermined. |
DataValue |
max(DataValue value)
Finds the largest data value. |
DataValue |
min(DataValue value)
Finds the larger of this and the given data value. |
DataValue |
mul(DataValue value)
Multiplies the current value with given number value. |
DataValue |
negate()
Returns the negation of current value. |
void |
setTime(java.util.Date value)
Sets the timestamp value. |
void |
setValue(java.lang.String stringValue,
java.text.ParsePosition status)
Sets data value from a string value. |
DataValue |
sub(DataValue value)
Substracts given value from current value. |
void |
toStatement(java.sql.PreparedStatement statement,
int parameter)
Converts data to a prepared statement input parameter. |
java.lang.String |
toString()
Gets the string representation of this timestamp value. |
java.lang.String |
toXML()
Gets the XML string representation of this value. |
DataValue |
unit(DataValue targetValue,
double maxSteps)
Gets the largest suitable unit step to represent a value change between this value and the given target value. |
| Methods inherited from class java.util.Date |
after, before, clone, compareTo, equals, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, UTC |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final long NaT
protected DateFormatType M_type
| Constructor Detail |
public TimestampData()
public TimestampData(TimestampData td,
boolean deep)
td - timestamp to copy (may be null)deep - determines if the copying is deep or shallowgetType(),
Type.dup()public TimestampData(java.util.Date date)
date - timestamp value (may be null)public TimestampData(long milliseconds)
milliseconds - milliseconds valuepublic TimestampData(DateFormatType type)
type - timestamp type
public TimestampData(DateFormatType type,
java.util.Date date)
type - timestamp typedate - timestamp value (may be null)
public TimestampData(DateFormatType type,
long milliseconds)
type - timestamp typemilliseconds - milliseconds value
public TimestampData(DateFormatType type,
java.lang.String stringValue,
java.text.ParsePosition status)
throws InvalidDataException
stringValue - string value to be parsedstatus - parse status (may be null)
InvalidDataException - if string value could not be parsersetValue(String,ParsePosition),
DateFormatType.dateValue(String,ParsePosition)| Method Detail |
public int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparableo - a Date object to compare this timestamp against with
java.lang.ClassCastException - if the given object is not a DatecompareTo(java.util.Date,Object)
public Type getType()
throws InvalidDataException
getType in interface DataInvalidDataException - if type retrieval failspublic boolean isNull()
Timestamp values are undetermined if the underlying Date
value is equal to NaT.
isNull in interface SerializableDataType.isNull(com.davisor.data.SerializableData)
public DataValue abs()
throws InvalidDataException
Absolute values must satisfy a requirement that when added to any other value, the result must be greater than or equal to the original value.
abs in interface DataValueInvalidDataException - if absolute value can not be computed
public DataValue add(DataValue value)
throws InvalidDataException
If the value is an instance of CalendarData, current
timestamp value is converted to a calendar value, to which given
value will be added field by field. This correspond
to a situation when given number of different calendar units like
days and hours are added to a known exact moment of time.
If the value is an instance of CalendarFieldData, current
timestamp value is converted to a calendar value, and given field
value is added to it. This correspond to a situation when given
number of spesific single calendar units are added to a known
exact moment of time.
If the value is an instance of Date, it and the
current timestamp values are converted to calendar values, which
will then be added field by field. This correspond to a situation
when a time period expressed in milliseconds is added to a known
exact moment of time.
If the value is an instance of Date and the value type
is MomentType then the result will be the given value.
Note that in that case this operation is not symmetric!
In any other case, the operation fails.
add in interface DataValuevalue - a data value to be added to this data value
InvalidDataException - if the data values cannot be addedcreateCalendar(),
sub(com.davisor.data.DataValue),
DateFormatType.toData(java.util.Date)
public DataValue ceil(DataValue precision)
throws InvalidDataException
The quantization method depends on given precision type. If the
precision is an instance of CalendarData, current timestamp
value is converted to a calendar value, which will be quantized
field by field.
If the precision is an instance of CalendarFieldData,
current timestamp value is converted to a calendar value,
and quantized by the field value.
If the precision is an instance of DateData, current
timestamp value is converted to a calendar value, which will be
quantized field by field by a calendar object constructed from
the precision object.
If the precision is an instance of Date, it's
milliseconds value will be used as a quantisation factor against
which the current milliseconds value will be quantizied.
In any other case, the operation fails.
ceil in interface DataValueprecision - the precision within quantization occurs
InvalidDataException - if precision was of unacceptable typecreateCalendar(),
floor(com.davisor.data.DataValue),
DateFormatType.toData(java.util.Date)
public double deinterpolate(DataValue min,
DataValue max)
throws InvalidDataException
Timestamp values are de-interpolated with the equation:
(thisValue - minValue) / (maxValue - minValue)
deinterpolate in interface DataValuemin - a data value representing a range's lower limitmax - a data value representing a range's higher limit
InvalidDataException - if the de-interpolation failsDataValue.interpolate(double, com.davisor.data.DataValue),
DeinterpolationException,
TupleData.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue)
public DataValue div(DataValue value)
throws InvalidDataException
div in interface DataValuevalue - the divider (expected to be a Number)
InvalidDataException - if divider is not a number
public DataValue floor(DataValue precision)
throws InvalidDataException
The quantization method depends on given precision type. If the
precision is an instance of CalendarData, current timestamp
value is converted to a calendar value, which will be quantized
field by field.
If the precision is an instance of CalendarFieldData,
current timestamp value is converted to a calendar value,
and quantized by the field value.
If the precision is an instance of DateData, current
timestamp value is converted to a calendar value, which will be
quantized field by field by a calendar object constructed from
the precision object.
If the precision is an instance of Date, it's
milliseconds value will be used as a quantisation factor against
which the current milliseconds value will be quantizied.
In any other case, the operation fails.
floor in interface DataValueprecision - the precision within quantization occurs
InvalidDataException - if precision was of unacceptable typeceil(com.davisor.data.DataValue),
createCalendar(),
DateFormatType.toData(Object)public java.lang.String getFormat()
This method analyzes the magnitude of the calendar time units that the
current time value represents. The field is then mapped to a Java
SimpleDateFormat pattern that best describes the field values.
The current type locale, if any, is also resolved. A
DateFormatType specification string is then
constructed.
getFormat in interface DataValueData.getType(),
DateFormatType.getFormat(),
DateFormatType.setFormat(java.lang.String)
public DataValue interpolate(double value,
DataValue max)
throws InvalidDataException
All number values can interpolate with this simple equation:
minValue + value * (maxValue - minValue)
interpolate in interface DataValuevalue - the scalar value to be interpolatedmax - a data value representing a range's higher limit
InvalidDataException - if the interpolation failsDateFormatType.toData(Object)
public DataValue max(DataValue value)
throws InvalidDataException
This method assumes that the given data value is an instance of
Date. The comparison is done by comparing
the date millisecond time values.
If the given value is null or an
instance of VoidValue, a reference to
this instance is returned.
max in interface DataValuevalue - a data value to be compared with this data value
InvalidDataException - if the data value cannot be comparedmin(com.davisor.data.DataValue)
public DataValue min(DataValue value)
throws InvalidDataException
This method assumes that the given data value is an instance of
Date. The comparison is done by comparing
the date millisecond time values.
If the given value is null or an
instance of VoidValue, a reference to
this instance is returned.
min in interface DataValuevalue - a data value to be compared with this data value
InvalidDataException - if the data value cannot be comparedmax(com.davisor.data.DataValue)
public DataValue mul(DataValue value)
throws InvalidDataException
mul in interface DataValuevalue - the multiplier (expected to be a Number)
InvalidDataException - if multiplier is not a number
public DataValue negate()
throws InvalidDataException
negate in interface DataValueInvalidDataException - if absolute value can not be computed
public void setValue(java.lang.String stringValue,
java.text.ParsePosition status)
throws InvalidDataException
setValue in interface DataValuestringValue - string value to be parsed (may be null)status - parse status (may be null)
InvalidDataException - if string value could not be parserDateFormatType.dateValue(String,ParsePosition)
public DataValue sub(DataValue value)
throws InvalidDataException
If the value is an instance of CalendarData, current
timestamp value is converted to a calendar value, from which
given value will be substracted field by field. This correspond
to a situation when given number of different calendar units like
days and hours are substracted from a known exact moment of time.
If the value is an instance of CalendarFieldData, current
timestamp value is converted to a calendar value, and given field
value is substracted from it. This correspond to a situation when
given number of spesific single calendar units are substracted
from a known exact moment of time.
If the value is an instance of Date, it's
millisecond value is simply substracted from the current
timestamp value. This correspond to a situation when a time
period expressed in milliseconds is substracted from a known
exact moment of time.
If the value is an instance of Date and the value type
is MomentType then the result will be the given value.
In any other case, the operation fails.
sub in interface DataValuevalue - a data value to be substracted from this data value
InvalidDataException - if the data values cannot be substractedcreateCalendar(),
add(com.davisor.data.DataValue),
DateFormatType.toData(java.util.Date)
public void toStatement(java.sql.PreparedStatement statement,
int parameter)
throws java.sql.SQLException
toStatement in interface DataValuejava.sql.SQLException - if a SQL error occurspublic java.lang.String toXML()
toXML in interface DataValuetoString(),
XMLUnicodeEncoder.encode(java.lang.String, boolean)
public DataValue unit(DataValue targetValue,
double maxSteps)
throws InvalidDataException
The returned unit time values are expressed with CalendarFieldData objects, which tell what and how many time
units would be a suitable step between this and given target
value.
If the target value is an instance of CalendarFieldData,
the source value is ignored, and the result is computed solely
from given target value. If the target calendar field value is
greater than one, the result is the same calendar field, but with
the value of one. If the target field value is one, the result is
the next less significant calendar field, again with the value of
one. For example, a target value of 5 hours would
result a unit time of 1 hour, while 1
hour would result 1 minute.
In all other cases, the given source and target values are first converted to calendar values. The most significant time field that is then different between the two calendars is resolved. If the difference is greater than one, the calendar field is returned with a value of one. If the difference is exactly one, the next less significant calendar field is returned, again with the value of one. If the target value equals current value, the most significant calendar field of current time value is returned, with the step value of one.
For example, if the current value is the first of May in
some year at 9 a clock in the morning, and the target value is
the third of May in that same year and at 10 a clock, the result
will be 1 day. If the target value would have been
the second of May, the result would have been 1
hour. If the target value would have been first of
May, the result would haven been 1 minute. And if
the target value would have been equal to current value, the
result would have been 1 month.
unit in interface DataValuetargetValue - target value to be reached (may be null)maxSteps - maximum number of steps (zero leaves the choise open)
InvalidDataException - if target value is unsuitablepublic com.davisor.core.Dupable dup()
dup in interface com.davisor.core.Dupablepublic java.lang.String toString()
toString in interface DataValuesetValue(String,ParsePosition),
DateFormatType.stringValue(Date)
protected static long initTime(DateFormatType type,
long milliseconds)
DateFormatType.createCalendar(java.util.Date). The
calendar fields are then stripped with DateFormatType.strip(java.util.Calendar) to mach the nature of current type. Finally,
the resulting timestamp is restored back to a milliseconds value,
and returned.
The method is static so that it can be used in constructors to process superclass initialization parameters, too.
type - the type the timestamp value is prepared formilliseconds - the timestamp value to prepareDateType.strip(java.util.Calendar),
TimeType.strip(java.util.Calendar)
public DataValue ceil(java.util.Date precision)
throws InvalidDataException
precision - the precision within quantization occurs
InvalidDataException - if precision was of unacceptable typeceil(DataValue),
floor(java.util.Date)public java.util.Calendar createCalendar()
public static int compareTo(java.util.Date data,
java.lang.Object o)
o - a Date object to compare this timestamp against with
java.lang.ClassCastException - if the given object is not a DatecompareTo(Object)
public DataValue floor(java.util.Date precision)
throws InvalidDataException
precision - the precision within quantization occurs
InvalidDataException - if precision was of unacceptable typeceil(java.util.Date),
floor(DataValue)public void setTime(java.util.Date value)
setTime method, which sub-classes may override to
implement explicit time value constraints.
If given timestamp value is null current timestamp
is set to special NaT value that indicates that
the timestamp value is undetermined.
value - a timestamp value (may be null)DateData.setTime(long),
TimeData.setTime(long)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||