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

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

Introduction

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

Prototype

public Object pop() throws EmptyStackException 

Source Link

Document

Pops the top item off of this stack and return it.

Usage

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

/**
 * Retrieves whether there're more nodes to visit.
 * @param start the start node.//from w ww.  ja  va2  s  .  c om
 * @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   w w  w .jav a2 s .co m*/
 * @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;
}

From source file:org.apache.cocoon.el.impl.objectmodel.ObjectModelImpl.java

public void cleanupLocalContext() {
    if (localContexts.empty()) {
        throw new IllegalStateException("Local contexts stack is empty");
    }//from  w ww . j av  a  2s  . c  o m

    ArrayStack removeEntries = (ArrayStack) localContexts.pop();
    while (!removeEntries.isEmpty()) {
        if (removeEntries.peek() instanceof PathValue) {
            PathValue entry = (PathValue) removeEntries.pop();
            removeAt(entry.getPath(), entry.getValue());
        } else {
            KeyValue entry = (KeyValue) removeEntries.pop();
            Object key = entry.getKey();
            Object value = entry.getValue();

            multiValueMap.remove(key, value);
            if (multiValueMap.containsKey(key)) {
                singleValueMap.put(key, ((StackReversedIteration) multiValueMap.get(key)).peek());
            } else {
                singleValueMap.remove(key);
            }
        }
    }
}

From source file:org.apache.jmeter.services.FileServer.java

/**
 * Calculates the relative path from {@link #DEFAULT_BASE} to the current base,
 * which must be the same as or a child of the default.
 * /*from   w  w w. j a  v  a  2s  .co  m*/
 * @return the relative path, or {@code "."} if the path cannot be determined
 */
public synchronized File getBaseDirRelative() {
    // Must first convert to absolute path names to ensure parents are available
    File parent = new File(DEFAULT_BASE).getAbsoluteFile();
    File f = base.getAbsoluteFile();
    ArrayStack l = new ArrayStack();
    while (f != null) {
        if (f.equals(parent)) {
            if (l.isEmpty()) {
                break;
            }
            File rel = new File((String) l.pop());
            while (!l.isEmpty()) {
                rel = new File(rel, (String) l.pop());
            }
            return rel;
        }
        l.push(f.getName());
        f = f.getParentFile();
    }
    return new File(".");
}