home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / NETSCAP4.06 / CP32E406.EXE / netcast.z / ncjava10.jar / netscape / palomar / util / TreeEnumeration.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  1.5 KB  |  49 lines

  1. package netscape.palomar.util;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Stack;
  5.  
  6. public class TreeEnumeration {
  7.    private int _lastLevel;
  8.    private Stack _eStack = new Stack();
  9.  
  10.    public TreeEnumeration(Tree nTop) throws CascadedException {
  11.       if (nTop.numChildren() > 0) {
  12.          this._eStack.push(nTop.getChildren());
  13.       }
  14.  
  15.    }
  16.  
  17.    public synchronized boolean hasMoreElements() {
  18.       while(!this._eStack.empty()) {
  19.          Enumeration t = (Enumeration)this._eStack.peek();
  20.          if (t.hasMoreElements()) {
  21.             return true;
  22.          }
  23.  
  24.          this._eStack.pop();
  25.       }
  26.  
  27.       return false;
  28.    }
  29.  
  30.    public synchronized Object nextElement() throws CascadedException {
  31.       if (this.hasMoreElements()) {
  32.          Enumeration t = (Enumeration)this._eStack.peek();
  33.          Tree p = (Tree)t.nextElement();
  34.          this._lastLevel = this._eStack.size();
  35.          if (p.numChildren() > 0) {
  36.             this._eStack.push(p.getChildren());
  37.          }
  38.  
  39.          return p;
  40.       } else {
  41.          throw new CascadedException(42);
  42.       }
  43.    }
  44.  
  45.    public int getLevelOfElement() {
  46.       return this._lastLevel;
  47.    }
  48. }
  49.