Refine search
private void flushParents(List<Record> willReturn){ Stack<RepeatedRecordInfo> reverseStack = new Stack<>(); while(!stack.isEmpty()){ reverseStack.push(stack.pop()); } while(!reverseStack.isEmpty()){ RepeatedRecordInfo info = reverseStack.pop(); info.timesSeen -= 1; flush(info, willReturn); stack.push(info); } }
private Phrase getNext() { while (!iteratorStack.isEmpty()) { Iterator<Object> iter = iteratorStack.peek(); if (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof Phrase) { return (Phrase) obj; } else if (obj instanceof Map) { iteratorStack.push(((Map) obj).values().iterator()); } else if (obj instanceof List) { iteratorStack.push(((List) obj).iterator()); } else { throw new RuntimeException("Unexpected class in phrase table " + obj.getClass()); } } else { iteratorStack.pop(); } } return null; }
@Override public void initialize() { if (node.equals(IndexedWord.NO_WORD)) { next = null; return; } searchStack = Generics.newArrayList(); for (int i = 0; i <= endDepth; ++i) { searchStack.add(new Stack<>()); } seenNodes = new ArrayList<>(); for (int i = 0; i <= endDepth; ++i) { seenNodes.add(Generics.<IndexedWord>newIdentityHashSet()); } returnedNodes = Generics.newIdentityHashSet(); currentDepth = 1; List<Pair<GrammaticalRelation, IndexedWord>> children = sg.childPairs(node); for (int i = children.size() - 1; i >= 0; i--) { searchStack.get(1).push(children.get(i)); } if (!searchStack.get(1).isEmpty()) { advance(); } }
public <T> List<T> reverse(List<T> list) { /* Algorithm: 1. Maintain a stack 2. Iterate over all the elements in a list and put that on the stack 3. Then empty the stack into a new LinkedList */ Stack<T> stack = new Stack<>(); list.forEach(stack::push); List<T> reversed = new LinkedList<>(); while (!stack.isEmpty()) { reversed.add(stack.pop()); } return reversed; } }
protected void assertLevels( Traverser traverser, Stack<Set<String>> levels ) { Set<String> current = levels.pop(); for ( Path position : traverser ) { String nodeName = (String) position.endNode().getProperty( "name" ); if ( current.isEmpty() ) { current = levels.pop(); } assertTrue( "Should not contain node (" + nodeName + ") at level " + (3 - levels.size()), current.remove( nodeName ) ); } assertTrue( "Should have no more levels", levels.isEmpty() ); assertTrue( "Should be empty", current.isEmpty() ); }
private boolean assertNoMissingParameters(ArgSpec argSpec, Range arity, Stack<String> args) { if (argSpec.interactive()) { return true; } int available = args.size(); if (available > 0 && commandSpec.parser().splitFirst() && argSpec.splitRegex().length() > 0) { available += argSpec.splitValue(args.peek(), commandSpec.parser(), arity, 0).length - 1; } else if (args.isEmpty()) { maybeThrow(new MissingParameterException(CommandLine.this, argSpec, optionDescription("", argSpec, 0) + " requires at least " + arity.min + " values, but none were specified."));
private void assertStateFor(String additionalMatcherName, int subMatchersCount) { if (matcherStack.isEmpty()) { throw reportNoSubMatchersFound(additionalMatcherName); } if (matcherStack.size() < subMatchersCount) { List<LocalizedMatcher> lastMatchers = resetStack(); throw incorrectUseOfAdditionalMatchers(additionalMatcherName, subMatchersCount, lastMatchers); } }
private CmdLineParser bindMethod(List<MethodBinder> binders) { registerOptionHandlers(); CmdLineParser parser = new CmdLineParser(null); // build up the call sequence Stack<Method> chains = new Stack<>(); Method method = m; while (true) { chains.push(method); if (Modifier.isStatic(method.getModifiers())) break; // the chain is complete. // the method in question is an instance method, so we need to resolve the instance by using another resolver Class<?> type = method.getDeclaringClass(); try { method = findResolver(type); } catch (IOException ex) { throw new RuntimeException("Unable to find the resolver method annotated with @CLIResolver for " + type, ex); } if (method == null) { throw new RuntimeException("Unable to find the resolver method annotated with @CLIResolver for " + type); } } while (!chains.isEmpty()) binders.add(new MethodBinder(chains.pop(), this, parser)); return parser; }
@Override public void initialize() { if (node.equals(IndexedWord.NO_WORD)) { next = null; return; } searchStack = Generics.newArrayList(); for (int i = 0; i <= endDepth; ++i) { searchStack.add(new Stack<>()); } seenNodes = new ArrayList<>(); for (int i = 0; i <= endDepth; ++i) { seenNodes.add(Generics.<IndexedWord>newIdentityHashSet()); } returnedNodes = Generics.newIdentityHashSet(); currentDepth = 1; List<Pair<GrammaticalRelation, IndexedWord>> parents = sg.parentPairs(node); for (int i = parents.size() - 1; i >= 0; i--) { searchStack.get(1).push(parents.get(i)); } if (!searchStack.get(1).isEmpty()) { advance(); } }
public boolean isBalancedString(final String input) { /* Algorithm: 1. Iterate over all the characters in a String 2. if stack is not empty and character is ')' then pop the element from the stack 3. else push the element into the stack 4. After iteration if stack is empty then return true else return false. */ Stack<Character> stack = new Stack<>(); char[] chars = input.toCharArray(); for (char ch : chars) { if (ch == ')' && !stack.empty()) { stack.pop(); } else { stack.push(ch); } } return stack.isEmpty(); }
/** * Receive notification of the end of an element. * * <p>The SAX parser will invoke this method at the end of every * element in the XML document; there will be a corresponding * startElement() event for every endElement() event (even when the * element is empty).</p> * * <p>If the element name has a namespace prefix, the prefix will * still be attached to the name.</p> * * * @param ns the namespace of the element * @param localName The local part of the qualified name of the element * @param name The element name */ public void endElement(String ns, String localName, String name) throws org.xml.sax.SAXException { m_elemStack.pop(); m_currentNode = m_elemStack.isEmpty() ? null : (Node)m_elemStack.peek(); }
if (tracer.isDebug()) {tracer.debug("Position %d is in index range %s. Trying to assign args to %s, arity=%s%n", position, indexRange, positionalParam, arity);} if (!assertNoMissingParameters(positionalParam, arity, argsCopy)) { break; } // #389 collectErrors parsing int originalSize = argsCopy.size(); int actuallyConsumed = applyOption(positionalParam, LookBehind.SEPARATE, arity, argsCopy, initialized, "args[" + indexRange + "] at position " + position); int count = originalSize - argsCopy.size(); if (count > 0 || actuallyConsumed > 0) { required.remove(positionalParam); for (int i = 0; i < argsConsumed; i++) { args.pop(); } position += argsConsumed + interactiveConsumed; if (tracer.isDebug()) {tracer.debug("Consumed %d arguments and %d interactive values, moving position to index %d.%n", argsConsumed, interactiveConsumed, position);} if (argsConsumed == 0 && interactiveConsumed == 0 && !args.isEmpty()) { handleUnmatchedArgument(args);