org.chronicj
Class TimePoint

java.lang.Object
  |
  +--org.chronicj.TimePoint
All Implemented Interfaces:
java.lang.Comparable

public class TimePoint
extends java.lang.Object
implements java.lang.Comparable

Based directly on the Time Point pattern described by Martin Fowler. This class wraps the standard GregorianCalendarin order to to simplify date precision. Also, some convenience constructors and methods are provided.

Since things will break if a non- GregorianCalendar is supplied, declarations explicitly deal with the concrete class instead of working with the abstract supertype Calendar.

Author:
Matthew Lipper

Constructor Summary
TimePoint(java.util.Date aDate)
          Creates a TimePoint using default DatePrecision.
TimePoint(java.util.Date aDate, org.chronicj.DatePrecision precision)
          Creates a TimePoint using the specified DatePrecision.
TimePoint(java.util.GregorianCalendar arg)
          Delegates call to TimePoint(GregorianCalendar, DatePrecision) using constant TimePoint#DEFAULT_PRECISION.
TimePoint(java.util.GregorianCalendar arg, org.chronicj.DatePrecision precision)
          Creates a TimePoint using specified DatePrecision.
TimePoint(int year, int month)
          Convenience constructor allowing the more natural 1-based-index for specifying month.
TimePoint(int year, int month, int day)
          Convenience constructor allowing the more natural 1-based-index for specifying month.
TimePoint(int year, int month, int day, int hour)
          Convenience constructor allowing the more natural 1-based-index for specifying month.
TimePoint(int year, int month, int day, int hour, int minute)
          Convenience constructor allowing the more natural 1-based-index for specifying month.
 
Method Summary
 org.chronicj.TimePoint addDays(int arg)
          Create a new TimePoint using the current instance plus n days.
 org.chronicj.TimePoint addHours(int arg)
          Create a new TimePoint using the current instance plus n hours.
 org.chronicj.TimePoint addMilliSeconds(int arg)
          Create a new TimePoint using the current instance plus n milliseconds.
 org.chronicj.TimePoint addMinutes(int arg)
          Create a new TimePoint using the current instance plus n minutes.
 org.chronicj.TimePoint addMonths(int arg)
          Create a new TimePoint using the current instance plus n months.
 org.chronicj.TimePoint addSeconds(int arg)
          Create a new TimePoint using the current instance plus n seconds.
 org.chronicj.TimePoint addYears(int arg)
          Create a new TimePoint using the current instance plus n years.
 boolean after(org.chronicj.TimePoint arg)
          Method to see whether this TimePoint instance occurs after another TimePoint instance.
 boolean before(org.chronicj.TimePoint arg)
          Method to see whether this TimePoint instance occurs before another TimePoint instance.
 int compareTo(java.lang.Object arg)
          Compare wrapped GregorianCalendars.
 boolean equals(java.lang.Object arg)
          Compare wrapped GregorianCalendar s for equality
 java.util.GregorianCalendar getCalendar()
          Getter method for the wrapped GregorianCalendar.
 org.chronicj.DatePrecision getDatePrecision()
          Getter method for DatePrecision field.
 int getDayOfMonth()
          Getter for day of the month.
 int getDayOfWeek()
          Getter for day of the week.
 int getHourOfDay()
          Getter for hour of the day (24hr).
 int getMilliSeconds()
          Getter for milliseconds.
 int getMinute()
          Getter for minutes.
 int getMonth()
          Getter for month (not zero-indexed).
 int getSeconds()
          Getter for seconds.
 java.util.Date getTime()
          Convenience getter method for getCalendar()
 int getYear()
          Getter for year.
 int getZeroIndexedMonth()
          Getter returning the wrapped Calendarmonth which is zero-indexed.
 int hashCode()
           
 org.chronicj.TimePoint increment(int amount)
          Increment this TimePoint using the current internal DatePrecisionby the number of units specified.
 org.chronicj.TimePoint minusDays(int arg)
          Create a new TimePoint using the current instance minus n days.
 org.chronicj.TimePoint toPrecison(org.chronicj.DatePrecision precision)
          Create a new TimePoint using this TimePoint current value set to the supplied DatePrecision.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimePoint

