summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/DeepEnumeration.java
blob: 060d71e8ef99e0265e2a7bfd91ce8dd20a8945ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package NET.worlds.scape;

import java.util.Enumeration;
import java.util.Vector;

public class DeepEnumeration<K> implements Enumeration<K> {
   Vector<SuperRoot> roots = new Vector<SuperRoot>();
   Vector<Vector<K>> vectors = new Vector<Vector<K>>();
   Vector<K> currentVector = null;
   int currentIndex = -1;
   SuperRoot nextValue = null;
   protected boolean valueRetrieved = true;

   public DeepEnumeration(SuperRoot o) {
      this.addChildElement(o);
   }

   public DeepEnumeration(Vector<K> v) {
      this.addChildVector(v);
   }

   public DeepEnumeration(Enumeration<K> e) {
      this.addChildEnumeration(e);
   }

   public DeepEnumeration() {
   }

   @Override
   public boolean hasMoreElements() {
      if (this.valueRetrieved) {
         this.getNextElement();
      }

      return this.nextValue != null;
   }

   @Override
   public K nextElement() {
      if (this.valueRetrieved) {
         this.getNextElement();
      }

      this.valueRetrieved = true;
      return (K)this.nextValue;
   }

   protected void getNextElement() {
      this.valueRetrieved = false;
      if (!this.roots.isEmpty()) {
         this.nextValue = this.roots.elementAt(this.roots.size() - 1);
         this.roots.removeElementAt(this.roots.size() - 1);

         assert this.nextValue != null;

         this.nextValue.getChildren(this);
      } else if (this.currentIndex >= 0) {
         try {
            this.nextValue = (SuperRoot)this.currentVector.elementAt(this.currentIndex--);
         } catch (ArrayIndexOutOfBoundsException var2) {
            this.currentIndex = this.currentVector.size() - 1;
            this.getNextElement();
         }

         assert this.nextValue != null;

         this.nextValue.getChildren(this);
      } else if (!this.vectors.isEmpty()) {
         this.currentVector = this.vectors.elementAt(this.vectors.size() - 1);
         this.currentIndex = this.currentVector.size() - 1;
         this.vectors.removeElementAt(this.vectors.size() - 1);
         this.getNextElement();
      } else {
         this.nextValue = null;
      }
   }

   public void addChildVector(Vector<K> eventHandlers) {
      assert eventHandlers != null;

      this.vectors.addElement(eventHandlers);
   }

   public void addChildEnumeration(Enumeration<K> e) {
      assert e != null;

      while (e.hasMoreElements()) {
         this.addChildElement(e.nextElement());
      }
   }

   public void addChildVectorWithNulls(Vector<K> v) {
      assert v != null;

      for (int i = v.size() - 1; i >= 0; i--) {
         Object obj = v.elementAt(i--);
         if (obj != null) {
            this.addChildElement(obj);
         }
      }
   }

   public void addChildElement(Object o) {
      assert o != null;

      this.roots.addElement((SuperRoot)o);
   }

   public void addChildVectorAction(Vector<K> actions) {
      assert actions != null;

      this.vectors.addElement(actions);
   }
}