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 void visit(N p) throws CycleDetectedException { if (!visited.add(p)) return; visiting.add(p); path.push(p); for (N q : getEdges(p)) { if (q==null) continue; // ignore unresolved references if (visiting.contains(q)) detectedCycle(q); visit(q); } visiting.remove(p); path.pop(); topologicalOrder.add(p); }
/** * walk the current operator and its descendants. * * @param nd * current operator in the graph * @throws SemanticException */ @Override protected void walk(Node nd) throws SemanticException { if (opStack.empty() || nd != opStack.peek()) { opStack.push(nd); } if (allParentsDispatched(nd)) { // all children are done or no need to walk the children if (!getDispatchedList().contains(nd)) { toWalk.addAll(nd.getChildren()); dispatch(nd, opStack); } opStack.pop(); return; } // add children, self to the front of the queue in that order toWalk.add(0, nd); addAllParents(nd); } }
private void shuntOperators(List<Token> outputQueue, Stack<Token> stack, LazyOperator o1) { Expression.Token nextToken = stack.isEmpty() ? null : stack.peek(); while (nextToken != null && (nextToken.type == Expression.TokenType.OPERATOR || nextToken.type == Expression.TokenType.UNARY_OPERATOR) && ((o1.isLeftAssoc() && o1.getPrecedence() <= operators.get(nextToken.surface).getPrecedence()) || (o1 .getPrecedence() < operators.get(nextToken.surface).getPrecedence()))) { outputQueue.add(stack.pop()); nextToken = stack.isEmpty() ? null : stack.peek(); } }
private Set<AbstractProject> getTransitive(Map<AbstractProject, List<DependencyGroup>> direction, AbstractProject src, boolean up) { Set<AbstractProject> visited = new HashSet<AbstractProject>(); Stack<AbstractProject> queue = new Stack<AbstractProject>(); queue.add(src); while(!queue.isEmpty()) { AbstractProject p = queue.pop(); for (AbstractProject child : get(direction,p,up)) { if(visited.add(child)) queue.add(child); } } return visited; }
private void validateRootExists(CaseInsensitiveString root, PipelineDependencyState pipelineDependencyState, Stack<CaseInsensitiveString> visiting) throws Exception { if (!pipelineDependencyState.hasPipeline(root)) { StringBuffer sb = new StringBuffer("Pipeline \""); sb.append(root); sb.append("\" does not exist."); visiting.pop(); if (!visiting.empty()) { CaseInsensitiveString parent = visiting.peek(); sb.append(" It is used from pipeline \""); sb.append(parent); sb.append("\"."); } throw new Exception(sb.toString()); } }
private Set<Class> findAllInterfacesInHierarchy(Class candidateGoExtensionClass) { Stack<Class> classesInHierarchy = new Stack<>(); classesInHierarchy.add(candidateGoExtensionClass); Set<Class> interfaces = new HashSet<>(); while (!classesInHierarchy.empty()) { Class classToCheckFor = classesInHierarchy.pop(); if (classToCheckFor.isInterface()) { interfaces.add(classToCheckFor); } classesInHierarchy.addAll(Arrays.asList(classToCheckFor.getInterfaces())); if (classToCheckFor.getSuperclass() != null) { classesInHierarchy.add(classToCheckFor.getSuperclass()); } } return interfaces; }
private void run(Graph<T> graph, T v) { m_indices.put(v, m_index); m_lowlinks.put(v, m_index); m_index++; m_s.push(v); for (T vprime : graph.getPredecessors(v)) { if (! m_indices.containsKey(vprime)) { run(graph, vprime); int min = Math.min(m_lowlinks.get(v), m_lowlinks.get(vprime)); m_lowlinks.put(v, min); } else if (m_s.contains(vprime)) { m_lowlinks.put(v, Math.min(m_lowlinks.get(v), m_indices.get(vprime))); } } if (Objects.equals(m_lowlinks.get(v), m_indices.get(v))) { m_cycle = Lists.newArrayList(); T n; do { n = m_s.pop(); m_cycle.add(n); } while (! n.equals(v)); } }
private static void close(Stack<XNode> stack, String text) { U.must(!stack.isEmpty(), "Empty stack!"); XNode x = stack.pop(); U.must(x.op != XNode.OP.OP_ROOT, "Cannot close a tag that wasn't open: %s", text); if (!U.eq(x.text, text)) { throw U.rte("Expected block: %s, but found: %s", x.text, text); } stack.peek().children.add(x); }