com.davisor.data
Class RelativeTimestampType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.data.LocaleType
              extended bycom.davisor.data.FormatType
                  extended bycom.davisor.data.DateFormatType
                      extended bycom.davisor.data.TimestampType
                          extended bycom.davisor.data.RelativeTimestampType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, NumberType, java.io.Serializable

public class RelativeTimestampType
extends TimestampType
implements NumberType

RelativeTimestampType defines a data type that supports timestamp values expressed relative to the given zero timestamp value. The relative timestamp data values are simple double precision floating point values that when multiplied with the type timescale parameter and added to the type zero timestamp parameter result an absolute timestamp value.

Since:
JDK1.1
See Also:
DoubleData, TimestampData, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
static java.lang.String TYPENAME
          Type name ("RELATIVESTAMP").
 
Fields inherited from class com.davisor.data.TimestampType
DEFAULT
 
Fields inherited from class com.davisor.data.DateFormatType
GMT, LOCAL, M_style, M_timeZone
 
Fields inherited from class com.davisor.data.FormatType
M_pattern, M_sample
 
Fields inherited from class com.davisor.data.LocaleType
DEFAULT_LOCALE, M_locale
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS
 
Constructor Summary
  RelativeTimestampType()
          Default constructor.
  RelativeTimestampType(RelativeTimestampType rtt)
          Copy constructor.
  RelativeTimestampType(java.lang.String dataName)
          Creates a new default type with no identity.
  RelativeTimestampType(java.lang.String dataName, java.lang.String id, java.util.Locale locale, java.lang.String pattern, java.lang.Object sample, int style, java.util.TimeZone timeZone, long zero, double scale)
          Creates a new relative timestamp type.
  RelativeTimestampType(java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.util.Locale locale, int style, java.util.TimeZone timeZone, long zero, double scale)
          Creates a new timestamp type with the specific locale formatting.
  RelativeTimestampType(java.lang.String dataName, java.lang.String id, java.lang.String format)
          Creates a new timestamp type with localized timestamp formatting.
protected RelativeTimestampType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.util.Locale locale, java.lang.String pattern, java.lang.Object sample, int style, java.util.TimeZone timeZone, long zero, double scale)
          Creates a new relative timestamp type.
 
Method Summary
 byte byteValue(byte value)
          Converts a byte value to an another byte value.
 byte byteValue(java.lang.String value, java.text.ParsePosition status)
          Converts a string to a byte value.
 java.lang.String check(java.lang.String value)
          Checks and reformats a data string value.
 java.util.Date dateValue(double doubleValue)
          Computes relative time from the given date value.
 java.util.Date dateValue(long longValue)
          Computes relative time from the given date value.
 double doubleValue(java.util.Date dateValue)
          Computes relative time from the given date value.
 double doubleValue(double value)
          Converts a double value to an another double value.
 double doubleValue(long timeValue)
          Computes relative time from the given date value.
 double doubleValue(java.lang.String value, java.text.ParsePosition status)
          Converts a string to a double value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
 float floatValue(float value)
          Converts a float value to an another float value.
 float floatValue(java.lang.String value, java.text.ParsePosition status)
          Converts a string to a float value.
 int getSQLCode()
          Gets the SQL type code, as defined by java.sql.Types.
 int hashCode()
          Returns a hash code value for the object.
 int intValue(int value)
          Converts a integer value to an another int value.
 int intValue(java.lang.String value, java.text.ParsePosition status)
          Converts a string to an int value.
 long longValue(java.util.Date dateValue)
          Computes relative time from the given date value.
 long longValue(long value)
          Converts a long value to an another long value.
 long longValue(java.lang.String value, java.text.ParsePosition status)
          Converts a string to a long value.
 java.lang.Number numberValue(java.lang.String value, java.text.ParsePosition status)
          Converts a string to a Number value.
 short shortValue(short value)
          Converts a short value to an another short value.
 short shortValue(java.lang.String value, java.text.ParsePosition status)
          Converts a string to a short value.
 java.lang.String stringValue(byte value)
          Converts a byte value to a string.
 java.lang.String stringValue(double value)
          Converts a double value to a string.
 java.lang.String stringValue(float value)
          Converts a float value to a string.
 java.lang.String stringValue(int value)
          Converts an int value to a string.
 java.lang.String stringValue(long value)
          Converts a long value to a string.
 java.lang.String stringValue(java.lang.Number value)
          Converts a Number value to a string.
 java.lang.String stringValue(short value)
          Converts a short value to a string.
 DataValue toData(java.sql.CallableStatement statement, int column)
          Converts a callable statement variable to a data value.
 DataValue toData(java.lang.Object objectValue)
          Converts an object to a data value.
 DataValue toData(java.sql.ResultSet resultSet, int column)
          Converts a result set column value to a data value.
 DataValue toData(java.lang.String stringValue, java.text.ParsePosition status)
          Converts a string to a data value.
 
