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

x33g5p2x  于2022-01-15 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(168)

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

ArrayDeque.peek介绍

[英]Retrieves, but does not remove, the head of the queue represented by this deque, or returns null if this deque is empty.

This method is equivalent to #peekFirst.
[中]检索但不删除此deque表示的队列头,如果此deque为空,则返回null。
此方法相当于#peek first。

代码示例

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

@Override
public AsyncResult peekBlockingly() throws InterruptedException {
  lock.lockInterruptibly();
  try {
    while (completedQueue.isEmpty()) {
      hasCompletedEntries.await();
    }
    LOG.debug("Peeked head element from unordered stream element queue with filling degree " +
      "({}/{}).", numberEntries, capacity);
    return completedQueue.peek();
  } finally {
    lock.unlock();
  }
}

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

@Override
public AsyncResult peekBlockingly() throws InterruptedException {
  lock.lockInterruptibly();
  try {
    while (queue.isEmpty() || !queue.peek().isDone()) {
      headIsCompleted.await();
    }
    LOG.debug("Peeked head element from ordered stream element queue with filling degree " +
      "({}/{}).", queue.size(), capacity);
    return queue.peek();
  } finally {
    lock.unlock();
  }
}

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

public String getNdc() {
  ArrayDeque<Entry> stack = ndcStack.get();
  return stack == null || stack.isEmpty() ? null : stack.peek().merged;
}

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

public String peekNdc() {
  ArrayDeque<Entry> stack = ndcStack.get();
  return stack == null || stack.isEmpty() ? "" : stack.peek().current;
}

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

@Override
public AsyncResult poll() throws InterruptedException {
  lock.lockInterruptibly();
  try {
    while (queue.isEmpty() || !queue.peek().isDone()) {
      headIsCompleted.await();
    }
    notFull.signalAll();
    LOG.debug("Polled head element from ordered stream element queue. New filling degree " +
      "({}/{}).", queue.size() - 1, capacity);
    return queue.poll();
  } finally {
    lock.unlock();
  }
}

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

/**
   * Check if the completed {@link StreamElementQueueEntry} is the current head. If this is the
   * case, then notify the consumer thread about a new consumable entry.
   *
   * @param streamElementQueueEntry which has been completed
   * @throws InterruptedException if the current thread is interrupted
   */
  private void onCompleteHandler(StreamElementQueueEntry<?> streamElementQueueEntry) throws InterruptedException {
    lock.lockInterruptibly();

    try {
      if (!queue.isEmpty() && queue.peek().isDone()) {
        LOG.debug("Signal ordered stream element queue has completed head element.");
        headIsCompleted.signalAll();
      }
    } finally {
      lock.unlock();
    }
  }
}

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

/**
 * Remove the first {@link ByteBuf} from the queue.
 * @param aggregatePromise used to aggregate the promises and listeners for the returned buffer.
 * @return the first {@link ByteBuf} from the queue.
 */
public final ByteBuf removeFirst(ChannelPromise aggregatePromise) {
  Object entry = bufAndListenerPairs.poll();
  if (entry == null) {
    return null;
  }
  assert entry instanceof ByteBuf;
  ByteBuf result = (ByteBuf) entry;
  decrementReadableBytes(result.readableBytes());
  entry = bufAndListenerPairs.peek();
  if (entry instanceof ChannelFutureListener) {
    aggregatePromise.addListener((ChannelFutureListener) entry);
    bufAndListenerPairs.poll();
  }
  return result;
}

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

private void processAtomEnded(long atomEndPosition) throws ParserException {
 while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
  onContainerAtomRead(containerAtoms.pop());
 }
 enterReadingAtomHeaderState();
}

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

public void pushNdc(String message) {
  ArrayDeque<Entry> stack = ndcStack.get();
  if (stack == null) {
    stack = new ArrayDeque<Entry>();
    ndcStack.set(stack);
  }
  stack.push(stack.isEmpty() ? new Entry(message) : new Entry(stack.peek(), message));
}

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

/**
 * Remove the first {@link ByteBuf} from the queue.
 * @param aggregatePromise used to aggregate the promises and listeners for the returned buffer.
 * @return the first {@link ByteBuf} from the queue.
 */
public final ByteBuf removeFirst(ChannelPromise aggregatePromise) {
  Object entry = bufAndListenerPairs.poll();
  if (entry == null) {
    return null;
  }
  assert entry instanceof ByteBuf;
  ByteBuf result = (ByteBuf) entry;
  decrementReadableBytes(result.readableBytes());
  entry = bufAndListenerPairs.peek();
  if (entry instanceof ChannelFutureListener) {
    aggregatePromise.addListener((ChannelFutureListener) entry);
    bufAndListenerPairs.poll();
  }
  return result;
}

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

private void processAtomEnded(long atomEndPosition) throws ParserException {
 while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
  Atom.ContainerAtom containerAtom = containerAtoms.pop();
  if (containerAtom.type == Atom.TYPE_moov) {
   // We've reached the end of the moov atom. Process it and prepare to read samples.
   processMoovAtom(containerAtom);
   containerAtoms.clear();
   parserState = STATE_READING_SAMPLE;
  } else if (!containerAtoms.isEmpty()) {
   containerAtoms.peek().add(containerAtom);
  }
 }
 if (parserState != STATE_READING_SAMPLE) {
  enterReadingAtomHeaderState();
 }
}

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

