home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / manif / interval.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.3 KB  |  108 lines

  1. // Interval.java
  2. // 14.03.96
  3. //
  4. // class to represent the possible viewing intervals for manifestations
  5.  
  6. package cybcerone.manif;
  7.  
  8. import cybcerone.utils.Date;
  9. import cybcerone.utils.Manif;
  10.  
  11. /** 
  12.  * Manif's (events) can be taking place either today, this week, in the
  13.  * following weeks.  This is an easy way of categorizing for searching.
  14.  */
  15. class Interval {
  16.   static final int TODAY     = 0;
  17.   static final int THISWEEK  = 1;
  18.   static final int NEXTWEEKS = 2;
  19.   static final int ALL       = 3;
  20.  
  21.   private int code;
  22.   private Date now = new Date ();
  23.  
  24.   private Date currentDate = new Date (now.getYear (),
  25.                        now.getMonth (),
  26.                        now.getDate ());
  27.  
  28.   private Date nextWeekDate = new Date (currentDate.getYear (),
  29.                     currentDate.getMonth (),
  30.                     currentDate.getDate () + 8);
  31.   
  32.   Interval (int code) {
  33.     this.code = code;
  34.   }
  35.  
  36.   public int getInterval () { return code; }
  37.  
  38.  
  39.   /** Returns true if the interval includes this event */
  40.   boolean includes (Manif theManif) {
  41.     switch (code) {
  42.     case TODAY:
  43.       return theManif.sameDay (currentDate);
  44.     case THISWEEK:
  45.       return theManif.between (currentDate, nextWeekDate);
  46.     case NEXTWEEKS:
  47.       return theManif.onOrAfter (nextWeekDate);
  48.     case ALL:
  49.       return true;
  50.     default:
  51.       return false;
  52.     }
  53.   }
  54.  
  55.   /** Returns true if the interval comes before this event */
  56.   boolean before (Manif theManif) {
  57.     Date eventDate = theManif.getStartDate ();
  58.  
  59.     switch (code) {
  60.     case TODAY:
  61.       return (currentDate.before (eventDate));
  62.     case THISWEEK:
  63.       return (nextWeekDate.before (eventDate));
  64.     default:
  65.       return false;
  66.     }
  67.   }
  68.  
  69.   /** Returns true if the interval comes after this event */
  70.   boolean after (Manif theManif) {
  71.     Date eventDate = theManif.getStartDate ();
  72.  
  73.     switch (code) {
  74.     case TODAY:
  75.     case THISWEEK:
  76.       return (currentDate.after (eventDate));
  77.     case NEXTWEEKS:
  78.       return (nextWeekDate.after (eventDate));
  79.     default:
  80.       return false;
  81.     }
  82.   }
  83.  
  84.  
  85.   public String toString () {
  86.     String theCode;
  87.  
  88.     switch (code) {
  89.     case TODAY:
  90.       theCode = "TODAY";
  91.       break;
  92.     case THISWEEK:
  93.       theCode = "THISWEEK";
  94.       break;
  95.     case NEXTWEEKS:
  96.       theCode = "NEXTWEEKS";
  97.       break;
  98.     case ALL:
  99.       theCode = "ALL";
  100.       break;
  101.     default:
  102.       theCode = "UNKNOWN";
  103.     }
  104.  
  105.     return ("Interval[" + theCode + "]");
  106.   }
  107. }
  108.