Search in sources :

Example 91 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class GPathResult method breadthFirst.

/**
     * Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.
     *
     * @return the <code>Iterator</code> of (breadth-first) ordered GPathResults
     */
public Iterator breadthFirst() {
    return new Iterator() {

        private final List list = new LinkedList();

        private Iterator iter = iterator();

        private GPathResult next = getNextByBreadth();

        public boolean hasNext() {
            return this.next != null;
        }

        public Object next() {
            try {
                return this.next;
            } finally {
                this.next = getNextByBreadth();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

        private GPathResult getNextByBreadth() {
            List children = new ArrayList();
            while (this.iter.hasNext() || !children.isEmpty()) {
                if (this.iter.hasNext()) {
                    final GPathResult node = (GPathResult) this.iter.next();
                    this.list.add(node);
                    this.list.add(this.iter);
                    children.add(node.children());
                } else {
                    List nextLevel = new ArrayList();
                    for (Object child : children) {
                        GPathResult next = (GPathResult) child;
                        Iterator iterator = next.iterator();
                        while (iterator.hasNext()) {
                            nextLevel.add(iterator.next());
                        }
                    }
                    this.iter = nextLevel.iterator();
                    children = new ArrayList();
                }
            }
            if (this.list.isEmpty()) {
                return null;
            } else {
                GPathResult result = (GPathResult) this.list.get(0);
                this.list.remove(0);
                this.iter = (Iterator) this.list.get(0);
                this.list.remove(0);
                return result;
            }
        }
    };
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GroovyObject(groovy.lang.GroovyObject) LinkedList(java.util.LinkedList)

Example 92 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class GPathResult method depthFirst.

/**
     * Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.
     *
     * @return the <code>Iterator</code> of (depth-first) ordered GPathResults
     */
public Iterator depthFirst() {
    return new Iterator() {

        private final List list = new LinkedList();

        private final Stack stack = new Stack();

        private Iterator iter = iterator();

        private GPathResult next = getNextByDepth();

        public boolean hasNext() {
            return this.next != null;
        }

        public Object next() {
            try {
                return this.next;
            } finally {
                this.next = getNextByDepth();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

        private GPathResult getNextByDepth() {
            while (this.iter.hasNext()) {
                final GPathResult node = (GPathResult) this.iter.next();
                this.list.add(node);
                this.stack.push(this.iter);
                this.iter = node.children().iterator();
            }
            if (this.list.isEmpty()) {
                return null;
            } else {
                GPathResult result = (GPathResult) this.list.get(0);
                this.list.remove(0);
                this.iter = (Iterator) this.stack.pop();
                return result;
            }
        }
    };
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) Stack(java.util.Stack)

Example 93 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class NodeChildren method size.

public synchronized int size() {
    if (this.size == -1) {
        final Iterator iter = iterator();
        this.size = 0;
        while (iter.hasNext()) {
            iter.next();
            this.size++;
        }
    }
    return this.size;
}
Also used : Iterator(java.util.Iterator)

Example 94 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class NodeChildren method replaceNode.

protected void replaceNode(final Closure newValue) {
    final Iterator iter = iterator();
    while (iter.hasNext()) {
        final NodeChild result = (NodeChild) iter.next();
        result.replaceNode(newValue);
    }
}
Also used : Iterator(java.util.Iterator)

Example 95 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class DOMCategory method toString.

private static String toString(NodeList self) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    Iterator it = XmlGroovyMethods.iterator(self);
    while (it.hasNext()) {
        if (sb.length() > 1)
            sb.append(", ");
        sb.append(it.next().toString());
    }
    sb.append("]");
    return sb.toString();
}
Also used : Iterator(java.util.Iterator)

Aggregations

Iterator (java.util.Iterator)8930 ArrayList (java.util.ArrayList)2267 Set (java.util.Set)1895 HashMap (java.util.HashMap)1828 Map (java.util.Map)1714 List (java.util.List)1622 HashSet (java.util.HashSet)1602 Test (org.junit.Test)624 IOException (java.io.IOException)524 Collection (java.util.Collection)377 Region (org.apache.geode.cache.Region)240 SSOException (com.iplanet.sso.SSOException)227 File (java.io.File)216 LinkedList (java.util.LinkedList)213 TreeSet (java.util.TreeSet)191 LinkedHashMap (java.util.LinkedHashMap)181 Entry (java.util.Map.Entry)174 SMSException (com.sun.identity.sm.SMSException)169 ListIterator (java.util.ListIterator)146 TreeMap (java.util.TreeMap)145