Methods inherited from class com.davisor.data.TimestampType
zero
 
Methods inherited from class com.davisor.data.DateFormatType
createCalendar, createCalendar, createCalendar, createCalendar, createCalendar, createCalendar, createFormatter, dateValue, getFormat, getLast, getStyle, getTimeZone, getValueClass, setFormat, setStyle, setTimeZone, stringValue, strip, toData, toData
 
Methods inherited from class com.davisor.data.FormatType
clearFormatter, getFormatter, getPattern, getSample, setFormat, setLocale, setPattern, setSample
 
Methods inherited from class com.davisor.data.LocaleType
getLocale, setLocale
 
Methods inherited from class com.davisor.data.Type
ceil, check, compare, create, create, create, create, create, dup, floor, format, getCompatibility, getDataName, getId, getID, getMetaData, getMetaData, getSpecs, getSQLName, getSQLName, getTypeName, isNull, parseObject, register, register, setDataName, setId, setID, setMetaData, setMetaData, setSpecs, toString, toXML, xmlEnd, xmlStart
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPENAME

public static final java.lang.String TYPENAME
Type name ("RELATIVESTAMP").

See Also:
Constant Field Values
Constructor Detail

RelativeTimestampType

public RelativeTimestampType()
Default constructor.


RelativeTimestampType

public RelativeTimestampType(RelativeTimestampType rtt)
Copy constructor.


RelativeTimestampType

public RelativeTimestampType(java.lang.String dataName)
Creates a new default type with no identity.

Parameters:
dataName - data name (may be null)

RelativeTimestampType

public RelativeTimestampType(java.lang.String dataName,
                             java.lang.String id,
                             java.lang.String format)
Creates a new timestamp type with localized timestamp formatting.

This is the constructor the SQL type mapper Type.create(Integer,String,String,String) method will call to create a type that matches given SQL type.

Parameters:
dataName - data name
id - type identity
format - language and country codes, separated by a single space characters. null or an empty specification string implies SQL timestamp formatting.
See Also:
DateFormatType.setFormat(java.lang.String)

RelativeTimestampType

public RelativeTimestampType(java.lang.String dataName,
                             java.lang.String id,
                             java.util.Map metaData,
                             java.util.Locale locale,
                             int style,
                             java.util.TimeZone timeZone,
                             long zero,
                             double scale)
Creates a new timestamp type with the specific locale formatting.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
locale - type locale (may be null)
style - time format style, as defined by the DateFormat class
timeZone - date format time zone
zero - time offset
scale - time scale

RelativeTimestampType

public RelativeTimestampType(java.lang.String dataName,
                             java.lang.String id,
                             java.util.Locale locale,
                             java.lang.String pattern,
                             java.lang.Object sample,
                             int style,
                             java.util.TimeZone timeZone,
                             long zero,
                             double scale)
Creates a new relative timestamp type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
locale - type locale (may be null)
pattern - format pattern (may be null)
sample - format sample (may be null)
style - date format style, as defined by the DateFormat class
timeZone - date format time zone
zero - time offset
scale - time scale

RelativeTimestampType

protected RelativeTimestampType(java.lang.String typeName,
                                java.lang.String dataName,
                                java.lang.String id,
                                java.util.Map metaData,
                                java.util.Locale locale,
                                java.lang.String pattern,
                                java.lang.Object sample,
                                int style,
                                java.util.TimeZone timeZone,
                                long zero,
                                double scale)
Creates a new relative timestamp type.

Parameters:
typeName - type name
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
locale - type locale (may be null)
pattern - format pattern (may be null)
sample - format sample (may be null)
style - date format style, as defined by the DateFormat class
timeZone - date format time zone
zero - time offset
scale - time scale
Method Detail

