home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / main / tsoltimes.java < prev   
Encoding:
Java Source  |  1996-08-14  |  1002 b   |  51 lines

  1. // TsolTimes.java
  2. // 22.03.96
  3. //
  4. // a liste of metro times
  5.  
  6. package cybcerone.main;
  7.  
  8. import java.util.Vector;
  9. import java.util.Enumeration;
  10.  
  11. import cybcerone.utils.Date;
  12.  
  13. /**
  14.  * A group of TsolTime objects, and a means of finding the next one.
  15.  */
  16. class TsolTimes {
  17.   private Vector times;
  18.  
  19.   /* to speed up the getNext method */
  20.   private TsolTime next;
  21.  
  22.   public TsolTimes (Vector theTimes) {
  23.     times = theTimes;
  24.   }
  25.  
  26.   public TsolTime getNext (TsolTime theTime) {
  27.     if (times != null && times.size () > 0) {
  28.       next = (TsolTime)times.firstElement ();
  29.       while (theTime.after (next) && times.size () > 0) {
  30.     times.removeElementAt (0);
  31.     if (times.size () > 0)
  32.       next = (TsolTime)times.firstElement ();
  33.       }
  34.       if (theTime.after (next))
  35.     return null;
  36.       else
  37.     return next;
  38.     }
  39.     return null;
  40.   }
  41.  
  42.   public TsolTime getNext (Date theDate) {
  43.     return getNext (new TsolTime (theDate));
  44.   }
  45.  
  46.   /** How many times are left */
  47.   public int size () {
  48.     return times.size ();
  49.   }
  50. }
  51.