Example usage for org.apache.commons.collections ArrayStack size

List of usage examples for org.apache.commons.collections ArrayStack size

Introduction

In this page you can find the example usage for org.apache.commons.collections ArrayStack size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:org.acmsl.undigester.TreeVisitor.java

/**
 * Retrieves whether there're more nodes to visit.
 * @param start the start node./*  ww w.ja  va  2s.  c o  m*/
 * @param current the current node.
 * @param iterator the node iterator.
 * @param subiterators the subiterators.
 * @return such information.
 * @precondition start != null
 */
protected boolean hasMoreNodes(final TreeNode start, final TreeNode current, final Iterator iterator,
        final ArrayStack subiterators) {
    boolean result = false;

    if ((subiterators == null) || (subiterators.size() == 0)) {
        // Browsing a level no deeper than 1.

        if (current == null) {
            setCurrentNode(start);

            result = true;
        } else if (iterator == null) {
            // Starting from the left-most first-level child.
            Collection t_cChildren = start.getChildren();

            result = ((t_cChildren != null) && (t_cChildren.size() > 0));
        } else {
            // Do we have more first-level children?
            result = iterator.hasNext();
        }
    } else {
        // Retrieving the current iterator from the stack.
        Iterator t_Iterator = (Iterator) subiterators.pop();

        result = t_Iterator.hasNext();
    }

    return result;
}

From source file:org.acmsl.undigester.TreeVisitor.java

/**
 * Retrieves the next node.//from  ww w .j  a v  a  2s.c  om
 * @param start the start node.
 * @param current the current node.
 * @param subiterators the subiterators stack.
 * @param iterator the first-level iterator.
 * @return such node.
 * @precondition start != null
 */
protected TreeNode nextNode(final TreeNode start, final TreeNode current, final ArrayStack subiterators,
        final Iterator iterator) {
    TreeNode result = null;

    if ((subiterators == null) || (subiterators.size() == 0)) {
        // Browsing a level no deeper than 1.

        if (current == start) {
            result = start;
        } else {
            Iterator t_Iterator = iterator;

            if (t_Iterator == null) {
                // Starting from the left-most first-level child.
                Collection t_cChildren = start.getChildren();

                if (t_cChildren != null) {
                    t_Iterator = t_cChildren.iterator();

                    setNodeIterator(t_Iterator);
                }
            }

            if ((t_Iterator != null) && (t_Iterator.hasNext())) {
                result = (TreeNode) iterator.next();

                ArrayStack t_asSubiterators = new ArrayStack();
                setSubiterators(t_asSubiterators);

                Collection t_cCollection = result.getChildren();

                if (t_cCollection != null) {
                    t_asSubiterators.push(t_cCollection.iterator());
                }
            }
        }
    } else {
        Iterator t_Iterator = (Iterator) subiterators.peek();

        if (t_Iterator.hasNext()) {
            result = (TreeNode) t_Iterator.next();
        } else {
            // Removing exhausted iterator.
            subiterators.pop();

            // Recursion
            result = nextNode();
        }
    }

    setCurrentNode(result);

    return result;
}