caltool.schedule
Class Date

java.lang.Object
  extended by java.util.Observable
      extended by mvp.Model
          extended by caltool.schedule.Date
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class Date
extends mvp.Model
implements java.lang.Comparable

Class Date is the basic unit of calendar time keeping, consisting of a day of the week, numeric date, month, and year.

See Also:
Serialized Form

Field Summary
protected  DayName day
          One of the seven standard days of the week
protected  java.util.Date jDate
          The java.util.Date value that represents this' date.
protected  MonthName month
          One of the twelve months of the year
protected  int number
          Numeric date in a month, between 1 and 31
protected  boolean valid
          True if this is a valud date
protected  int year
          The four-digit year number.
 
Fields inherited from class mvp.Model
view
 
Constructor Summary
Date()
          Construct an empty Date.
Date(DayName day, int number, MonthName month, int year)
          Construct a date from the given field values.
Date(java.lang.String dateString)
          Construct a date from the given string.
 
Method Summary
 int compareTo(java.lang.Object o)
          Define compareTo using java.util.Calendar.
protected  void constructJCalendarIfNecessary()
          Construct the static java.util.format and Calendar if this is the first time the constructor has been called.
protected  DayName convertJavaDay(int javaDayNum)
          Convert a java.util.Calendar.DAY_OF_WEEK number to a caltool.schedule.DayName enum.
 boolean equals(java.lang.Object obj)
          Define equality for this as componentwise equality.
 int hashCode()
          Define the hash code for this as the sum of the components.
 boolean isEmpty()
          Return true if this is an empty date, indicated by the date number = 0.
 boolean isValid()
          Return true if this is a valid date.
 java.lang.String toString()
          Return the string representation of this.
 
Methods inherited from class mvp.Model
dump, exit, getView, setView
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

day

protected DayName day
One of the seven standard days of the week


number

protected int number
Numeric date in a month, between 1 and 31


month

protected MonthName month
One of the twelve months of the year


year

protected int year
The four-digit year number. (Yes, this Calendar Tool has a Y10K problem.)


valid

protected boolean valid
True if this is a valud date


jDate

protected java.util.Date jDate
The java.util.Date value that represents this' date. In future, this may be the only data rep of this, but for now we keep our own model data fields around as well. At present, the significant use of this date rep is in this.compareTo.

Constructor Detail

Date

public Date()
Construct an empty Date.


Date

public Date(java.lang.String dateString)
Construct a date from the given string. Set the valid field to false if the given string does not parse as a valid date. Note that the invalid state representation is used instead of throwing an exception because some users may want to delay the processing of invalid dates, and hence may not be interested in handling an exception. Use java.text.SimpleDateFormat and java.util.Calendar to do the work. This means that the first time the constructor is invoked, the static format and jCalendar data fields are initialized to new SimpleDateFormat and Calendar objects, resp. These static values are used in all subsequent Date constructions.


Date

public Date(DayName day,
            int number,
            MonthName month,
            int year)
Construct a date from the given field values. See the additional comments in the String-valued constructor.

Method Detail

constructJCalendarIfNecessary

protected void constructJCalendarIfNecessary()
Construct the static java.util.format and Calendar if this is the first time the constructor has been called.


convertJavaDay

protected DayName convertJavaDay(int javaDayNum)
Convert a java.util.Calendar.DAY_OF_WEEK number to a caltool.schedule.DayName enum. This is necessary because JFC does not (necessarily) map the pseudo-enum day name literals to any particular numeric sequence. The last time I checked, Calendar.MONDAY == 2.


isValid

public boolean isValid()
Return true if this is a valid date.


isEmpty

public boolean isEmpty()
Return true if this is an empty date, indicated by the date number = 0.


toString

public java.lang.String toString()
Return the string representation of this.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Define equality for this as componentwise equality.

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Define compareTo using java.util.Calendar. The comparison of invalid dates is defined as follows: (1) invalid < valid; (2) invalid == invalid.

Specified by:
compareTo in interface java.lang.Comparable

hashCode

public int hashCode()
Define the hash code for this as the sum of the components. This hash code is used in turn by ItemKey.hashCode.

Overrides:
hashCode in class java.lang.Object