org.hackystat.utilities.time.period
Class Week

java.lang.Object
  extended by org.hackystat.utilities.time.period.Week
All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>, TimePeriod

public class Week
extends java.lang.Object
implements TimePeriod

Provides a representation for seven Day instances where the first Day is always a Sunday and the last Day is always the following Saturday.

The Calendar is forced to Locale.US to ensure constant week boundaries.

Author:
Hongbing Kou

Constructor Summary
Week()
          Create a Week instance that starts on Sunday and ends on Saturday and that includes today.
Week(java.util.Date date)
          Create a Week instance that includes the passed date.
Week(Day day)
          Creates a Week instance that starts on Sunday and ends on Saturday and that includes the passed day.
Week(javax.xml.datatype.XMLGregorianCalendar xmlDay)
          Creates a week instance starting on Sunday and ending on Saturday that includes the passed Day.
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares two Week objects.
 Week dec()
          Returns a new Week instance representing the previous Week.
 boolean equals(java.lang.Object obj)
          Returns true if the passed object is a Week and is equal to this Week.
 java.util.List<Day> getDays()
          Returns a list with the seven Day instances in this Week.
 Day getFirstDay()
          Gets first day of this Week, always a Sunday.
 Day getLastDay()
          Gets the last day of this Week, always a Saturday.
 java.lang.String getWeekRepresentation()
          Returns a String representation of this Week.
 int hashCode()
          Calculate the hashcode for this Week.
 Week inc()
          Returns a new Week instance representing the next Week.
 java.lang.String toString()
          First day of the week is chosen to represent the week in toString().
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Week

public Week()
Create a Week instance that starts on Sunday and ends on Saturday and that includes today.


Week

public Week(java.util.Date date)
Create a Week instance that includes the passed date.

Parameters:
date - The date to be included in the constructed Week.

Week

public Week(Day day)
Creates a Week instance that starts on Sunday and ends on Saturday and that includes the passed day.

Parameters:
day - A day that identifies the Week to be returned.

Week

public Week(javax.xml.datatype.XMLGregorianCalendar xmlDay)
Creates a week instance starting on Sunday and ending on Saturday that includes the passed Day.

Parameters:
xmlDay - The day.
Method Detail

getFirstDay

public Day getFirstDay()
Gets first day of this Week, always a Sunday.

Specified by:
getFirstDay in interface TimePeriod
Returns:
First day of the week.

getLastDay

public Day getLastDay()
Gets the last day of this Week, always a Saturday.

Returns:
Last day of the week.

getDays

public java.util.List<Day> getDays()
Returns a list with the seven Day instances in this Week.

Returns:
A list of the Days in this Week.

hashCode

public int hashCode()
Calculate the hashcode for this Week.

Overrides:
hashCode in class java.lang.Object
Returns:
This Week's hashcode.

equals

public boolean equals(java.lang.Object obj)
Returns true if the passed object is a Week and is equal to this Week.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Any object.
Returns:
True if the two Week instances are the same.

getWeekRepresentation

public java.lang.String getWeekRepresentation()
Returns a String representation of this Week.

Returns:
First day of the week.

toString

public java.lang.String toString()
First day of the week is chosen to represent the week in toString().

Overrides:
toString in class java.lang.Object
Returns:
Week string.

dec

public Week dec()
Returns a new Week instance representing the previous Week.

Returns:
The previous Week.

inc

public Week inc()
Returns a new Week instance representing the next Week.

Returns:
The next Week.

compareTo

public int compareTo(java.lang.Object obj)
Compares two Week objects.

Specified by:
compareTo in interface java.lang.Comparable<java.lang.Object>
Parameters:
obj - Another week object.
Returns:
Comparison of the first day.