FileDocCategorySizeDatePackage
MonthYear.javaAPI DocExample2214Sun Sep 02 14:59:06 BST 2001com.oreilly.forum.domain

MonthYear

public class MonthYear extends Object implements Comparable, Serializable
Represents a month and a year.

Fields Summary
private int
month
private int
year
Constructors Summary
public MonthYear()
Construct a new object representing the current instant in time.

        this(new Date());
    
public MonthYear(Date date)
Construct a new object with the given date.

        this(DateUtil.getMonth(date), DateUtil.getYear(date));
    
public MonthYear(int month, int year)
Construct a new object with the given month and year.

param
month a zero-based month, just like java.util.Calendar.

        this.month = month;
        this.year = year;
    
Methods Summary
public intcompareTo(java.lang.Object obj)
Compare this MonthYear object to another.

        MonthYear rhs = (MonthYear) obj;
        // first compare year
        if (this.year < rhs.year) {
            return -1;
        } else if (this.year > rhs.year) {
            return 1;
        }
        // then month
        if (this.month < rhs.month) {
            return -1;
        } else if (this.month > rhs.month) {
            return 1;
        }

        return 0;
    
public booleancontainsInMonth(DayMonthYear date)

return
true if the specified date occurs sometime during this month.

        return date.getMonth() == this.month
                && date.getYear() == this.year;
    
public booleanequals(java.lang.Object obj)

        if (obj instanceof MonthYear) {
            MonthYear rhs = (MonthYear) obj;
            return this.month == rhs.month
                    && this.year == rhs.year;
        }
        return false;
    
public intgetMonth()

return
the month number, starting with 0 for January.

        return this.month;
    
public intgetYear()

return
the year number.

        return this.year;
    
public inthashCode()

        return this.month ^ this.year;