private void onContainerAtomRead(ContainerAtom container) throws ParserException {
 if (container.type == Atom.TYPE_moov) {
  onMoovContainerAtomRead(container);
 } else if (container.type == Atom.TYPE_moof) {
  onMoofContainerAtomRead(container);
 } else if (!containerAtoms.isEmpty()) {
  containerAtoms.peek().add(container);
 }
}

代码示例来源:origin: ReactiveX/RxJava

C b = bs.peek();

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

/**
 * Remove the first {@link ByteBuf} from the queue.
 * @param aggregatePromise used to aggregate the promises and listeners for the returned buffer.
 * @return the first {@link ByteBuf} from the queue.
 */
public final ByteBuf removeFirst(ChannelPromise aggregatePromise) {
  Object entry = bufAndListenerPairs.poll();
  if (entry == null) {
    return null;
  }
  assert entry instanceof ByteBuf;
  ByteBuf result = (ByteBuf) entry;
  decrementReadableBytes(result.readableBytes());
  entry = bufAndListenerPairs.peek();
  if (entry instanceof ChannelFutureListener) {
    aggregatePromise.addListener((ChannelFutureListener) entry);
    bufAndListenerPairs.poll();
  }
  return result;
}

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

private void onLeafAtomRead(LeafAtom leaf, long inputPosition) throws ParserException {
 if (!containerAtoms.isEmpty()) {
  containerAtoms.peek().add(leaf);
 } else if (leaf.type == Atom.TYPE_sidx) {
  Pair<Long, ChunkIndex> result = parseSidx(leaf.data, inputPosition);
  segmentIndexEarliestPresentationTimeUs = result.first;
  extractorOutput.seekMap(result.second);
  haveOutputSeekMap = true;
 } else if (leaf.type == Atom.TYPE_emsg) {
  onEmsgLeafAtomRead(leaf.data);
 }
}

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

C b = bs.peek();

代码示例来源:origin: Graylog2/graylog2-server

@Override
public void exitIdentifier(RuleLangParser.IdentifierContext ctx) {
  // unquote identifier if necessary
  final String identifierName = unquote(ctx.Identifier().getText(), '`');
  if (!isIdIsFieldAccess.peek() && !definedVars.contains(identifierName)) {
    parseContext.addError(new UndeclaredVariable(ctx));
  }
  final Expression expr;
  String type;
  // if the identifier is also a declared variable name prefer the variable
  if (isIdIsFieldAccess.peek() && !definedVars.contains(identifierName)) {
    expr = new FieldRefExpression(ctx.getStart(), identifierName, parseContext.getDefinedVar(identifierName));
    type = "FIELDREF";
  } else {
    expr = new VarRefExpression(ctx.getStart(), identifierName, parseContext.getDefinedVar(identifierName));
    type = "VARREF";
  }
  log.trace("{}: ctx {} => {}", type, ctx, expr);
  exprs.put(ctx, expr);
}

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

/**
 * Processes the atom payload. If {@link #atomData} is null and the size is at or above the
 * threshold {@link #RELOAD_MINIMUM_SEEK_DISTANCE}, {@code true} is returned and the caller should
 * restart loading at the position in {@code positionHolder}. Otherwise, the atom is read/skipped.
 */
private boolean readAtomPayload(ExtractorInput input, PositionHolder positionHolder)
  throws IOException, InterruptedException {
 long atomPayloadSize = atomSize - atomHeaderBytesRead;
 long atomEndPosition = input.getPosition() + atomPayloadSize;
 boolean seekRequired = false;
 if (atomData != null) {
  input.readFully(atomData.data, atomHeaderBytesRead, (int) atomPayloadSize);
  if (atomType == Atom.TYPE_ftyp) {
   isQuickTime = processFtypAtom(atomData);
  } else if (!containerAtoms.isEmpty()) {
   containerAtoms.peek().add(new Atom.LeafAtom(atomType, atomData));
  }
 } else {
  // We don't need the data. Skip or seek, depending on how large the atom is.
  if (atomPayloadSize < RELOAD_MINIMUM_SEEK_DISTANCE) {
   input.skipFully((int) atomPayloadSize);
  } else {
   positionHolder.position = input.getPosition() + atomPayloadSize;
   seekRequired = true;
  }
 }
 processAtomEnded(atomEndPosition);
 return seekRequired && parserState != STATE_READING_SAMPLE;
}

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

private TerminalAutoCompleteMatches traverseArguments(TerminalCommand command, TerminalAutoCompleteMatches matches, ArrayDeque<String> inputArguments) {
  if (command.getArguments() != null) {
    for (TerminalCommand argument : command.getArguments()) {
      if (!inputArguments.isEmpty()) {
        String inputArgument = inputArguments.peek();
        if (isPartialMatch(argument, inputArgument)) {
          if (isExactMatch(argument, inputArgument) && argument.hasArguments()) {
            matches.extendBaseCommand(argument);
            inputArguments.removeFirst();
            return traverseArguments(argument, matches, inputArguments);
          }
          matches.addMatch(argument);
        }
      }
      else {
        matches.addMatch(argument);
      }
    }
  }
  return matches;
}

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

endPosition = containerAtoms.peek().endPosition;

相关文章

微信公众号

最新文章

更多