package NET.worlds.scape; import java.util.Enumeration; import java.util.Vector; public class DeepEnumeration implements Enumeration { Vector roots = new Vector(); Vector> vectors = new Vector>(); Vector currentVector = null; int currentIndex = -1; SuperRoot nextValue = null; protected boolean valueRetrieved = true; public DeepEnumeration(SuperRoot o) { this.addChildElement(o); } public DeepEnumeration(Vector v) { this.addChildVector(v); } public DeepEnumeration(Enumeration 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 eventHandlers) { assert eventHandlers != null; this.vectors.addElement(eventHandlers); } public void addChildEnumeration(Enumeration e) { assert e != null; while (e.hasMoreElements()) { this.addChildElement(e.nextElement()); } } public void addChildVectorWithNulls(Vector 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 actions) { assert actions != null; this.vectors.addElement(actions); } }