public TimePoint(int year,
                 int month,
                 int day)
Convenience constructor allowing the more natural 1-based-index for specifying month. Timezone is ignored.

Parameters:
year - the year
month - the month using 1 to 12, where 1 == January and 12 == DECEMBER. NOTE: java.util.Calendar is zero based, this is not.
day - the day of the month using 1 to 31

TimePoint

public TimePoint(int year,
                 int month)
Convenience constructor allowing the more natural 1-based-index for specifying month. Timezone is ignored.

Parameters:
year - the year
month - the month using 1 to 12, where 1 == January and 12 == DECEMBER. NOTE: java.util.Calendar is zero based, this is not.

TimePoint

public TimePoint(int year,
                 int month,
                 int day,
                 int hour)
Convenience constructor allowing the more natural 1-based-index for specifying month. Timezone is ignored.

Parameters:
year - the year
month - the month using 1 to 12, where 1 == January and 12 == DECEMBER. NOTE: java.util.Calendar is zero based, this is not.
day - the day of the month using 1 to 31
hour - the hour of the day using 0 to 24

TimePoint

public TimePoint(int year,
                 int month,
                 int day,
                 int hour,
                 int minute)
Convenience constructor allowing the more natural 1-based-index for specifying month. Timezone is ignored.

Parameters:
year - the year
month - the month using 1 to 12, where 1 == January and 12 == DECEMBER. NOTE: java.util.Calendar is zero based, this is not.
day - the day of the month using 1 to 31
hour - the hour of the day using 0 to 24
minute - the minute of the hour using 0 to 60

TimePoint

public TimePoint(java.util.GregorianCalendar arg)
Delegates call to TimePoint(GregorianCalendar, DatePrecision) using constant TimePoint#DEFAULT_PRECISION.

Parameters:
arg - the GregorianCalendar which will be set using TimePoint#DEFAULT_PRECISION.

TimePoint

public TimePoint(java.util.Date aDate)
Creates a TimePoint using default DatePrecision.

Parameters:
aDate - the Date which will be set using TimePoint#DEFAULT_PRECISION.

TimePoint

public TimePoint(java.util.Date aDate,
                 org.chronicj.DatePrecision precision)
Creates a TimePoint using the specified DatePrecision.

Parameters:
aDate - the Date to be set
precision - the DatePrecision to use
Throws:
java.lang.NullPointerException - if supplied Date is null

TimePoint

public TimePoint(java.util.GregorianCalendar arg,
                 org.chronicj.DatePrecision precision)
Creates a TimePoint using specified DatePrecision. Timezone information is assumed set or not set by the caller.
NOTE: ATM, GregorianCalendar argument obeys pass by value semantics.

Parameters:
arg - the GregorianCalendar with the requested date value
precision - the DatePrecision to use
Method Detail

getCalendar

public java.util.GregorianCalendar getCalendar()
Getter method for the wrapped GregorianCalendar.

Returns:
the wrapped GregorianCalendar

getDatePrecision

public org.chronicj.DatePrecision getDatePrecision()
Getter method for DatePrecision field.

Returns:
DatePrecision of this TimePoint

getDayOfMonth

public int getDayOfMonth()
Getter for day of the month.

Returns:
int day of the month

getDayOfWeek

public int getDayOfWeek()
Getter for day of the week.

Returns:
int day of the week.

getHourOfDay

public int getHourOfDay()
Getter for hour of the day (24hr).

Returns:
int hour of the day

getMilliSeconds

public int getMilliSeconds()
Getter for milliseconds.

Returns:
int milliseconds

getMinute

public int getMinute()
Getter for minutes.

Returns:
int minutes

getMonth

public int getMonth()
Getter for month (not zero-indexed). Values will be between 1 and 12 for GregorianCalendars.

Returns:
int month

getSeconds

public int getSeconds()
Getter for seconds.

Returns:
int seconds

getTime

public java.util.Date getTime()
Convenience getter method for getCalendar()

Returns:
the wrapped GregorianCalendar as a Date

getYear

public int getYear()
Getter for year.

Returns:
int year

getZeroIndexedMonth

