com.davisor.data
Class CalendarData

java.lang.Object
  extended byjava.util.Date
      extended bycom.davisor.data.TimestampData
          extended bycom.davisor.data.CalendarData
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, Data, DataValue, com.davisor.core.Dupable, java.io.Serializable, SerializableData

public class CalendarData
extends TimestampData

CalendarData represents a calendar value. A calendar value represents either an absolute date, like first of May, 1999, or a relative period of time, like "five years and two months" or "three weeks and twelve hours, six minutes".

This class extends TimestampData with an internal calendar object that is kept in sync with the underlying timestamp value. This calenderical view affects in particular time arithmetics.

Since:
JDK1.3
See Also:
getCalendar(), CalendarFieldData, CalendarType, DateData, TimeData, TimestampData, Serialized Form

Field Summary
protected  java.util.Calendar M_calendar
          Calendar value.
 
Fields inherited from class com.davisor.data.TimestampData
M_type, NaT
 
Constructor Summary
CalendarData()
          Creates a new calendar data object with the current time and default type.
CalendarData(java.util.Calendar calendar)
          Creates a calendar data value from the default type and given calendar value.
CalendarData(CalendarData cd, boolean deep)
          Deep or shallow copy constructor.
CalendarData(CalendarField field)
          Creates a calendar data value from the default type and given calendar field value.
CalendarData(CalendarField field1, CalendarField field2)
          Creates a calendar data value from the default type and given calendar field values.
CalendarData(DateFormatType type)
          Creates a new calendar data object with the current time and given type.
CalendarData(DateFormatType type, java.util.Calendar calendar)
          Creates a calendar data value from a given type and calendar value.
CalendarData(DateFormatType type, CalendarData calendarData)
          Creates a calendar data value from a given type and calendar value.
CalendarData(DateFormatType type, CalendarField field)
          Creates a calendar data value from a given type and calendar field value.
CalendarData(DateFormatType type, CalendarField field1, CalendarField field2)
          Creates a calendar data value from a given type and calendar field value.
CalendarData(DateFormatType type, CalendarFieldData cfd)
          Creates a calendar data value from a given type and calendar value.
CalendarData(DateFormatType type, java.util.Date date)
          Creates a calendar data value from a given type and date.
CalendarData(DateFormatType type, long milliseconds)
          Creates a calendar data value from a given type and date.
CalendarData(DateFormatType type, java.lang.String stringValue, java.text.ParsePosition status)
          Creates a calendar data value from a string value.
 
Method Summary
 void add(int field, int amount)
          Adds given amount of time to current calendar value.
 DataValue ceil(java.util.Date precision)
          Quantizes the current value up to an even value within given date precision.
 java.util.Calendar createCalendar()
          Creates a new calendar set to the moment of time this object currently represents.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 DataValue floor(java.util.Date precision)
          Quantizes the current value down to an even value within given precision.
 int get(int field)
          Gets the value for a given time field.
 int getActualMaximum(int field)
          Gets the actual maximum value for a given time field, given the current date.
 int getActualMinimum(int field)
          Gets the actual minimum value for a given time field, given the current date.
 java.util.Calendar getCalendar()
          Gets a reference to the underlying calendar object.
 int getGreatestMinimum(int field)
          Gets the greatest minimum value for a given time field.
 int getLeastMaximum(int field)
          Gets the least maximum value for a given time field.
 int getMaximum(int field)
          Gets the maximum value for a given time field, given the current date.
 int getMinimum(int field)
          Gets the minimum value for a given time field, given the current date.
 boolean isNull()
          Tests if this data object value is undetermined.
 void roll(int field, int amount)
          Rolls given field a given amount of time.
 void setTime(long time)
          Sets the duration of this calendar date in milliseconds.
 void setTimeZone(java.util.TimeZone value)
          Sets calendar time zone.
 
Methods inherited from class com.davisor.data.TimestampData
abs, add, ceil, compareTo, compareTo, deinterpolate, div, floor, getFormat, getType, initTime, interpolate, max, min, mul, negate, setTime, setValue, sub, toStatement, toString, toXML, unit
 
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, setYear, toGMTString, toLocaleString, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

M_calendar

protected java.util.Calendar M_calendar
Calendar value.

Constructor Detail

CalendarData

public CalendarData()
Creates a new calendar data object with the current time and default type.

See Also:
DateFormatType.createCalendar(java.util.Date)

CalendarData

public CalendarData(CalendarData cd,
                    boolean deep)
Deep or shallow copy constructor. If it is shallow, then the new object shares the underlying type and calendar with the original object. If it is deep, then the type and calendar are dupped.

Parameters:
cd - source calendar data (may be null)
deep - determines if the copying is deep or shallow

CalendarData

public CalendarData(DateFormatType type)
Creates a new calendar data object with the current time and given type.

Parameters:
type - custom calendar type

CalendarData

public CalendarData(java.util.Calendar calendar)
Creates a calendar data value from the default type and given calendar value.

Parameters:
calendar - calendar

CalendarData

public CalendarData(CalendarField field)
Creates a calendar data value from the default type and given calendar field value.

