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

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

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

  1. /**
  2. * Returns the name of the most recent Activity
  3. *
  4. * @return the name of the current {@code Activity}
  5. */
  6. public String getCurrentActivityName(){
  7. if(!activitiesStoredInActivityStack.isEmpty()){
  8. return activitiesStoredInActivityStack.peek();
  9. }
  10. return "";
  11. }

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

  1. /**
  2. * Peek the last signal
  3. */
  4. public Signal signalPeek() {
  5. if (!exec.signals.empty()) {
  6. return exec.signals.peek();
  7. }
  8. return null;
  9. }

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

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

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

  1. private GroovySourceAST getParentNode() {
  2. GroovySourceAST parentNode = null;
  3. GroovySourceAST currentNode = stack.pop();
  4. if (!stack.empty()) {
  5. parentNode = stack.peek();
  6. }
  7. stack.push(currentNode);
  8. return parentNode;
  9. }

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

  1. /**
  2. * walk the current operator and its descendants.
  3. *
  4. * @param nd
  5. * current operator in the graph
  6. * @throws SemanticException
  7. */
  8. @Override
  9. protected void walk(Node nd) throws SemanticException {
  10. if (opStack.empty() || nd != opStack.peek()) {
  11. opStack.push(nd);
  12. }
  13. if (allParentsDispatched(nd)) {
  14. // all children are done or no need to walk the children
  15. if (!getDispatchedList().contains(nd)) {
  16. toWalk.addAll(nd.getChildren());
  17. dispatch(nd, opStack);
  18. }
  19. opStack.pop();
  20. return;
  21. }
  22. // add children, self to the front of the queue in that order
  23. toWalk.add(0, nd);
  24. addAllParents(nd);
  25. }
  26. }

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

  1. private void shuntOperators(List<Token> outputQueue, Stack<Token> stack, LazyOperator o1) {
  2. Expression.Token nextToken = stack.isEmpty() ? null : stack.peek();
  3. while (nextToken != null
  4. && (nextToken.type == Expression.TokenType.OPERATOR || nextToken.type == Expression.TokenType.UNARY_OPERATOR)
  5. && ((o1.isLeftAssoc() && o1.getPrecedence() <= operators.get(nextToken.surface).getPrecedence()) || (o1
  6. .getPrecedence() < operators.get(nextToken.surface).getPrecedence()))) {
  7. outputQueue.add(stack.pop());
  8. nextToken = stack.isEmpty() ? null : stack.peek();
  9. }
  10. }

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

  1. public void pushSection(PageSection pageSection) {
  2. LayoutSection section = new LayoutSection(pageSection.getName(), pageSection.getPlace());
  3. if (!sectionStack.isEmpty()) {
  4. sectionStack.peek().addSection(section);
  5. }
  6. else {
  7. layoutReport.getSections().add(section);
  8. }
  9. sectionStack.push(section);
  10. }

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

  1. arity = arity.min(Math.max(1, arity.min)); // if key=value, minimum arity is at least 1
  2. if (arity.min > 0 && !empty(cluster)) {
  3. if (tracer.isDebug()) {tracer.debug("Trying to process '%s' as option parameter%n", cluster);}
  4. if (!empty(cluster)) {
  5. args.push(cluster); // interpret remainder as option parameter (CAUTION: may be empty string!)
  6. parseResult.nowProcessing.add(argSpec);
  7. first = false;
  8. } else {
  9. int consumed = applyOption(argSpec, lookBehind, arity, args, initialized, argDescription);
  10. if (empty(cluster) || args.isEmpty() || args.size() < argCount) {
  11. return;
  12. cluster = args.pop();
  13. } else { // cluster is empty || cluster.charAt(0) is not a short option key
  14. if (cluster.length() == 0) { // we finished parsing a group of short options like -rxv
  15. args.push(paramAttachedToOption ? prefix + cluster : cluster);
  16. if (args.peek().equals(arg)) { // #149 be consistent between unmatched short and long options
  17. 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);}
  18. if (commandSpec.resemblesOption(arg, tracer)) { handleUnmatchedArgument(args); return; } // #149

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

  1. List dirs = new ArrayList();
  2. List sizes = new ArrayList();
  3. while (stack.peek() instanceof File) {
  4. dirs.add(stack.pop());
  5. sizes.add(stack.pop());
  6. Object a = stack.peek();
  7. if (a instanceof RegionAttributesCreation) {
  8. RegionAttributesCreation attrs = (RegionAttributesCreation) a;

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

  1. private GroovySourceAST getParentNode() {
  2. Object currentNode = stack.pop();
  3. Object parentNode = stack.peek();
  4. stack.push(currentNode);
  5. return (GroovySourceAST) parentNode;
  6. }

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

  1. /**
  2. * Push a new fieldname on to the stack
  3. */
  4. private void pushField( final String fieldName ) {
  5. if ( fieldStack.isEmpty() ) {
  6. fieldStack.push( fieldName );
  7. return;
  8. }
  9. final String newFieldName = fieldStack.peek() + "." + fieldName;
  10. fieldStack.push( newFieldName );
  11. }

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

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

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

  1. private void validateRootExists(CaseInsensitiveString root, PipelineDependencyState pipelineDependencyState, Stack<CaseInsensitiveString> visiting) throws Exception {
  2. if (!pipelineDependencyState.hasPipeline(root)) {
  3. StringBuffer sb = new StringBuffer("Pipeline \"");
  4. sb.append(root);
  5. sb.append("\" does not exist.");
  6. visiting.pop();
  7. if (!visiting.empty()) {
  8. CaseInsensitiveString parent = visiting.peek();
  9. sb.append(" It is used from pipeline \"");
  10. sb.append(parent);
  11. sb.append("\".");
  12. }
  13. throw new Exception(sb.toString());
  14. }
  15. }

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

  1. private void endIndex() {
  2. // Ignore any whitespace noise between fields
  3. if (stack.peek() instanceof StringBuffer) {
  4. stack.pop();
  5. }
  6. // Remove the index creation from the stack
  7. stack.pop();
  8. }

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

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

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

  1. public Scope addScope(boolean isRoot) {
  2. Scope scope = new Scope(scopeStack.empty() ? null : scopeStack.peek());
  3. scopeStack.push(scope);
  4. if (isRoot)
  5. rootScopeStack.push(scope);
  6. return scope;
  7. }

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

  1. private Phrase getNext() {
  2. while (!iteratorStack.isEmpty()) {
  3. Iterator<Object> iter = iteratorStack.peek();
  4. if (iter.hasNext()) {
  5. Object obj = iter.next();
  6. if (obj instanceof Phrase) {
  7. return (Phrase) obj;
  8. } else if (obj instanceof Map) {
  9. iteratorStack.push(((Map) obj).values().iterator());
  10. } else if (obj instanceof List) {
  11. iteratorStack.push(((List) obj).iterator());
  12. } else {
  13. throw new RuntimeException("Unexpected class in phrase table " + obj.getClass());
  14. }
  15. } else {
  16. iteratorStack.pop();
  17. }
  18. }
  19. return null;
  20. }

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

  1. /**
  2. * walk the current operator and its descendants.
  3. *
  4. * @param nd
  5. * current operator in the graph
  6. * @throws SemanticException
  7. */
  8. @Override
  9. protected void walk(Node nd) throws SemanticException {
  10. if (opStack.empty() || nd != opStack.peek()) {
  11. opStack.push(nd);
  12. }
  13. if (allParentsDispatched(nd)) {
  14. // all children are done or no need to walk the children
  15. if (!getDispatchedList().contains(nd)) {
  16. toWalk.addAll(nd.getChildren());
  17. dispatch(nd, opStack);
  18. }
  19. opStack.pop();
  20. return;
  21. }
  22. // add children, self to the front of the queue in that order
  23. toWalk.add(0, nd);
  24. addAllParents(nd);
  25. }
  26. }

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

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

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

  1. private static void close(Stack<XNode> stack, String text) {
  2. U.must(!stack.isEmpty(), "Empty stack!");
  3. XNode x = stack.pop();
  4. U.must(x.op != XNode.OP.OP_ROOT, "Cannot close a tag that wasn't open: %s", text);
  5. if (!U.eq(x.text, text)) {
  6. throw U.rte("Expected block: %s, but found: %s", x.text, text);
  7. }
  8. stack.peek().children.add(x);
  9. }

相关文章