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 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 static List<SQLSelectQueryBlock> splitSQLSelectQuery(SQLSelectQuery x) { List<SQLSelectQueryBlock> groupList = new ArrayList<SQLSelectQueryBlock>(); Stack<SQLSelectQuery> stack = new Stack<SQLSelectQuery>(); stack.push(x); do { SQLSelectQuery query = stack.pop(); if (query instanceof SQLSelectQueryBlock) { groupList.add((SQLSelectQueryBlock) query); } else if (query instanceof SQLUnionQuery) { SQLUnionQuery unionQuery = (SQLUnionQuery) query; stack.push(unionQuery.getLeft()); stack.push(unionQuery.getRight()); } } while (!stack.empty()); return groupList; }
import java.util.*; public class Test { public static void main(String[] args) { Stack<String> stack = new Stack<String>(); stack.push("Bottom"); stack.push("Middle"); stack.push("Top"); List<String> list = new ArrayList<String>(stack); for (String x : list) { System.out.println(x); } } }
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; }
/** Push new diagnostic context information for the current thread. <p>The contents of the <code>message</code> parameter is determined solely by the client. @param message The new diagnostic context information. */ public static void push(String message) { Stack stack = getCurrentStack(); if(stack == null) { DiagnosticContext dc = new DiagnosticContext(message, null); stack = new Stack(); Thread key = Thread.currentThread(); ht.put(key, stack); stack.push(dc); } else if (stack.isEmpty()) { DiagnosticContext dc = new DiagnosticContext(message, null); stack.push(dc); } else { DiagnosticContext parent = (DiagnosticContext) stack.peek(); stack.push(new DiagnosticContext(message, parent)); } }
public static int itFunc(int m, int n){ Stack<Integer> s = new Stack<Integer>; s.add(m); while(!s.isEmpty()){ m=s.pop(); if(m==0||n==0) n+=m+1; else{ s.add(--m); s.add(++m); n--; } } return n; }
import java.util.Collections; import java.util.Stack; public class StackDemo { public static void main(String[] args) { Stack lifo = new Stack(); lifo.push(new Integer(4)); lifo.push(new Integer(1)); lifo.push(new Integer(150)); lifo.push(new Integer(40)); lifo.push(new Integer(0)); lifo.push(new Integer(60)); lifo.push(new Integer(47)); lifo.push(new Integer(104)); System.out.println("max= 150"); // http://xkcd.com/221/ } }
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; }
/** * Creates a new activity stack and pushes the start activity. */ private void createStackAndPushStartActivity(){ activityStack = new Stack<WeakReference<Activity>>(); if (activity != null && config.trackActivities){ WeakReference<Activity> weakReference = new WeakReference<Activity>(activity); activity = null; activityStack.push(weakReference); } }
private Set<Operator<?>> getAllOperatorsForSimpleFetch(Set<Operator<?>> opSet) { Set<Operator<?>> returnSet = new LinkedHashSet<Operator<?>>(); Stack<Operator<?>> opStack = new Stack<Operator<?>>(); // add all children opStack.addAll(opSet); while (!opStack.empty()) { Operator<?> op = opStack.pop(); returnSet.add(op); if (op.getChildOperators() != null) { opStack.addAll(op.getChildOperators()); } } return returnSet; } }
/** * Returns true if a project has a non-direct dependency to another project. * <p> * A non-direct dependency is a path of dependency "edge"s from the source to the destination, * where the length is greater than 1. */ public boolean hasIndirectDependencies(AbstractProject src, AbstractProject dst) { Set<AbstractProject> visited = new HashSet<AbstractProject>(); Stack<AbstractProject> queue = new Stack<AbstractProject>(); queue.addAll(getDownstream(src)); queue.remove(dst); while(!queue.isEmpty()) { AbstractProject p = queue.pop(); if(p==dst) return true; if(visited.add(p)) queue.addAll(getDownstream(p)); } return false; }
public void markOptional(boolean propagate) { this.isOptional = true; if (propagate && next != null) { Stack<State> todo = new Stack<>(); Set<State> seen = new HashSet<>(); todo.addAll(next); while (!todo.empty()) { State s = todo.pop(); s.isOptional = true; seen.add(s); if (next != null) { for (State n : next) { if (!seen.contains(n)) { todo.push(n); } } } } } } }
public static void main(String[] args) { Stack<Integer> s = new Stack<Integer>(); Deque<Integer> d = new ArrayDeque<Integer>(); Queue<Integer> l = new LinkedList<Integer>(); for (int i : numbers) { s.push(i); l.offer(i); d.push(i); } System.out.println("Stack: "); for(Integer i : s) { System.out.println(i); } System.out.println(); System.out.println("Queue:"); for(Integer i : l) { System.out.println(i); } System.out.println(); System.out.println("Deque:"); for(Integer i : d) { System.out.println(i); } }
public FileSequentialCollectionIterator() { // log.info("Coll is " + coll); roots = coll.toArray(); rootsIndex = 0; fileArrayStack = new Stack<>(); fileArrayStackIndices = new Stack<>(); if (roots.length > 0) { fileArrayStack.add(roots[rootsIndex]); fileArrayStackIndices.push(Integer.valueOf(0)); } next = primeNextFile(); }
private Set<Operator<?>> getAllOperatorsForSimpleFetch(Set<Operator<?>> opSet) { Set<Operator<?>> returnSet = new LinkedHashSet<Operator<?>>(); Stack<Operator<?>> opStack = new Stack<Operator<?>>(); // add all children opStack.addAll(opSet); while (!opStack.empty()) { Operator<?> op = opStack.pop(); returnSet.add(op); if (op.getChildOperators() != null) { opStack.addAll(op.getChildOperators()); } } return returnSet; } }