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

x33g5p2x  于2022-01-17 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(706)

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

Deque.peek介绍

[英]Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.

This method is equivalent to #peekFirst().
[中]检索但不删除此deque表示的队列头(换句话说,此deque的第一个元素),如果此deque为空,则返回null。
此方法相当于#peek first()。

代码示例

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

@Override
public boolean isNextComplexMultiValue() {
 Field current = stack.peek();
 final boolean isNext = current.index < current.count;
 if (!isNext) {
  stack.pop();
  stack.peek().index++;
 }
 return isNext;
}

代码示例来源:origin: com.h2database/h2

public String getParsingCreateViewName() {
  if (viewNameStack.isEmpty()) {
    return null;
  }
  return viewNameStack.peek();
}

代码示例来源:origin: lettuce-io/lettuce-core

@Override
public void complete(int depth) {
  if (counts.isEmpty()) {
    return;
  }
  if (depth == stack.size()) {
    if (stack.peek().size() == counts.peek()) {
      List<Object> pop = stack.pop();
      counts.pop();
      if (!stack.isEmpty()) {
        stack.peek().add(pop);
      }
    }
  }
}

代码示例来源:origin: prestodb/presto

@Override
public boolean hasNext()
{
  if (geometriesDeque.isEmpty()) {
    return false;
  }
  while (geometriesDeque.peek() instanceof OGCConcreteGeometryCollection) {
    OGCGeometryCollection collection = (OGCGeometryCollection) geometriesDeque.pop();
    for (int i = 0; i < collection.numGeometries(); i++) {
      geometriesDeque.push(collection.geometryN(i));
    }
  }
  return !geometriesDeque.isEmpty();
}

代码示例来源:origin: com.h2database/h2

/**
 * Stores name of currently parsed view in a stack so it can be determined
 * during {@code prepare()}.
 *
 * @param parsingView
 *            {@code true} to store one more name, {@code false} to remove it
 *            from stack
 * @param viewName
 *            name of the view
 */
public void setParsingCreateView(boolean parsingView, String viewName) {
  // It can be recursive, thus implemented as counter.
  this.parsingView += parsingView ? 1 : -1;
  assert this.parsingView >= 0;
  if (parsingView) {
    viewNameStack.push(viewName);
  } else {
    assert viewName.equals(viewNameStack.peek());
    viewNameStack.pop();
  }
}
public String getParsingCreateViewName() {

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

/**
 * Store un-initialized variables in a temporary stack for future use.
 */
private void storePrevScopeUninitializedVariableData() {
  final ScopeData scopeData = scopeStack.peek();
  final Deque<DetailAST> prevScopeUninitializedVariableData =
      new ArrayDeque<>();
  scopeData.uninitializedVariables.forEach(prevScopeUninitializedVariableData::push);
  prevScopeUninitializedVariables.push(prevScopeUninitializedVariableData);
}

代码示例来源:origin: google/guava

public void testHoldsLockOnAllOperations() {
 create().element();
 create().offer("foo");
 create().peek();
 create().poll();
 create().remove();
 create().equals(new ArrayDeque<>(ImmutableList.of("foo")));
 create().hashCode();
 create().isEmpty();
 create().iterator();
 create().remove("foo");
 create().removeFirstOccurrence("e");
 create().removeLastOccurrence("e");
 create().push("e");
 create().pop();
 create().descendingIterator();

代码示例来源:origin: MovingBlocks/Terasology

@Override
public Activity startActivity(String activityName) {
  if (Thread.currentThread() != mainThread) {
    return OFF_THREAD_ACTIVITY;
  }
  ActivityInfo newActivity = new ActivityInfo(activityName).initialize();
  if (!activityStack.isEmpty()) {
    ActivityInfo currentActivity = activityStack.peek();
    currentActivity.ownTime += newActivity.startTime - ((currentActivity.resumeTime > 0) ? currentActivity.resumeTime : currentActivity.startTime);
    currentActivity.ownMem += (currentActivity.startMem - newActivity.startMem > 0) ? currentActivity.startMem - newActivity.startMem : 0;
  }
  activityStack.push(newActivity);
  return activityInstance;
}

代码示例来源:origin: cucumber/cucumber-jvm

private void moveToNext() {
  if (nextBlank && !this.iterators.isEmpty()) {
    if (!iterators.peek().hasNext()) {
      iterators.removeFirst();
      moveToNext();
    } else {
      final Object next = iterators.peekFirst().next();
      if (next instanceof Iterator) {
        push((Iterator<?>) next);
        moveToNext();
      } else {
        this.next = (T) next;
        nextBlank = false;
      }
    }
  }
}

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

private StringBuilder dump(StringBuilder sb) {
 Deque<ASTNode> stack = new ArrayDeque<ASTNode>();
 stack.push(this);
 int tabLength = 0;
 while (!stack.isEmpty()) {
  ASTNode next = stack.peek();
  if (!next.visited) {
   sb.append(StringUtils.repeat(" ", tabLength * 3));
   sb.append(next.toString());
   sb.append("\n");
   if (next.children != null) {
    for (int i = next.children.size() - 1 ; i >= 0 ; i--) {
     stack.push((ASTNode)next.children.get(i));
    }
   }
   tabLength++;
   next.visited = true;
  } else {
   tabLength--;
   next.visited = false;
   stack.pop();
  }
 }
 return sb;
}

代码示例来源:origin: konsoletyper/teavm

});
Deque<NodeImpl> stack = new ArrayDeque<>();
stack.push(root);
for (Range range : rangeList) {
  NodeImpl current = new NodeImpl();
  current.start = range.left;
  current.end = range.right;
  while (range.right <= stack.peek().start) {
    stack.pop();
  NodeImpl parent = stack.peek();
  current.next = parent.firstChild;
  parent.firstChild = current;
  stack.push(current);

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

/**
 * End a {@link Scope} by removing {@code this} from a {@link java.util.Deque} contained in a
 * {@link java.lang.ThreadLocal}.
 * If {@code this} isn't on the top of the Deque, an {@link IllegalStateException} will be thrown, as that signals a
 * process is trying to end somebody else's scope.
 * If the Deque is empty, it will be removed from the ThreadLocal.
 */
protected void endScope() {
  Deque<Scope> scopes = CURRENT_SCOPE.get();
  if (this != scopes.peek()) {
    throw new IllegalStateException(
        "Incorrectly trying to end another Scope then which the calling process is contained in."
    );
  }
  scopes.pop();
  if (scopes.isEmpty()) {
    logger.debug("Clearing out ThreadLocal current Scope, as no Scopes are present");
    CURRENT_SCOPE.remove();
  }
}

代码示例来源:origin: spockframework/spock

public Integer getCurrentRecordingVarNum() {
  if (startedRecordings.isEmpty()) {
   return null;
  } else {
   return startedRecordings.peek();
  }
 }
}

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

@Override
public void visitToken(DetailAST ast) {
  final AbstractExpressionHandler handler = handlerFactory.getHandler(this, ast,
    handlers.peek());
  handlers.push(handler);
  handler.checkIndentation();
}

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

@Override
 public void finishComplexVariableFieldsType() {
  stack.pop();
  if (stack.peek() == null) {
   throw new RuntimeException();
  }
  stack.peek();
 }
}

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

