Class TimePeriod

java.lang.Object
org.jfree.data.time.RegularTimePeriod
net.simplace.ui.jfreechart.TimePeriod
All Implemented Interfaces:
Serializable, Comparable, org.jfree.chart.date.MonthConstants, org.jfree.data.time.TimePeriod

public class TimePeriod extends org.jfree.data.time.RegularTimePeriod implements Serializable
Represents an arbitrary time period between two dates (adapted from the JFreeChart class Year). This class is immutable, which is a requirement for all RegularTimePeriod subclasses.
Author:
Andreas Enders
See Also:
  • Field Summary

    Fields inherited from interface org.jfree.chart.date.MonthConstants

    APRIL, AUGUST, DECEMBER, FEBRUARY, JANUARY, JULY, JUNE, MARCH, MAY, NOVEMBER, OCTOBER, SEPTEMBER
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty period at the current system date/time.
    TimePeriod(Date start, Date end)
    Creates a time period between two dates.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns an integer indicating the order of this period relative to the specified object: time periods are ordered by their first, then by their last millisecond.
    boolean
    Tests the equality of this period to an arbitrary object.
    long
    Returns the first millisecond of the period.
    long
    Returns the first millisecond of the period (independent of the calendar).
    long
    Returns the last millisecond of the period.
    long
    Returns the last millisecond of the period (independent of the calendar).
    long
    Returns a serial index number for the period.
    int
    Returns a hash code for this object instance.
    org.jfree.data.time.RegularTimePeriod
     
    void
    peg(Calendar calendar)
    Recalculates the start date/time and end date/time for this time period relative to the supplied calendar; the period is independent of the time zone, so nothing changes.
    org.jfree.data.time.RegularTimePeriod
    Returns the period of the same length ending at the start of this period.
    Returns a string representing the period.

    Methods inherited from class org.jfree.data.time.RegularTimePeriod

    createInstance, downsize, getCalendarInstance, getEnd, getMiddleMillisecond, getMiddleMillisecond, getMillisecond, getStart, setCalendarInstancePrototype, setThreadLocalCalendarInstance

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TimePeriod

      public TimePeriod()
      Creates an empty period at the current system date/time.
    • TimePeriod

      public TimePeriod(Date start, Date end)
      Creates a time period between two dates.
      Parameters:
      start - the start of the period
      end - the end of the period
  • Method Details

    • getFirstMillisecond

      public long getFirstMillisecond()
      Returns the first millisecond of the period.
      Specified by:
      getFirstMillisecond in class org.jfree.data.time.RegularTimePeriod
      Returns:
      The first millisecond of the period.
      See Also:
    • getLastMillisecond

      public long getLastMillisecond()
      Returns the last millisecond of the period.
      Specified by:
      getLastMillisecond in class org.jfree.data.time.RegularTimePeriod
      Returns:
      The last millisecond of the period.
      See Also:
    • peg

      public void peg(Calendar calendar)
      Recalculates the start date/time and end date/time for this time period relative to the supplied calendar; the period is independent of the time zone, so nothing changes.
      Specified by:
      peg in class org.jfree.data.time.RegularTimePeriod
      Parameters:
      calendar - the calendar (not used).
    • getSerialIndex

      public long getSerialIndex()
      Returns a serial index number for the period.

      The implementation simply returns the start time in seconds.

      Specified by:
      getSerialIndex in class org.jfree.data.time.RegularTimePeriod
      Returns:
      The serial index number.
    • getFirstMillisecond

      public long getFirstMillisecond(Calendar calendar)
      Returns the first millisecond of the period (independent of the calendar).
      Specified by:
      getFirstMillisecond in class org.jfree.data.time.RegularTimePeriod
      Parameters:
      calendar - the calendar (not used).
      Returns:
      The first millisecond of the period.
    • getLastMillisecond

      public long getLastMillisecond(Calendar calendar)
      Returns the last millisecond of the period (independent of the calendar).
      Specified by:
      getLastMillisecond in class org.jfree.data.time.RegularTimePeriod
      Parameters:
      calendar - the calendar (not used).
      Returns:
      The last millisecond of the period.
    • equals

      public boolean equals(Object obj)
      Tests the equality of this period to an arbitrary object.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object (null permitted).
      Returns:
      true if the object is a TimePeriod with the same start and end.
    • hashCode

      public int hashCode()
      Returns a hash code for this object instance. The approach described by Joshua Bloch in "Effective Java" has been used here:

      http://developer.java.sun.com/developer/Books/effectivejava /Chapter3.pdf

      Overrides:
      hashCode in class Object
      Returns:
      A hash code.
    • compareTo

      public int compareTo(Object o1)
      Returns an integer indicating the order of this period relative to the specified object: time periods are ordered by their first, then by their last millisecond.
      Specified by:
      compareTo in interface Comparable
      Parameters:
      o1 - the object to compare.
      Returns:
      negative, zero or positive if this period is before, equal to or after the given period; 1 (after) for objects that are no time periods
    • toString

      public String toString()
      Returns a string representing the period.
      Overrides:
      toString in class org.jfree.data.time.RegularTimePeriod
      Returns:
      start and end as MM-yyyy - MM-yyyy.
    • previous

      public org.jfree.data.time.RegularTimePeriod previous()
      Returns the period of the same length ending at the start of this period.
      Specified by:
      previous in class org.jfree.data.time.RegularTimePeriod
      Returns:
      the previous period
    • next

      public org.jfree.data.time.RegularTimePeriod next()
      Specified by:
      next in class org.jfree.data.time.RegularTimePeriod
      Returns:
      the period of the same length starting at the end of this period