org.jfree.data.time
Class RegularTimePeriod

java.lang.Object
  extended byorg.jfree.data.time.RegularTimePeriod
All Implemented Interfaces:
java.lang.Comparable, TimePeriod
Direct Known Subclasses:
Day, FixedMillisecond, Hour, Millisecond, Minute, Month, Quarter, Second, Week, Year

public abstract class RegularTimePeriod
extends java.lang.Object
implements TimePeriod, java.lang.Comparable

An abstract class representing a unit of time.

Convenient methods are provided for calculating the next and previous time periods.

Conversion methods are defined that return the first and last milliseconds of the time period. The results from these methods are timezone dependent.

This class is immutable, and all subclasses should be immutable also.


Field Summary
static java.util.TimeZone DEFAULT_TIME_ZONE
          The default time zone.
static java.util.Calendar WORKING_CALENDAR
          A working calendar (recycle to avoid unnecessary object creation).
 
Constructor Summary
RegularTimePeriod()
           
 
Method Summary
static RegularTimePeriod createInstance(java.lang.Class c, java.util.Date millisecond, java.util.TimeZone zone)
          Creates a time period that includes the specified millisecond, assuming the given time zone.
static java.lang.Class downsize(java.lang.Class c)
          Returns a subclass of RegularTimePeriod that is smaller than the specified class.
 java.util.Date getEnd()
          Returns the date/time that marks the end of the time period.
 long getFirstMillisecond()
          Returns the first millisecond of the time period, evaluated in the default time zone.
abstract  long getFirstMillisecond(java.util.Calendar calendar)
          Returns the first millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).
 long getFirstMillisecond(java.util.TimeZone zone)
          Returns the first millisecond of the time period, evaluated within a specific time zone.
 long getLastMillisecond()
          Returns the last millisecond of the time period, evaluated in the default time zone.
abstract  long getLastMillisecond(java.util.Calendar calendar)
          Returns the last millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).
 long getLastMillisecond(java.util.TimeZone zone)
          Returns the last millisecond of the time period, evaluated within a specific time zone.
 long getMiddleMillisecond()
          Returns the millisecond closest to the middle of the time period, evaluated in the default time zone.
 long getMiddleMillisecond(java.util.Calendar calendar)
          Returns the millisecond closest to the middle of the time period, evaluated using the supplied calendar (which incorporates a timezone).
 long getMiddleMillisecond(java.util.TimeZone zone)
          Returns the millisecond closest to the middle of the time period, evaluated within a specific time zone.
abstract  long getSerialIndex()
          Returns a serial index number for the time unit.
 java.util.Date getStart()
          Returns the date/time that marks the start of the time period.
abstract  RegularTimePeriod next()
          Returns the time period following this one, or null if some limit has been reached.
abstract  RegularTimePeriod previous()
          Returns the time period preceding this one, or null if some lower limit has been reached.
 java.lang.String toString()
          Returns a string representation of the time period.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

DEFAULT_TIME_ZONE

public static final java.util.TimeZone DEFAULT_TIME_ZONE
The default time zone.


WORKING_CALENDAR

public static final java.util.Calendar WORKING_CALENDAR
A working calendar (recycle to avoid unnecessary object creation).

Constructor Detail

RegularTimePeriod

public RegularTimePeriod()
Method Detail

createInstance

public static RegularTimePeriod createInstance(java.lang.Class c,
                                               java.util.Date millisecond,
                                               java.util.TimeZone zone)
Creates a time period that includes the specified millisecond, assuming the given time zone.

Parameters:
c - the time period class.
millisecond - the time.
zone - the time zone.
Returns:
The time period.

downsize

public static java.lang.Class downsize(java.lang.Class c)
Returns a subclass of RegularTimePeriod that is smaller than the specified class.

Parameters:
c - a subclass of RegularTimePeriod.
Returns:
A class.

previous

public abstract RegularTimePeriod previous()
Returns the time period preceding this one, or null if some lower limit has been reached.

Returns:
The previous time period (possibly null).

next

public abstract RegularTimePeriod next()
Returns the time period following this one, or null if some limit has been reached.

Returns:
The next time period (possibly null).

getSerialIndex

public abstract long getSerialIndex()
Returns a serial index number for the time unit.

Returns:
The serial index number.

getStart

public java.util.Date getStart()
Returns the date/time that marks the start of the time period.

Specified by:
getStart in interface TimePeriod
Returns:
The start date/time.

getEnd

public java.util.Date getEnd()
Returns the date/time that marks the end of the time period.

Specified by:
getEnd in interface TimePeriod
Returns:
The end date/time.

getFirstMillisecond

public long getFirstMillisecond()
Returns the first millisecond of the time period, evaluated in the default time zone.

Returns:
The first millisecond of the time period.

getFirstMillisecond

public long getFirstMillisecond(java.util.TimeZone zone)
Returns the first millisecond of the time period, evaluated within a specific time zone.

Parameters:
zone - the time zone.
Returns:
The first millisecond of the time period.

getFirstMillisecond

public abstract long getFirstMillisecond(java.util.Calendar calendar)
Returns the first millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).

Parameters:
calendar - the calendar.
Returns:
The first millisecond of the time period.

getLastMillisecond

public long getLastMillisecond()
Returns the last millisecond of the time period, evaluated in the default time zone.

Returns:
The last millisecond of the time period.

getLastMillisecond

public long getLastMillisecond(java.util.TimeZone zone)
Returns the last millisecond of the time period, evaluated within a specific time zone.

Parameters:
zone - the time zone.
Returns:
The last millisecond of the time period.

getLastMillisecond

public abstract long getLastMillisecond(java.util.Calendar calendar)
Returns the last millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).

Parameters:
calendar - the calendar.
Returns:
The last millisecond of the time period.

getMiddleMillisecond

public long getMiddleMillisecond()
Returns the millisecond closest to the middle of the time period, evaluated in the default time zone.

Returns:
The middle millisecond.

getMiddleMillisecond

public long getMiddleMillisecond(java.util.TimeZone zone)
Returns the millisecond closest to the middle of the time period, evaluated within a specific time zone.

Parameters:
zone - the time zone.
Returns:
The middle millisecond.

getMiddleMillisecond

public long getMiddleMillisecond(java.util.Calendar calendar)
Returns the millisecond closest to the middle of the time period, evaluated using the supplied calendar (which incorporates a timezone).

Parameters:
calendar - the calendar.
Returns:
The middle millisecond.

toString

public java.lang.String toString()
Returns a string representation of the time period.

Returns:
The string.