home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.3 KB | 108 lines |
- // Interval.java
- // 14.03.96
- //
- // class to represent the possible viewing intervals for manifestations
-
- package cybcerone.manif;
-
- import cybcerone.utils.Date;
- import cybcerone.utils.Manif;
-
- /**
- * Manif's (events) can be taking place either today, this week, in the
- * following weeks. This is an easy way of categorizing for searching.
- */
- class Interval {
- static final int TODAY = 0;
- static final int THISWEEK = 1;
- static final int NEXTWEEKS = 2;
- static final int ALL = 3;
-
- private int code;
- private Date now = new Date ();
-
- private Date currentDate = new Date (now.getYear (),
- now.getMonth (),
- now.getDate ());
-
- private Date nextWeekDate = new Date (currentDate.getYear (),
- currentDate.getMonth (),
- currentDate.getDate () + 8);
-
- Interval (int code) {
- this.code = code;
- }
-
- public int getInterval () { return code; }
-
-
- /** Returns true if the interval includes this event */
- boolean includes (Manif theManif) {
- switch (code) {
- case TODAY:
- return theManif.sameDay (currentDate);
- case THISWEEK:
- return theManif.between (currentDate, nextWeekDate);
- case NEXTWEEKS:
- return theManif.onOrAfter (nextWeekDate);
- case ALL:
- return true;
- default:
- return false;
- }
- }
-
- /** Returns true if the interval comes before this event */
- boolean before (Manif theManif) {
- Date eventDate = theManif.getStartDate ();
-
- switch (code) {
- case TODAY:
- return (currentDate.before (eventDate));
- case THISWEEK:
- return (nextWeekDate.before (eventDate));
- default:
- return false;
- }
- }
-
- /** Returns true if the interval comes after this event */
- boolean after (Manif theManif) {
- Date eventDate = theManif.getStartDate ();
-
- switch (code) {
- case TODAY:
- case THISWEEK:
- return (currentDate.after (eventDate));
- case NEXTWEEKS:
- return (nextWeekDate.after (eventDate));
- default:
- return false;
- }
- }
-
-
- public String toString () {
- String theCode;
-
- switch (code) {
- case TODAY:
- theCode = "TODAY";
- break;
- case THISWEEK:
- theCode = "THISWEEK";
- break;
- case NEXTWEEKS:
- theCode = "NEXTWEEKS";
- break;
- case ALL:
- theCode = "ALL";
- break;
- default:
- theCode = "UNKNOWN";
- }
-
- return ("Interval[" + theCode + "]");
- }
- }
-