/** * 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(); }
/** * 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(); } }
public int front() { return queue.getFirst().intValue(); }
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); }
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; }
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(); } }
while (true) { if (waitingSessions.getFirst() == session) { if (doLock2(session, lockMode, exclusive)) { return;
while (true) { if (waitingSessions.getFirst() == session) { if (doLock2(session, lockMode, exclusive)) { return;
/** * 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() ); } } } }
/** * 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() ); } } } }
/** * 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(); }
/** Returns the case section of the next finally block. */ @Nullable private Case getNextFinallyCase() { return finallyCases.isEmpty() ? null : finallyCases.getFirst(); }
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; }
private void nextToken() { tokens.pop(); if (tokens.isEmpty()) lookahead = new Token(TokenType.END, ""); else lookahead = tokens.getFirst(); } }
/** 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)); } }
@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); } }
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(); } }