home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / applets / collectn / incrcoll.jav < prev    next >
Encoding:
Text File  |  1995-12-14  |  2.1 KB  |  88 lines

  1. /*
  2.   File: IncrCollectionEnumeration.java
  3.  
  4.   Originally written by Doug Lea and released into the public domain. 
  5.   Thanks for the assistance and support of Sun Microsystems Labs, Agorics 
  6.   Inc, Loral, and everyone contributing, testing, and using this code.
  7.  
  8.   History:
  9.   Date     Who                What
  10.   13Oct    dl@cs.oswego.edu   Create.
  11.  
  12. */
  13.   
  14. package collections;
  15.  
  16. import java.util.Enumeration;
  17. import java.util.NoSuchElementException;
  18.  
  19. /**
  20.  *
  21.  *
  22.  * Enumerator for IncrCollections
  23.  * @author Doug Lea
  24.  * @version 0.93
  25.  *
  26.  * <P> For an introduction to this package see <A HREF="index.html"> Overview </A>.
  27. **/
  28.  
  29. public final class IncrCollectionEnumeration implements CollectionEnumeration {
  30.   private IncrImpl owner_;
  31.   private CollectionEnumeration enum_;
  32.  
  33. /**
  34.  * Wrap the enumeration e created by o in an Incr version
  35. **/
  36.  
  37.   IncrCollectionEnumeration(IncrImpl o, CollectionEnumeration e) {
  38.     owner_ = o; enum_ = e;
  39.   }
  40.  
  41.  
  42. /**
  43.  * Implements java.util.Enumeration.hasMoreElements.
  44.  * @see java.util.Enumeration#hasMoreElements
  45. **/
  46.   public synchronized boolean hasMoreElements() {
  47.     // call back owner_ if exhausted
  48.     boolean has = enum_.hasMoreElements();
  49.     if (!has) owner_.unpin(this);
  50.     return has;
  51.   }
  52.  
  53. /**
  54.  * Implements collections.CollectionEnumeration.numberOfRemainingElements
  55.  * @see collections.CollectionEnumeration#numberOfRemainingElements
  56. **/
  57.   public synchronized int numberOfRemainingElements() {
  58.     return enum_.numberOfRemainingElements();
  59.   }
  60.  
  61. /**
  62.  * Implements java.util.Enumeration.nextElement().
  63.  * @see java.util.Enumeration#nextElement()
  64. **/
  65.   public synchronized Object nextElement() {
  66.     return enum_.nextElement();
  67.   }
  68.  
  69. /**
  70.  * Implements collections.CollectionEnumeration.corrupted.
  71.  * Should always return false unless underlying collection
  72.  * that has been wrapped in Incr version has been independently
  73.  * modified.
  74.  * @return false
  75.  * @see collections.CollectionEnumeration#corrupted
  76. **/
  77.   public synchronized boolean corrupted() {
  78.     return enum_.corrupted(); 
  79.   }
  80.  
  81.  
  82. /**
  83.  * IncrCollectionEnumerations are NOT copyable!
  84. **/
  85.  
  86. }
  87.  
  88.