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

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

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

ArrayDeque.getFirst介绍

暂无

代码示例

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

/**
 * Retrieves, but does not remove, the head of the queue represented by
 * this deque.  This method differs from {@link #peek peek} only in
 * that it throws an exception if this deque is empty.
 *
 * <p>This method is equivalent to {@link #getFirst}.
 *
 * @return the head of the queue represented by this deque
 * @throws NoSuchElementException {@inheritDoc}
 */
public E element() {
  return getFirst();
}

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

/**
 * Returns the queue's next element without removing it, if the queue is non-empty.
 * Otherwise, returns null.
 *
 * <p>The method throws an {@code IllegalStateException} if the queue is closed.
 * Checking whether the queue is open and getting the next element is one atomic operation.
 *
 * <p>This method never blocks.
 *
 * @return The queue's next element, or null, if the queue is empty.
 * @throws IllegalStateException Thrown, if the queue is closed.
 */
public E peek() {
  lock.lock();
  try {
    if (open) {
      if (elements.size() > 0) {
        return elements.getFirst();
      } else {
        return null;
      }
    } else {
      throw new IllegalStateException("queue is closed");
    }
  } finally {
    lock.unlock();
  }
}

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

public int front() {
 return queue.getFirst().intValue();
}

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

private long applySpeedup(long positionUs) {
 @Nullable PlaybackParametersCheckpoint checkpoint = null;
 while (!playbackParametersCheckpoints.isEmpty()
   && positionUs >= playbackParametersCheckpoints.getFirst().positionUs) {
  checkpoint = playbackParametersCheckpoints.remove();
 }
 if (checkpoint != null) {
  // We are playing (or about to play) media with the new playback parameters, so update them.
  playbackParameters = checkpoint.playbackParameters;
  playbackParametersPositionUs = checkpoint.positionUs;
  playbackParametersOffsetUs = checkpoint.mediaTimeUs - startMediaTimeUs;
 }
 if (playbackParameters.speed == 1f) {
  return positionUs + playbackParametersOffsetUs - playbackParametersPositionUs;
 }
 if (playbackParametersCheckpoints.isEmpty()) {
  return playbackParametersOffsetUs
    + audioProcessorChain.getMediaDuration(positionUs - playbackParametersPositionUs);
 }
 // We are playing data at a previous playback speed, so fall back to multiplying by the speed.
 return playbackParametersOffsetUs
   + Util.getMediaDurationForPlayoutDuration(
     positionUs - playbackParametersPositionUs, playbackParameters.speed);
}

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

public void putFirstOverflow(Integer eventCount) {
 if ((queue.peekFirst() == null) || queue.getFirst().intValue() > 0) {
  queue.addFirst(new MutableInteger(-eventCount));
 } else {
  queue.getFirst().add(-eventCount);
 }
 overflowCounter += eventCount;
}

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

public void putFirstPrimary(Integer eventCount) {
 if ((queue.peekFirst() == null) || queue.getFirst().intValue() < 0) {
  queue.addFirst(new MutableInteger(eventCount));
 } else {
  queue.getFirst().add(eventCount);
 }
}

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

public void takeOverflow(int takeCount) {
 MutableInteger headValue = queue.getFirst();
 if (headValue.intValue() > -takeCount) {
  throw new IllegalStateException("Cannot take " + takeCount + " from "
    + headValue.intValue() + " in DrainOrder Queue head ");
 }
 headValue.add(takeCount);
 if (headValue.intValue() == 0) {
  queue.removeFirst();
 }
 overflowCounter -= takeCount;
}

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

public void takePrimary(int takeCount) {
 MutableInteger headValue = queue.getFirst();
 // this condition is optimization to avoid redundant conversions of
 // int -> Integer -> string in hot path
 if (headValue.intValue() < takeCount) {
  throw new IllegalStateException("Cannot take " + takeCount +
    " from " + headValue.intValue() + " in DrainOrder Queue");
 }
 headValue.add(-takeCount);
 if (headValue.intValue() == 0) {
  queue.removeFirst();
 }
}

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