dup

public com.davisor.core.Dupable dup()
Makes a deep copy of this object.

Specified by:
dup in interface com.davisor.core.Dupable
Overrides:
dup in class TimestampType

byteValue

public byte byteValue(java.lang.String value,
                      java.text.ParsePosition status)
               throws InvalidDataException
Converts a string to a byte value.

Specified by:
byteValue in interface NumberType
Parameters:
value - the string to be converted
status - parse status (may be null)
Returns:
byte value
Throws:
InvalidDataException - if the value cannot be converted to a byte value.

doubleValue

public double doubleValue(java.lang.String value,
                          java.text.ParsePosition status)
                   throws InvalidDataException
Converts a string to a double value.

Specified by:
doubleValue in interface NumberType
Parameters:
value - the string to be converted
status - parse status (may be null)
Returns:
double value
Throws:
InvalidDataException - if the value cannot be converted to a double value.

floatValue

public float floatValue(java.lang.String value,
                        java.text.ParsePosition status)
                 throws InvalidDataException
Converts a string to a float value.

Specified by:
floatValue in interface NumberType
Parameters:
value - the string to be converted
status - parse status (may be null)
Returns:
float value
Throws:
InvalidDataException - if the value cannot be converted to a float value.

intValue

public int intValue(java.lang.String value,
                    java.text.ParsePosition status)
             throws InvalidDataException
Converts a string to an int value.

Specified by:
intValue in interface NumberType
Parameters:
value - the string to be converted
status - parse status (may be null)
Returns:
integer value
Throws:
InvalidDataException - if the value cannot be converted to a int value.

longValue

public long longValue(java.lang.String value,
                      java.text.ParsePosition status)
               throws InvalidDataException
Converts a string to a long value.

Specified by:
longValue in interface NumberType
Parameters:
value - the string to be converted
status - parse status (may be null)
Returns:
long value
Throws:
InvalidDataException - if the value cannot be converted to a long value.

numberValue

public java.lang.Number numberValue(java.lang.String value,
                                    java.text.ParsePosition status)
                             throws InvalidDataException
Converts a string to a Number value.

Specified by:
numberValue in interface NumberType
Parameters:
value - the string to be converted (may be null)
status - parse status (may be null)
Returns:
Number value, or null
Throws:
InvalidDataException - if the value cannot be converted to a long value.

shortValue

public short shortValue(java.lang.String value,
                        java.text.ParsePosition status)
                 throws InvalidDataException
Converts a string to a short value.

Specified by:
shortValue in interface NumberType
Parameters:
value - the string to be converted
status - parse status (may be null)
Returns:
short value
Throws:
InvalidDataException - if the value cannot be converted to a short value.

stringValue

public java.lang.String stringValue(byte value)
Converts a byte value to a string.

Specified by:
stringValue in interface NumberType
Parameters:
value - the value to be converted

stringValue

public java.lang.String stringValue(double value)
Converts a double value to a string.

Specified by:
stringValue in interface NumberType
Parameters:
value - the value to be converted

stringValue

public java.lang.String stringValue(float value)
Converts a float value to a string.

Specified by:
stringValue in interface NumberType
Parameters:
value - the value to be converted

stringValue

public java.lang.String stringValue(int value)
Converts an int value to a string.

Specified by:
stringValue in interface NumberType
Parameters:
value - the value to be converted

stringValue

public java.lang.String stringValue(long value)
Converts a long value to a string.

Specified by:
stringValue in interface NumberType
Parameters:
value - the value to be converted

stringValue

public java.lang.String stringValue(short value)
Converts a short value to a string.

Specified by:
stringValue in interface NumberType
Parameters:
value - the value to be converted

stringValue

public java.lang.String stringValue(java.lang.Number value)
Converts a Number value to a string.

Specified by:
stringValue in interface NumberType
Parameters:
value - the value to be converted

byteValue

public byte byteValue(byte value)
Converts a byte value to an another byte value.

Specified by:
byteValue in interface NumberType
Parameters:
value - the value to be converted

doubleValue

public double doubleValue(double value)
Converts a double value to an another double value.

Specified by:
doubleValue in interface NumberType
Parameters:
value - the value to be converted

floatValue

