List of usage examples for org.apache.commons.collections ArrayStack peek
public Object peek() throws EmptyStackException
From source file:org.acmsl.undigester.TreeVisitor.java
/** * Retrieves the next node.// w w w . j a va 2 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 w w . j av a 2 s . com 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); } } } }