while (true) {
  if (waitingSessions.getFirst() == session) {
    if (doLock2(session, lockMode, exclusive)) {
      return;

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

while (true) {
  if (waitingSessions.getFirst() == session) {
    if (doLock2(session, lockMode, exclusive)) {
      return;

代码示例来源:origin: Sable/soot

&& otherHierarchy.getFirst() == thisHierarchy.getFirst()) {
commonClass = otherHierarchy.removeFirst();
thisHierarchy.removeFirst();

代码示例来源:origin: SpigotMC/BungeeCord

/**
 * Handles the Forge packet.
 *
 * @param message The Forge Handshake packet to handle.
 */
public void handle(PluginMessage message) throws IllegalArgumentException
{
  if ( !message.getTag().equalsIgnoreCase( ForgeConstants.FML_HANDSHAKE_TAG ) )
  {
    throw new IllegalArgumentException( "Expecting a Forge Handshake packet." );
  }
  message.setAllowExtendedPacket( true ); // FML allows extended packets so this must be enabled
  ForgeClientHandshakeState prevState = state;
  Preconditions.checkState( packetQueue.size() < 128, "Forge packet queue too big!" );
  packetQueue.add( message );
  state = state.send( message, con );
  if ( state != prevState ) // state finished, send packets
  {
    synchronized ( packetQueue )
    {
      while ( !packetQueue.isEmpty() )
      {
        ForgeLogger.logClient( ForgeLogger.LogDirection.SENDING, prevState.name(), packetQueue.getFirst() );
        con.getForgeServerHandler().receive( packetQueue.removeFirst() );
      }
    }
  }
}

代码示例来源:origin: SpigotMC/BungeeCord

/**
 * Handles any {@link PluginMessage} that contains a FML Handshake or Forge
 * Register.
 *
 * @param message The message to handle.
 * @throws IllegalArgumentException If the wrong packet is sent down.
 */
public void handle(PluginMessage message) throws IllegalArgumentException
{
  if ( !message.getTag().equalsIgnoreCase( ForgeConstants.FML_HANDSHAKE_TAG ) && !message.getTag().equalsIgnoreCase( ForgeConstants.FORGE_REGISTER ) )
  {
    throw new IllegalArgumentException( "Expecting a Forge REGISTER or FML Handshake packet." );
  }
  message.setAllowExtendedPacket( true ); // FML allows extended packets so this must be enabled
  ForgeServerHandshakeState prevState = state;
  packetQueue.add( message );
  state = state.send( message, con );
  if ( state != prevState ) // send packets
  {
    synchronized ( packetQueue )
    {
      while ( !packetQueue.isEmpty() )
      {
        ForgeLogger.logServer( LogDirection.SENDING, prevState.name(), packetQueue.getFirst() );
        con.getForgeClientHandler().receive( packetQueue.removeFirst() );
      }
    }
  }
}

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

/**
 * Retrieves, but does not remove, the head of the queue represented by
 * this deque.  This method differs from {@link #peek peek} only in
 * that it throws an exception if this deque is empty.
 *
 * <p>This method is equivalent to {@link #getFirst}.
 *
 * @return the head of the queue represented by this deque
 * @throws NoSuchElementException {@inheritDoc}
 */
public E element() {
  return getFirst();
}

代码示例来源:origin: com.google.javascript/closure-compiler

/** Returns the case section of the next finally block. */
@Nullable
private Case getNextFinallyCase() {
 return finallyCases.isEmpty() ? null : finallyCases.getFirst();
}

代码示例来源:origin: espertechinc/esper

public PropertyTokenParser(ArrayDeque<Token> tokens, boolean rootedDynamic) {
  if (tokens.isEmpty()) {
    throw new PropertyParseNodepException("Empty property name");
  }
  lookahead = tokens.getFirst();
  this.tokens = tokens;
  this.dynamic = rootedDynamic;
}

代码示例来源:origin: espertechinc/esper

private void nextToken() {
    tokens.pop();
    if (tokens.isEmpty())
      lookahead = new Token(TokenType.END, "");
    else
      lookahead = tokens.getFirst();
  }
}

代码示例来源:origin: com.google.javascript/closure-compiler

/** Adds references to catch and finally blocks to the transpilation context. */
private void addCatchFinallyCases(@Nullable Case catchCase, @Nullable Case finallyCase) {
 if (finallyCase != null) {
  if (!catchCases.isEmpty()) {
   ++catchCases.getFirst().finallyBlocks;
  }
  finallyCases.addFirst(finallyCase);
 }
 if (catchCase != null) {
  catchCases.addFirst(new CatchCase(catchCase));
 }
}

代码示例来源:origin: vidstige/jadb

@Override
  public void write(int c) throws IOException {
    if (!lookback().isEmpty()) {
      Byte last = lookback().getFirst();
      if (last != null && last == 0x0d && c == 0x0a) {
        unwrite();
      }
    }
    super.write(c);
  }
}

代码示例来源:origin: org.apache.flume.flume-ng-channels/flume-spillable-memory-channel

public void takePrimary(int takeCount) {
 MutableInteger headValue = queue.getFirst();
 // this condition is optimization to avoid redundant conversions of
 // int -> Integer -> string in hot path
 if (headValue.intValue() < takeCount) {
  throw new IllegalStateException("Cannot take " + takeCount +
    " from " + headValue.intValue() + " in DrainOrder Queue");
 }
 headValue.add(-takeCount);
 if (headValue.intValue() == 0) {
  queue.removeFirst();
 }
}

相关文章