public float floatValue(float value)
Converts a float value to an another float value.

Specified by:
floatValue in interface NumberType
Parameters:
value - the value to be converted

intValue

public int intValue(int value)
Converts a integer value to an another int value.

Specified by:
intValue in interface NumberType
Parameters:
value - the value to be converted

longValue

public long longValue(long value)
Converts a long value to an another long value.

Specified by:
longValue in interface NumberType
Parameters:
value - the value to be converted

shortValue

public short shortValue(short value)
Converts a short value to an another short value.

Specified by:
shortValue in interface NumberType
Parameters:
value - the value to be converted

equals

public boolean equals(java.lang.Object o)
Tests if this object is equal with another object.

Relative timestamp types are equal if their super-classes and scale and zero values are.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class TimestampType

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class DateFormatType

check

public java.lang.String check(java.lang.String value)
                       throws InvalidDataException
Checks and reformats a data string value.

The default checking procedure is to first parse the data string as a data object, and then turn the resulting object back to a data string. Parsing checks the validity of the data string, while formatting reformats it. Therefore, in addition to validating the input value, the resulting string may also have been changed in some way.

Overrides:
check in class Type
Parameters:
value - data string value
Returns:
checked and reformatted data string
Throws:
InvalidDataException - if the value is invalid as a timestamp
See Also:
Type.check(String[]), Type.toData(java.lang.String, java.text.ParsePosition), DataValue.toString()

getSQLCode

public int getSQLCode()
Gets the SQL type code, as defined by java.sql.Types.

Overrides:
getSQLCode in class TimestampType

toData

public DataValue toData(java.sql.CallableStatement statement,
                        int column)
                 throws InvalidDataException,
                        java.sql.SQLException
Converts a callable statement variable to a data value.

Gets statement double value, and returns a corresponding DoubleData value.

Overrides:
toData in class TimestampType
Parameters:
statement - statement holding the data value to be converted
column - SQL column index for the data value to be converted
Returns:
a data value object corresponding to given object value
Throws:
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurs
See Also:
toData(Object), toData(ResultSet,int), toData(String,ParsePosition), DoubleData

toData

public DataValue toData(java.lang.Object objectValue)
                 throws InvalidDataException
Converts an object to a data value.

NumberValue, Number, and Date objects are converted directly, other objects are converted first to strings, then to double values.

Overrides:
toData in class DateFormatType
Parameters:
objectValue - data object
Returns:
a data value object corresponding to given object value
Throws:
InvalidDataException - if given object value could not be parsed
See Also:
toData(CallableStatement,int), toData(ResultSet,int), toData(String,ParsePosition), DoubleData

toData

public DataValue toData(java.lang.String stringValue,
                        java.text.ParsePosition status)
                 throws InvalidDataException
Converts a string to a data value.

RelativeTimestamp type expects the given value to contain a date or a double value, and returns a corresponding DoubleData value.

Overrides:
toData in class DateFormatType
Parameters:
stringValue - data string
status - parse status (may be null)
Returns:
a data value object corresponding given string value
Throws:
InvalidDataException - if given string value could not be parsed
See Also:
toData(CallableStatement,int), toData(Object), toData(ResultSet,int), DoubleData

toData

public DataValue toData(java.sql.ResultSet resultSet,
                        int column)
                 throws InvalidDataException,
                        java.sql.SQLException
Converts a result set column value to a data value.

Gets result set column double value, and returns a corresponding DoubleData value.

Overrides:
toData in class TimestampType
Parameters:
resultSet - resultSet holding the data value to be converted
column - SQL column index for the data value to be converted
Returns:
a data value object corresponding to given object value
Throws:
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurs
See Also:
toData(CallableStatement,int), toData(Object), toData(String,ParsePosition), DoubleData

dateValue

public java.util.Date dateValue(double doubleValue)
Computes relative time from the given date value.


dateValue

public java.util.Date dateValue(long longValue)
Computes relative time from the given date value.


doubleValue

public double doubleValue(java.util.Date dateValue)
Computes relative time from the given date value.


doubleValue

public double doubleValue(long timeValue)
Computes relative time from the given date value.


longValue

public long longValue(java.util.Date dateValue)
Computes relative time from the given date value.



Copyright © 2001-2004 Davisor Oy. All Rights Reserved.