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

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

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

Stack.isEmpty介绍

暂无

代码示例

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

@Override
 void advance() {
  if (searchStack.isEmpty()) {
   next = null;
  } else {
   next = searchStack.pop();
  }
 }
};

代码示例来源: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: 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: 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: stanfordnlp/CoreNLP

@Override
public void initialize() {
 if (node.equals(IndexedWord.NO_WORD)) {
  next = null;
  return;
 }
 searchStack = Generics.newArrayList();
 for (int i = 0; i <= endDepth; ++i) {
  searchStack.add(new Stack<>());
 }
 seenNodes = new ArrayList<>();
 for (int i = 0; i <= endDepth; ++i) {
  seenNodes.add(Generics.<IndexedWord>newIdentityHashSet());
 }
 returnedNodes = Generics.newIdentityHashSet();
 currentDepth = 1;
 List<Pair<GrammaticalRelation, IndexedWord>> children = sg.childPairs(node);
 for (int i = children.size() - 1; i >= 0; i--) {
  searchStack.get(1).push(children.get(i));
 }
 if (!searchStack.get(1).isEmpty()) {
  advance();
 }
}

代码示例来源:origin: shekhargulati/99-problems

public <T> List<T> reverse(List<T> list) {
    /*
    Algorithm:
      1. Maintain a stack
      2. Iterate over all the elements in a list and put that on the stack
      3. Then empty the stack into a new LinkedList
     */
    Stack<T> stack = new Stack<>();
    list.forEach(stack::push);
    List<T> reversed = new LinkedList<>();
    while (!stack.isEmpty()) {
      reversed.add(stack.pop());
    }
    return reversed;
  }
}

代码示例来源: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: neo4j/neo4j

protected void assertLevels( Traverser traverser, Stack<Set<String>> levels )
{
  Set<String> current = levels.pop();
  for ( Path position : traverser )
  {
    String nodeName = (String) position.endNode().getProperty( "name" );
    if ( current.isEmpty() )
    {
      current = levels.pop();
    }
    assertTrue( "Should not contain node (" + nodeName
        + ") at level " + (3 - levels.size()),
        current.remove( nodeName ) );
  }
  assertTrue( "Should have no more levels", levels.isEmpty() );
  assertTrue( "Should be empty", current.isEmpty() );
}

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

@Override
public void initialize() {
 searchStack = new Stack<>();
 for (int i = t.numChildren() - 1; i >= 0; i--) {
  searchStack.push(t.getChild(i));
 }
 if (!searchStack.isEmpty()) {
  advance();
 }
}

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

private boolean assertNoMissingParameters(ArgSpec argSpec, Range arity, Stack<String> args) {
  if (argSpec.interactive()) { return true; }
  int available = args.size();
  if (available > 0 && commandSpec.parser().splitFirst() && argSpec.splitRegex().length() > 0) {
    available += argSpec.splitValue(args.peek(), commandSpec.parser(), arity, 0).length - 1;
    } else if (args.isEmpty()) {
      maybeThrow(new MissingParameterException(CommandLine.this, argSpec, optionDescription("", argSpec, 0) +
          " requires at least " + arity.min + " values, but none were specified."));

代码示例来源:origin: org.mockito/mockito-core

private void assertStateFor(String additionalMatcherName, int subMatchersCount) {
  if (matcherStack.isEmpty()) {
    throw reportNoSubMatchersFound(additionalMatcherName);
  }
  if (matcherStack.size() < subMatchersCount) {
    List<LocalizedMatcher> lastMatchers = resetStack();
    throw incorrectUseOfAdditionalMatchers(additionalMatcherName, subMatchersCount, lastMatchers);
  }
}

代码示例来源: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: stanfordnlp/CoreNLP

@Override
public void initialize() {
 if (node.equals(IndexedWord.NO_WORD)) {
  next = null;
  return;
 }
 searchStack = Generics.newArrayList();
 for (int i = 0; i <= endDepth; ++i) {
  searchStack.add(new Stack<>());
 }
 seenNodes = new ArrayList<>();
 for (int i = 0; i <= endDepth; ++i) {
  seenNodes.add(Generics.<IndexedWord>newIdentityHashSet());
 }
 returnedNodes = Generics.newIdentityHashSet();
 currentDepth = 1;
 List<Pair<GrammaticalRelation, IndexedWord>> parents = sg.parentPairs(node);
 for (int i = parents.size() - 1; i >= 0; i--) {
  searchStack.get(1).push(parents.get(i));
 }
 if (!searchStack.get(1).isEmpty()) {
  advance();
 }
}

代码示例来源:origin: shekhargulati/99-problems

public boolean isBalancedString(final String input) {
  /*
  Algorithm:
    1. Iterate over all the characters in a String
    2. if stack is not empty and character is ')' then pop the element from the stack
    3. else push the element into the stack
    4. After iteration if stack is empty then return true else return false.
   */
  Stack<Character> stack = new Stack<>();
  char[] chars = input.toCharArray();
  for (char ch : chars) {
    if (ch == ')' && !stack.empty()) {
      stack.pop();
    } else {
      stack.push(ch);
    }
  }
  return stack.isEmpty();
}

代码示例来源:origin: k9mail/k-9

@Override
public void startMessage() throws MimeException {
  if (stack.isEmpty()) {
    stack.push(decryptedRootPart);
  } else {
    Part part = (Part) stack.peek();
    Message innerMessage = new MimeMessage();
    part.setBody(innerMessage);
    stack.push(innerMessage);
  }
}

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

@Override
 void advance() {
  if (searchStack.isEmpty()) {
   next = null;
  } else {
   next = searchStack.pop();
  }
 }
};

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

/**
 * Receive notification of the end of an element.
 *
 * <p>The SAX parser will invoke this method at the end of every
 * element in the XML document; there will be a corresponding
 * startElement() event for every endElement() event (even when the
 * element is empty).</p>
 *
 * <p>If the element name has a namespace prefix, the prefix will
 * still be attached to the name.</p>
 *
 *
 * @param ns the namespace of the element
 * @param localName The local part of the qualified name of the element
 * @param name The element name
 */
public void endElement(String ns, String localName, String name)
    throws org.xml.sax.SAXException
{
 m_elemStack.pop();
 m_currentNode = m_elemStack.isEmpty() ? null : (Node)m_elemStack.peek();
}

代码示例来源:origin: pedrovgs/Algorithms

public int getMin() {
  if (innerStack.isEmpty()) {
   return Integer.MAX_VALUE;
  } else {
   return innerStack.peek();
  }
 }
}

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

if (tracer.isDebug()) {tracer.debug("Position %d is in index range %s. Trying to assign args to %s, arity=%s%n", position, indexRange, positionalParam, arity);}
  if (!assertNoMissingParameters(positionalParam, arity, argsCopy)) { break; } // #389 collectErrors parsing
  int originalSize = argsCopy.size();
  int actuallyConsumed = applyOption(positionalParam, LookBehind.SEPARATE, arity, argsCopy, initialized, "args[" + indexRange + "] at position " + position);
  int count = originalSize - argsCopy.size();
  if (count > 0 || actuallyConsumed > 0) {
    required.remove(positionalParam);
for (int i = 0; i < argsConsumed; i++) { args.pop(); }
position += argsConsumed + interactiveConsumed;
if (tracer.isDebug()) {tracer.debug("Consumed %d arguments and %d interactive values, moving position to index %d.%n", argsConsumed, interactiveConsumed, position);}
if (argsConsumed == 0 && interactiveConsumed == 0 && !args.isEmpty()) {
  handleUnmatchedArgument(args);

相关文章