public int getZeroIndexedMonth()
Getter returning the wrapped Calendarmonth which is zero-indexed. Values will be between 0 to 11 (inclusive) for GregorianCalendars.

Returns:
int zero-indexed month

addDays

public org.chronicj.TimePoint addDays(int arg)
Create a new TimePoint using the current instance plus n days. NOTE: the existing instance will not change!

Parameters:
arg - number of days to add
Returns:
a brand new TimePoint

addHours

public org.chronicj.TimePoint addHours(int arg)
Create a new TimePoint using the current instance plus n hours. NOTE: the existing instance will not change!

Parameters:
arg - number of hours to add
Returns:
a brand new TimePoint

addMilliSeconds

public org.chronicj.TimePoint addMilliSeconds(int arg)
Create a new TimePoint using the current instance plus n milliseconds. NOTE: the existing instance will not change!

Parameters:
arg - number of milliseconds to add
Returns:
a brand new TimePoint

addMinutes

public org.chronicj.TimePoint addMinutes(int arg)
Create a new TimePoint using the current instance plus n minutes. NOTE: the existing instance will not change!

Parameters:
arg - number of minutes to add
Returns:
a brand new TimePoint

addMonths

public org.chronicj.TimePoint addMonths(int arg)
Create a new TimePoint using the current instance plus n months. NOTE: the existing instance will not change!

Parameters:
arg - number of months to add
Returns:
a brand new TimePoint

addSeconds

public org.chronicj.TimePoint addSeconds(int arg)
Create a new TimePoint using the current instance plus n seconds. NOTE: the existing instance will not change!

Parameters:
arg - number of seconds to add
Returns:
a brand new TimePoint

addYears

public org.chronicj.TimePoint addYears(int arg)
Create a new TimePoint using the current instance plus n years. NOTE: the existing instance will not change!

Parameters:
arg - number of years to add
Returns:
a brand new TimePoint

after

public boolean after(org.chronicj.TimePoint arg)
Method to see whether this TimePoint instance occurs after another TimePoint instance.

Parameters:
arg - the TimePoint to check
Returns:
true if this TimePoint occurs after the one provided false if this TimePoint occurs before the one provided
Throws:
java.lang.NullPointerException - if argument is null

before

public boolean before(org.chronicj.TimePoint arg)
Method to see whether this TimePoint instance occurs before another TimePoint instance.

Parameters:
arg - the TimePoint to check
Returns:
true if this TimePoint occurs before the one provided false if this TimePoint occurs after the one provided
Throws:
java.lang.NullPointerException - if argument is null

compareTo

public int compareTo(java.lang.Object arg)
Compare wrapped GregorianCalendars.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
arg - Object to compare
Returns:
  • -1 if this TimePoint occurs after the one provided
  • 0 if this TimePoint occurs at the same time as the one provided
  • 1 if this TimePoint occurs before the one provided
See Also:

equals

public boolean equals(java.lang.Object arg)
Compare wrapped GregorianCalendar s for equality

Overrides:
equals in class java.lang.Object
Parameters:
arg - Object to check
Returns:
true if underlying GregorianCalendar instances are equal
See Also:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

increment

public org.chronicj.TimePoint increment(int amount)
Increment this TimePoint using the current internal DatePrecisionby the number of units specified. This is semantically, equivalent to calling Calendar.add(int, int)with the first argument being the current TimePoint's DatePrecsion and the second argument being the supplied positive or negative integer amount.

Parameters:
amount - int number of units to increment by.
Returns:
TimePoint a brand new TimePoint

toPrecison

public org.chronicj.TimePoint toPrecison(org.chronicj.DatePrecision precision)
Create a new TimePoint using this TimePoint current value set to the supplied DatePrecision.

Parameters:
precision - DatePrecision to use when creating the new TimePoint
Returns:
TimePoint a brand new TimePoint

minusDays

public org.chronicj.TimePoint minusDays(int arg)
Create a new TimePoint using the current instance minus n days. NOTE: the existing instance will not change!

Parameters:
arg - number of days to subtract
Returns:
a brand new TimePoint

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2003-2004 Digital Clash Software. All Rights Reserved.