Parameters:
field - calendar field

CalendarData

public CalendarData(CalendarField field1,
                    CalendarField field2)
Creates a calendar data value from the default type and given calendar field values.

Parameters:
field1 - calendar field
field2 - calendar field

CalendarData

public CalendarData(DateFormatType type,
                    CalendarField field)
Creates a calendar data value from a given type and calendar field value.

Parameters:
type - calendar type
field - calendar field

CalendarData

public CalendarData(DateFormatType type,
                    CalendarField field1,
                    CalendarField field2)
Creates a calendar data value from a given type and calendar field value.

Parameters:
type - calendar type
field1 - calendar field
field2 - calendar field

CalendarData

public CalendarData(DateFormatType type,
                    java.lang.String stringValue,
                    java.text.ParsePosition status)
             throws InvalidDataException
Creates a calendar data value from a string value.

Parameters:
stringValue - string value to be parsed
status - parse status (may be null)
Throws:
InvalidDataException - if string value could not be parser
See Also:
TimestampData.setValue(String,ParsePosition), DateFormatType.dateValue(String,ParsePosition)

CalendarData

public CalendarData(DateFormatType type,
                    java.util.Calendar calendar)
Creates a calendar data value from a given type and calendar value.

Parameters:
type - calendar type
calendar - calendar

CalendarData

public CalendarData(DateFormatType type,
                    CalendarData calendarData)
Creates a calendar data value from a given type and calendar value.

Parameters:
type - calendar type
calendarData - calendar data

CalendarData

public CalendarData(DateFormatType type,
                    CalendarFieldData cfd)
Creates a calendar data value from a given type and calendar value.

Parameters:
type - calendar type
cfd - calendar field data
See Also:
DateFormatType.createCalendar(CalendarField)

CalendarData

public CalendarData(DateFormatType type,
                    java.util.Date date)
Creates a calendar data value from a given type and date.

Parameters:
type - calendar type
date - date

CalendarData

public CalendarData(DateFormatType type,
                    long milliseconds)
Creates a calendar data value from a given type and date.

Parameters:
type - timestamp type
milliseconds - milliseconds value
Method Detail

add

public void add(int field,
                int amount)
Adds given amount of time to current calendar value. If the new field value under- or overflows, other fields are affected also.

Parameters:
field - the time field
amount - the amount of date or time to be added to the field

get

public int get(int field)
Gets the value for a given time field.

Parameters:
field - the time field

getActualMaximum

public int getActualMaximum(int field)
Gets the actual maximum value for a given time field, given the current date.

Parameters:
field - the time field

getActualMinimum

public int getActualMinimum(int field)
Gets the actual minimum value for a given time field, given the current date.

Parameters:
field - the time field

getGreatestMinimum

public int getGreatestMinimum(int field)
Gets the greatest minimum value for a given time field.

Parameters:
field - the time field

getLeastMaximum

public int getLeastMaximum(int field)
Gets the least maximum value for a given time field.

Parameters:
field - the time field

getMaximum

public int getMaximum(int field)
Gets the maximum value for a given time field, given the current date.

Parameters:
field - the time field

getMinimum

public int getMinimum(int field)
Gets the minimum value for a given time field, given the current date.

Parameters:
field - the time field

roll

public void roll(int field,
                 int amount)
Rolls given field a given amount of time. If the new field value under- or overflows, other fields are not affected.

Parameters:
field - the time field
amount - the amount of date or time to be added to the field

setTimeZone

public void setTimeZone(java.util.TimeZone value)
Sets calendar time zone.

Parameters:
value - the new time zone.

isNull

public boolean isNull()
Tests if this data object value is undetermined.

Specified by:
isNull in interface SerializableData
Overrides:
isNull in class TimestampData

setTime

public void setTime(long time)
Sets the duration of this calendar date in milliseconds. This sets the current date value, as well as the calendar value.


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 TimestampData

getCalendar

public java.util.Calendar getCalendar()
Gets a reference to the underlying calendar object. Modifications made to the calendar will not automatically reflect back to the current date value. To update the date value safely, use setTime(long).


ceil

public DataValue ceil(java.util.Date precision)
               throws InvalidDataException
Quantizes the current value up to an even value within given date precision. The returned value is more than or equal with the current value, but not more than the current value added by given precision.

Overrides:
ceil in class TimestampData
Parameters:
precision - the precision within quantization occurs
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if precision was of unacceptable type
See Also:
TimestampData.ceil(DataValue), floor(java.util.Date)

createCalendar

public java.util.Calendar createCalendar()
Creates a new calendar set to the moment of time this object currently represents.

Overrides:
createCalendar in class TimestampData

floor

public DataValue floor(java.util.Date precision)
                throws InvalidDataException
Quantizes the current value down to an even value within given precision. The returned value is more than or equal with the current value, but not more than the current value added by given precision.

Overrides:
floor in class TimestampData
Parameters:
precision - the precision within quantization occurs
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if precision was of unacceptable type
See Also:
ceil(java.util.Date), TimestampData.floor(DataValue)


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