org.hackystat.utilities.time.period
Class Month

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

public class Month
extends java.lang.Object
implements TimePeriod

Provides the Month abstract data type, which represents the collection of Week and Day instances in a given month. The Calendar is forced to Locale.US to ensure constant week boundaries.

Author:
Hongbing Kou

Constructor Summary
Month(int year, int month)
          Creates a Month instance for the given year and month.
Month(javax.xml.datatype.XMLGregorianCalendar xmlDay)
          Returns the Month instance corresponding to the passed XMLGregorianCalendar instance.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares two Month instances.
 Month dec()
          Returns the Month instance prior to this Month.
 boolean equals(java.lang.Object obj)
          Returns true if the passed object is a month and is equal to this Month.
 java.util.List<Day> getDays()
          Returns a list of Day instances from the first Day to the last Day in this Month.
 Day getFirstDay()
          Returns the first Day instance associated with this Month.
 Week getFirstWeekInMonth()
          Returns the Week instance associated with the first day in this Month.
 Day getLastDay()
          Returns the last Day instance associated with this Month.
 Week getLastWeekInMonth()
          Returns the Week instance associated with the last Day of this Month.
 int getMonth()
          Returns the zero-based month associated with this Month.
 int getNumOfDays()
          Returns the number of days in this Month.
 int getYear()
          Returns the year associated with this Month.
 int hashCode()
          Hash code of this Month.
 Month inc()
          Returns the Month instance after this Month.
 java.lang.String toString()
          String representation of this Month.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Month

public Month(int year,
             int month)
Creates a Month instance for the given year and month.

Parameters:
year - The calendar year, such as 2004.
month - The zero-based calendar month, such as 0 (January) or 11 (December).

Month

public Month(javax.xml.datatype.XMLGregorianCalendar xmlDay)
Returns the Month instance corresponding to the passed XMLGregorianCalendar instance.

Parameters:
xmlDay - The XMLGregorianCalendar date.
Method Detail

getYear

public int getYear()
Returns the year associated with this Month.

Returns:
The year, such as 2004.

getMonth

public int getMonth()
Returns the zero-based month associated with this Month.

Returns:
The month, such as 0 (January) or 11 (December).

getFirstDay

public Day getFirstDay()
Returns the first Day instance associated with this Month.

Specified by:
getFirstDay in interface TimePeriod
Returns:
First Day of this Month.

getFirstWeekInMonth

public Week getFirstWeekInMonth()
Returns the Week instance associated with the first day in this Month. Note that the Week instance may include Day instances from the prior Month.

Returns:
The Week instance that includes the first Day of this Month.

getLastDay

public Day getLastDay()
Returns the last Day instance associated with this Month.

Returns:
Last day of the month.

getLastWeekInMonth

public Week getLastWeekInMonth()
Returns the Week instance associated with the last Day of this Month. Note that the Week instance may include Day instances from the next Month.

Returns:
Last week in the month.

getNumOfDays

public int getNumOfDays()
Returns the number of days in this Month.

Returns:
Days in this month.

compareTo

public int compareTo(java.lang.Object o)
Compares two Month instances.

Specified by:
compareTo in interface java.lang.Comparable<java.lang.Object>
Parameters:
o - Another month object.
Returns:
Comparison result.

dec

public Month dec()
Returns the Month instance prior to this Month.

Returns:
Previous month.

inc

public Month inc()
Returns the Month instance after this Month.

Returns:
Next month.

hashCode

public int hashCode()
Hash code of this Month.

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

equals

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

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

toString

public java.lang.String toString()
String representation of this Month.

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

getDays

public java.util.List<Day> getDays()
Returns a list of Day instances from the first Day to the last Day in this Month.

Returns:
A sorted list of the Days in this Month.