java.util.Stack.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(260)

本文整理了Java中java.util.Stack.<init>()方法的一些代码示例,展示了Stack.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stack.<init>()方法的具体详情如下:
包路径:java.util.Stack
类名称:Stack
方法名:<init>

Stack.<init>介绍

[英]Constructs a stack with the default size of Vector.
[中]使用向量的默认大小构造堆栈。

代码示例

代码示例来源:origin: jenkinsci/jenkins

  1. synchronized void push(RunExecution r) {
  2. Executor e = Executor.currentExecutor();
  3. Stack<RunExecution> s = stack.get(e);
  4. if(s==null) stack.put(e,s=new Stack<RunExecution>());
  5. s.push(r);
  6. }

代码示例来源:origin: jenkinsci/jenkins

  1. private Set<AbstractProject> getTransitive(Map<AbstractProject, List<DependencyGroup>> direction, AbstractProject src, boolean up) {
  2. Set<AbstractProject> visited = new HashSet<AbstractProject>();
  3. Stack<AbstractProject> queue = new Stack<AbstractProject>();
  4. queue.add(src);
  5. while(!queue.isEmpty()) {
  6. AbstractProject p = queue.pop();
  7. for (AbstractProject child : get(direction,p,up)) {
  8. if(visited.add(child))
  9. queue.add(child);
  10. }
  11. }
  12. return visited;
  13. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. private void flushParents(List<Record> willReturn){
  2. Stack<RepeatedRecordInfo> reverseStack = new Stack<>();
  3. while(!stack.isEmpty()){
  4. reverseStack.push(stack.pop());
  5. }
  6. while(!reverseStack.isEmpty()){
  7. RepeatedRecordInfo info = reverseStack.pop();
  8. info.timesSeen -= 1;
  9. flush(info, willReturn);
  10. stack.push(info);
  11. }
  12. }

代码示例来源:origin: alibaba/druid

  1. private static List<SQLSelectQueryBlock> splitSQLSelectQuery(SQLSelectQuery x) {
  2. List<SQLSelectQueryBlock> groupList = new ArrayList<SQLSelectQueryBlock>();
  3. Stack<SQLSelectQuery> stack = new Stack<SQLSelectQuery>();
  4. stack.push(x);
  5. do {
  6. SQLSelectQuery query = stack.pop();
  7. if (query instanceof SQLSelectQueryBlock) {
  8. groupList.add((SQLSelectQueryBlock) query);
  9. } else if (query instanceof SQLUnionQuery) {
  10. SQLUnionQuery unionQuery = (SQLUnionQuery) query;
  11. stack.push(unionQuery.getLeft());
  12. stack.push(unionQuery.getRight());
  13. }
  14. } while (!stack.empty());
  15. return groupList;
  16. }

代码示例来源:origin: stackoverflow.com

  1. import java.util.*;
  2. public class Test
  3. {
  4. public static void main(String[] args)
  5. {
  6. Stack<String> stack = new Stack<String>();
  7. stack.push("Bottom");
  8. stack.push("Middle");
  9. stack.push("Top");
  10. List<String> list = new ArrayList<String>(stack);
  11. for (String x : list)
  12. {
  13. System.out.println(x);
  14. }
  15. }
  16. }

代码示例来源:origin: spotbugs/spotbugs

  1. public Profiler() {
  2. startTimes = new Stack<>();
  3. profile = new ConcurrentHashMap<>();
  4. if (REPORT) {
  5. System.err.println("Profiling activated");
  6. }
  7. }

代码示例来源:origin: gocd/gocd

  1. private Set<Class> findAllInterfacesInHierarchy(Class candidateGoExtensionClass) {
  2. Stack<Class> classesInHierarchy = new Stack<>();
  3. classesInHierarchy.add(candidateGoExtensionClass);
  4. Set<Class> interfaces = new HashSet<>();
  5. while (!classesInHierarchy.empty()) {
  6. Class classToCheckFor = classesInHierarchy.pop();
  7. if (classToCheckFor.isInterface()) {
  8. interfaces.add(classToCheckFor);
  9. }
  10. classesInHierarchy.addAll(Arrays.asList(classToCheckFor.getInterfaces()));
  11. if (classToCheckFor.getSuperclass() != null) {
  12. classesInHierarchy.add(classToCheckFor.getSuperclass());
  13. }
  14. }
  15. return interfaces;
  16. }

代码示例来源:origin: log4j/log4j

  1. /**
  2. Push new diagnostic context information for the current thread.
  3. <p>The contents of the <code>message</code> parameter is
  4. determined solely by the client.
  5. @param message The new diagnostic context information. */
  6. public
  7. static
  8. void push(String message) {
  9. Stack stack = getCurrentStack();
  10. if(stack == null) {
  11. DiagnosticContext dc = new DiagnosticContext(message, null);
  12. stack = new Stack();
  13. Thread key = Thread.currentThread();
  14. ht.put(key, stack);
  15. stack.push(dc);
  16. } else if (stack.isEmpty()) {
  17. DiagnosticContext dc = new DiagnosticContext(message, null);
  18. stack.push(dc);
  19. } else {
  20. DiagnosticContext parent = (DiagnosticContext) stack.peek();
  21. stack.push(new DiagnosticContext(message, parent));
  22. }
  23. }

代码示例来源:origin: stackoverflow.com

  1. public static int itFunc(int m, int n){
  2. Stack<Integer> s = new Stack<Integer>;
  3. s.add(m);
  4. while(!s.isEmpty()){
  5. m=s.pop();
  6. if(m==0||n==0)
  7. n+=m+1;
  8. else{
  9. s.add(--m);
  10. s.add(++m);
  11. n--;
  12. }
  13. }
  14. return n;
  15. }

代码示例来源:origin: stackoverflow.com

  1. Stack<String> stack = new Stack<String>();
  2. stack.push("1");
  3. stack.push("2");
  4. stack.push("3");
  5. stack.insertElementAt("squeeze me in!", 1);
  6. while (!stack.isEmpty()) {
  7. System.out.println(stack.pop());
  8. }
  9. // prints "3", "2", "squeeze me in!", "1"

代码示例来源:origin: stackoverflow.com

  1. import java.util.Collections;
  2. import java.util.Stack;
  3. public class StackDemo {
  4. public static void main(String[] args) {
  5. Stack lifo = new Stack();
  6. lifo.push(new Integer(4));
  7. lifo.push(new Integer(1));
  8. lifo.push(new Integer(150));
  9. lifo.push(new Integer(40));
  10. lifo.push(new Integer(0));
  11. lifo.push(new Integer(60));
  12. lifo.push(new Integer(47));
  13. lifo.push(new Integer(104));
  14. System.out.println("max= 150"); // http://xkcd.com/221/
  15. }
  16. }

代码示例来源:origin: jenkinsci/jenkins

  1. private CmdLineParser bindMethod(List<MethodBinder> binders) {
  2. registerOptionHandlers();
  3. CmdLineParser parser = new CmdLineParser(null);
  4. // build up the call sequence
  5. Stack<Method> chains = new Stack<>();
  6. Method method = m;
  7. while (true) {
  8. chains.push(method);
  9. if (Modifier.isStatic(method.getModifiers()))
  10. break; // the chain is complete.
  11. // the method in question is an instance method, so we need to resolve the instance by using another resolver
  12. Class<?> type = method.getDeclaringClass();
  13. try {
  14. method = findResolver(type);
  15. } catch (IOException ex) {
  16. throw new RuntimeException("Unable to find the resolver method annotated with @CLIResolver for " + type, ex);
  17. }
  18. if (method == null) {
  19. throw new RuntimeException("Unable to find the resolver method annotated with @CLIResolver for " + type);
  20. }
  21. }
  22. while (!chains.isEmpty())
  23. binders.add(new MethodBinder(chains.pop(), this, parser));
  24. return parser;
  25. }

代码示例来源:origin: RobotiumTech/robotium

  1. /**
  2. * Creates a new activity stack and pushes the start activity.
  3. */
  4. private void createStackAndPushStartActivity(){
  5. activityStack = new Stack<WeakReference<Activity>>();
  6. if (activity != null && config.trackActivities){
  7. WeakReference<Activity> weakReference = new WeakReference<Activity>(activity);
  8. activity = null;
  9. activityStack.push(weakReference);
  10. }
  11. }

代码示例来源:origin: apache/hive

  1. private Set<Operator<?>> getAllOperatorsForSimpleFetch(Set<Operator<?>> opSet) {
  2. Set<Operator<?>> returnSet = new LinkedHashSet<Operator<?>>();
  3. Stack<Operator<?>> opStack = new Stack<Operator<?>>();
  4. // add all children
  5. opStack.addAll(opSet);
  6. while (!opStack.empty()) {
  7. Operator<?> op = opStack.pop();
  8. returnSet.add(op);
  9. if (op.getChildOperators() != null) {
  10. opStack.addAll(op.getChildOperators());
  11. }
  12. }
  13. return returnSet;
  14. }
  15. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Returns true if a project has a non-direct dependency to another project.
  3. * <p>
  4. * A non-direct dependency is a path of dependency "edge"s from the source to the destination,
  5. * where the length is greater than 1.
  6. */
  7. public boolean hasIndirectDependencies(AbstractProject src, AbstractProject dst) {
  8. Set<AbstractProject> visited = new HashSet<AbstractProject>();
  9. Stack<AbstractProject> queue = new Stack<AbstractProject>();
  10. queue.addAll(getDownstream(src));
  11. queue.remove(dst);
  12. while(!queue.isEmpty()) {
  13. AbstractProject p = queue.pop();
  14. if(p==dst)
  15. return true;
  16. if(visited.add(p))
  17. queue.addAll(getDownstream(p));
  18. }
  19. return false;
  20. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. public void markOptional(boolean propagate) {
  2. this.isOptional = true;
  3. if (propagate && next != null) {
  4. Stack<State> todo = new Stack<>();
  5. Set<State> seen = new HashSet<>();
  6. todo.addAll(next);
  7. while (!todo.empty()) {
  8. State s = todo.pop();
  9. s.isOptional = true;
  10. seen.add(s);
  11. if (next != null) {
  12. for (State n : next) {
  13. if (!seen.contains(n)) {
  14. todo.push(n);
  15. }
  16. }
  17. }
  18. }
  19. }
  20. }
  21. }

代码示例来源:origin: stackoverflow.com

  1. public static void main(String[] args) {
  2. Stack<Integer> s = new Stack<Integer>();
  3. Deque<Integer> d = new ArrayDeque<Integer>();
  4. Queue<Integer> l = new LinkedList<Integer>();
  5. for (int i : numbers) {
  6. s.push(i);
  7. l.offer(i);
  8. d.push(i);
  9. }
  10. System.out.println("Stack: ");
  11. for(Integer i : s) {
  12. System.out.println(i);
  13. }
  14. System.out.println();
  15. System.out.println("Queue:");
  16. for(Integer i : l) {
  17. System.out.println(i);
  18. }
  19. System.out.println();
  20. System.out.println("Deque:");
  21. for(Integer i : d) {
  22. System.out.println(i);
  23. }
  24. }

代码示例来源:origin: jenkinsci/jenkins

  1. String[] p = path.split("/");
  2. Stack<String> name = new Stack<String>();
  3. for (int i=0; i<c.length;i++) {
  4. if (i==0 && c[i].equals("")) continue;
  5. name.push(c[i]);
  6. ));
  7. name.pop();
  8. continue;
  9. continue;
  10. name.push(p[i]);

代码示例来源:origin: stanfordnlp/CoreNLP

  1. public FileSequentialCollectionIterator() {
  2. // log.info("Coll is " + coll);
  3. roots = coll.toArray();
  4. rootsIndex = 0;
  5. fileArrayStack = new Stack<>();
  6. fileArrayStackIndices = new Stack<>();
  7. if (roots.length > 0) {
  8. fileArrayStack.add(roots[rootsIndex]);
  9. fileArrayStackIndices.push(Integer.valueOf(0));
  10. }
  11. next = primeNextFile();
  12. }

代码示例来源:origin: apache/drill

  1. private Set<Operator<?>> getAllOperatorsForSimpleFetch(Set<Operator<?>> opSet) {
  2. Set<Operator<?>> returnSet = new LinkedHashSet<Operator<?>>();
  3. Stack<Operator<?>> opStack = new Stack<Operator<?>>();
  4. // add all children
  5. opStack.addAll(opSet);
  6. while (!opStack.empty()) {
  7. Operator<?> op = opStack.pop();
  8. returnSet.add(op);
  9. if (op.getChildOperators() != null) {
  10. opStack.addAll(op.getChildOperators());
  11. }
  12. }
  13. return returnSet;
  14. }
  15. }

相关文章