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

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

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

Stack.peek介绍

[英]Returns the element at the top of the stack without removing it.
[中]返回堆栈顶部的元素,而不删除它。

代码示例

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

/**
 * Returns the name of the most recent Activity
 *  
 * @return the name of the current {@code Activity}
 */

public String getCurrentActivityName(){
  if(!activitiesStoredInActivityStack.isEmpty()){
    return activitiesStoredInActivityStack.peek();
  }
  return "";
}

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

/**
 * Peek the last signal
 */
public Signal signalPeek() {
 if (!exec.signals.empty()) {
  return exec.signals.peek();
 }
 return null;
}

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

public void addAttribute(String name, String value) {
  List<String> atts = pendings.peek().attributes;
  atts.add(escapeXmlName(name));
  atts.add(value);
}

代码示例来源:origin: groovy/groovy-core

private GroovySourceAST getParentNode() {
  GroovySourceAST parentNode = null;
  GroovySourceAST currentNode = stack.pop();
  if (!stack.empty()) {
    parentNode = stack.peek();
  }
  stack.push(currentNode);
  return parentNode;
}

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

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

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

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

代码示例来源:origin: galenframework/galen

public void pushSection(PageSection pageSection) {
  LayoutSection section = new LayoutSection(pageSection.getName(), pageSection.getPlace());
  if (!sectionStack.isEmpty()) {
    sectionStack.peek().addSection(section);
  }
  else {
    layoutReport.getSections().add(section);
  }
  sectionStack.push(section);
}

代码示例来源:origin: remkop/picocli

arity = arity.min(Math.max(1, arity.min)); // if key=value, minimum arity is at least 1
  if (arity.min > 0 && !empty(cluster)) {
    if (tracer.isDebug()) {tracer.debug("Trying to process '%s' as option parameter%n", cluster);}
  if (!empty(cluster)) {
    args.push(cluster); // interpret remainder as option parameter (CAUTION: may be empty string!)
    parseResult.nowProcessing.add(argSpec);
    first = false;
  } else {
  int consumed = applyOption(argSpec, lookBehind, arity, args, initialized, argDescription);
  if (empty(cluster) || args.isEmpty() || args.size() < argCount) {
    return;
  cluster = args.pop();
} else { // cluster is empty || cluster.charAt(0) is not a short option key
  if (cluster.length() == 0) { // we finished parsing a group of short options like -rxv
    args.push(paramAttachedToOption ? prefix + cluster : cluster);
    if (args.peek().equals(arg)) { // #149 be consistent between unmatched short and long options
      if (tracer.isDebug()) {tracer.debug("Could not match any short options in %s, deciding whether to treat as unmatched option or positional parameter...%n", arg);}
      if (commandSpec.resemblesOption(arg, tracer)) { handleUnmatchedArgument(args); return; } // #149

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

List dirs = new ArrayList();
List sizes = new ArrayList();
while (stack.peek() instanceof File) {
 dirs.add(stack.pop());
 sizes.add(stack.pop());
Object a = stack.peek();
if (a instanceof RegionAttributesCreation) {
 RegionAttributesCreation attrs = (RegionAttributesCreation) a;

代码示例来源:origin: org.codehaus.groovy/groovy

private GroovySourceAST getParentNode() {
  Object currentNode = stack.pop();
  Object parentNode = stack.peek();
  stack.push(currentNode);
  return (GroovySourceAST) parentNode;
}

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

/**
 * Push a new fieldname on to the stack
 */
private void pushField( final String fieldName ) {
  if ( fieldStack.isEmpty() ) {
    fieldStack.push( fieldName );
    return;
  }
  final String newFieldName = fieldStack.peek() + "." + fieldName;
  fieldStack.push( newFieldName );
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Called at the end of processing an antlib.
 */
public void exitAntLib() {
  antLibStack.pop();
  antLibCurrentUri = (antLibStack.isEmpty()) ? null : antLibStack.peek();
}

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

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

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

private void endIndex() {
 // Ignore any whitespace noise between fields
 if (stack.peek() instanceof StringBuffer) {
  stack.pop();
 }
 // Remove the index creation from the stack
 stack.pop();
}

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

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
  String tagName = localName.toUpperCase(Locale.ENGLISH);
  // make sure that this tag occurs in the proper context
  if(!elements.peek().isAllowed(tagName))
    throw new SAXException(tagName+" is not allowed inside "+tagNames.peek());
  Checker next = CHECKERS.get(tagName);
  if(next==null)  next = ALL_ALLOWED;
  elements.push(next);
  tagNames.push(tagName);
  super.startElement(uri, localName, qName, atts);
}

代码示例来源:origin: jphp-group/jphp

public Scope addScope(boolean isRoot) {
  Scope scope = new Scope(scopeStack.empty() ? null : scopeStack.peek());
  scopeStack.push(scope);
  if (isRoot)
    rootScopeStack.push(scope);
  return scope;
}

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

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

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

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

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

private static void addText(Stack<XNode> stack, String g1) {
  stack.peek().children.add(new XNode(XNode.OP.OP_TEXT, g1));
}

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

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

相关文章