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

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

本文整理了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

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

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

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;
}

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

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);
  }
}

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

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;
}

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

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);
    }
  }
}

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

public Profiler() {
  startTimes = new Stack<>();
  profile = new ConcurrentHashMap<>();
  if (REPORT) {
    System.err.println("Profiling activated");
  }
}

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

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;
}

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

/**
  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));
 }    
}

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

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;
}

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

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

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

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/
  }
}

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

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;
}

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

/**
 * 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);
  }
}

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

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;
 }
}

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

/**
 * 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;
}

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

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);
      }
     }
    }
   }
  }
 }
}

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

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);
 }
}

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

String[] p = path.split("/");
Stack<String> name = new Stack<String>();
for (int i=0; i<c.length;i++) {
  if (i==0 && c[i].equals("")) continue;
  name.push(c[i]);
      ));
    name.pop();
    continue;
    continue;
  name.push(p[i]);

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

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();
}

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

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;
 }
}

相关文章