if (!configStack.isEmpty()) {
  final DefaultConfiguration top =
    configStack.peek();
  top.addChild(conf);
configStack.push(conf);
  configStack.peek();
top.addAttribute(name, value);
final DefaultConfiguration top = configStack.peek();
top.addMessage(key, value);

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

private StringBuilder dump(StringBuilder sb) {
 Deque<ASTNode> stack = new ArrayDeque<ASTNode>();
 stack.push(this);
 int tabLength = 0;
 while (!stack.isEmpty()) {
  ASTNode next = stack.peek();
  if (!next.visited) {
   sb.append(StringUtils.repeat(" ", tabLength * 3));
   sb.append(next.toString());
   sb.append("\n");
   if (next.children != null) {
    for (int i = next.children.size() - 1 ; i >= 0 ; i--) {
     stack.push((ASTNode)next.children.get(i));
    }
   }
   tabLength++;
   next.visited = true;
  } else {
   tabLength--;
   next.visited = false;
   stack.pop();
  }
 }
 return sb;
}

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

stack.push(dir.getName());
} while ((dir = dir.getParentFile()) != null);
while ((dirName = stack.peek()) != null) {
  stack.pop();

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

/**
 * Clears the UnitOfWork currently bound to the current thread, if that UnitOfWork is the given
 * {@code unitOfWork}.
 *
 * @param unitOfWork The UnitOfWork expected to be bound to the current thread.
 * @throws IllegalStateException when the given UnitOfWork was not the current active UnitOfWork. This exception
 *                               indicates a potentially wrong nesting of Units Of Work.
 */
public static void clear(UnitOfWork<?> unitOfWork) {
  if (!isStarted()) {
    throw new IllegalStateException("Could not clear this UnitOfWork. There is no UnitOfWork active.");
  }
  if (CURRENT.get().peek() == unitOfWork) {
    CURRENT.get().pop();
    if (CURRENT.get().isEmpty()) {
      CURRENT.remove();
    }
  } else {
    throw new IllegalStateException("Could not clear this UnitOfWork. It is not the active one.");
  }
}

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

private String quote( String value )
{
  assert !stack.isEmpty();
  Writer head = stack.peek();
  return head.quote( value );
}

相关文章