Tabnine Logo
Deque
Code IndexAdd Tabnine to your IDE (free)

How to use
Deque
in
java.util

Best Java code snippets using java.util.Deque (Showing top 20 results out of 19,917)

origin: square/okhttp

 @Override public List<Cookie> loadForRequest(HttpUrl url) {
  if (requestCookies.isEmpty()) return Collections.emptyList();
  return requestCookies.removeFirst();
 }
}
origin: spring-projects/spring-framework

public void pushActiveContextObject(TypedValue obj) {
  if (this.contextObjects == null) {
    this.contextObjects = new ArrayDeque<>();
  }
  this.contextObjects.push(obj);
}
origin: spring-projects/spring-framework

/**
 * Exit a compilation scope, usually after a nested expression has been evaluated. For
 * example after an argument for a method invocation has been evaluated this method
 * returns us to the previous (outer) scope.
 */
public void exitCompilationScope() {
  this.compilationScopes.pop();
}
origin: iluwatar/java-design-patterns

/**
 * Undo last spell
 */
public void undoLastSpell() {
 if (!undoStack.isEmpty()) {
  Command previousSpell = undoStack.pollLast();
  redoStack.offerLast(previousSpell);
  LOGGER.info("{} undoes {}", this, previousSpell);
  previousSpell.undo();
 }
}
origin: skylot/jadx

private void store(Level level, String msg) {
  buffer.addLast(new LogEvent(level, msg));
  if (buffer.size() > BUFFER_SIZE) {
    buffer.pollFirst();
  }
}
origin: google/guava

public void testHoldsLockOnAllOperations() {
 create().element();
 create().offer("foo");
 create().peek();
 create().poll();
 create().remove();
 create().add("foo");
 create().addAll(ImmutableList.of("foo"));
 create().clear();
 create().contains("foo");
 create().containsAll(ImmutableList.of("foo"));
 create().equals(new ArrayDeque<>(ImmutableList.of("foo")));
 create().hashCode();
 create().isEmpty();
 create().iterator();
 create().remove("foo");
 create().removeAll(ImmutableList.of("foo"));
 create().retainAll(ImmutableList.of("foo"));
 create().size();
 create().toArray();
 create().toArray(new String[] {"foo"});
 create().addFirst("e");
 create().addLast("e");
 create().offerFirst("e");
 create().offerLast("e");
 create().removeFirst();
 create().removeLast();
 create().pollFirst();
 create().pollLast();
 create().getFirst();
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: neo4j/neo4j

private void writeValue( Object value )
{
  assert !stack.isEmpty();
  Writer head = stack.peek();
  head.write( value );
}
origin: apache/kafka

/**
 * Can we send more requests to this node?
 *
 * @param node Node in question
 * @return true iff we have no requests still being sent to the given node
 */
public boolean canSendMore(String node) {
  Deque<NetworkClient.InFlightRequest> queue = requests.get(node);
  return queue == null || queue.isEmpty() ||
      (queue.peekFirst().send.completed() && queue.size() < this.maxInFlightRequestsPerConnection);
}
origin: skylot/jadx

public String getFullName() {
  if (cachedPackageFullName == null) {
    Deque<PackageNode> pp = getParentPackages();
    StringBuilder result = new StringBuilder();
    result.append(pp.pop().getName());
    while (!pp.isEmpty()) {
      result.append(SEPARATOR_CHAR);
      result.append(pp.pop().getName());
    }
    cachedPackageFullName = result.toString();
  }
  return cachedPackageFullName;
}
origin: google/guava

/**
 * An analogue of {@link java.util.function.DoubleFunction} also accepting an index.
 *
 * <p>This interface is only intended for use by callers of {@link #mapWithIndex(DoubleStream,
 * DoubleFunctionWithIndex)}.
 *
 * @since 21.0
 */
@Beta
public interface DoubleFunctionWithIndex<R> {
 /** Applies this function to the given argument and its index within a stream. */
 R apply(double from, long index);
}
origin: square/okhttp

/** Used by {@code Call#execute} to signal it is in-flight. */
synchronized void executed(RealCall call) {
 runningSyncCalls.add(call);
}
origin: skylot/jadx

public void push(IRegion region) {
  stack.push(curState);
  if (stack.size() > REGIONS_STACK_LIMIT) {
    throw new JadxOverflowException("Regions stack size limit reached");
  }
  curState = curState.copy();
  curState.region = region;
  if (DEBUG) {
    LOG.debug("Stack push: {}: {}", size(), curState);
  }
}
origin: spring-projects/spring-framework

/**
 * Return the current number of statements or statement parameters
 * in the queue.
 */
public int getQueueCount() {
  return this.parameterQueue.size();
}
origin: spring-projects/spring-framework

private boolean inTag() {
  return !this.tagState.isEmpty();
}
origin: apache/kafka

/**
 * Attempt to ensure we have at least the requested number of bytes of memory for allocation by deallocating pooled
 * buffers (if needed)
 */
private void freeUp(int size) {
  while (!this.free.isEmpty() && this.nonPooledAvailableMemory < size)
    this.nonPooledAvailableMemory += this.free.pollLast().capacity();
}
origin: checkstyle/checkstyle

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

synchronized void enqueue(AsyncCall call) {
 if (runningAsyncCalls.size() < maxRequests && runningCallsForHost(call) < maxRequestsPerHost) {
  runningAsyncCalls.add(call);
  executorService().execute(call);
 } else {
  readyAsyncCalls.add(call);
 }
}
origin: google/j2objc

@Override
public void addFirst(E e) {
 synchronized (mutex) {
  delegate().addFirst(e);
 }
}
origin: spring-projects/spring-framework

@Nullable
public CompositeComponentDefinition getContainingComponent() {
  return this.containingComponents.peek();
}
java.utilDeque

Javadoc

A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue" and is usually pronounced "deck". Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit.

This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element. Each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (either null or false, depending on the operation). The latter form of the insert operation is designed specifically for use with capacity-restricted Deque implementations; in most implementations, insert operations cannot fail.

The twelve methods described above are summarized in the following table:

First Element (Head) Last Element (Tail)
Throws exception Special value Throws exception Special value
Insert #addFirst #offerFirst #addLast #offerLast
Remove #removeFirst #pollFirst #removeLast #pollLast
Examine #getFirst #peekFirst #getLast #peekLast

This interface extends the Queue interface. When a deque is used as a queue, FIFO (First-In-First-Out) behavior results. Elements are added at the end of the deque and removed from the beginning. The methods inherited from the Queue interface are precisely equivalent to Deque methods as indicated in the following table:

Queue Method Equivalent Deque Method
java.util.Queue#add #addLast
java.util.Queue#offer #offerLast
java.util.Queue#remove #removeFirst
java.util.Queue#poll #pollFirst
java.util.Queue#element #getFirst
java.util.Queue#peek #peek

Deques can also be used as LIFO (Last-In-First-Out) stacks. This interface should be used in preference to the legacy Stack class. When a deque is used as a stack, elements are pushed and popped from the beginning of the deque. Stack methods are precisely equivalent to Deque methods as indicated in the table below:

Stack Method Equivalent Deque Method
#push #addFirst
#pop #removeFirst
#peek #peekFirst

Note that the #peek method works equally well when a deque is used as a queue or a stack; in either case, elements are drawn from the beginning of the deque.

This interface provides two methods to remove interior elements, #removeFirstOccurrence and #removeLastOccurrence.

Unlike the List interface, this interface does not provide support for indexed access to elements.

While Deque implementations are not strictly required to prohibit the insertion of null elements, they are strongly encouraged to do so. Users of any Deque implementations that do allow null elements are strongly encouraged not to take advantage of the ability to insert nulls. This is so because null is used as a special return value by various methods to indicated that the deque is empty.

Deque implementations generally do not define element-based versions of the equals and hashCode methods, but instead inherit the identity-based versions from class Object.

Most used methods

  • isEmpty
  • push
    Pushes an element onto the stack represented by this deque (in other words, at the head of this dequ
  • pop
    Pops an element from the stack represented by this deque. In other words, removes and returns the fi
  • add
    Inserts the specified element into the queue represented by this deque (in other words, at the tail
  • size
    Returns the number of elements in this deque.
  • peek
    Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the
  • addFirst
    Inserts the specified element at the front of this deque if it is possible to do so immediately with
  • addLast
    Inserts the specified element at the end of this deque if it is possible to do so immediately withou
  • removeFirst
    Retrieves and removes the first element of this deque. This method differs from #pollFirst only in t
  • clear
  • removeLast
    Retrieves and removes the last element of this deque. This method differs from #pollLast only in tha
  • poll
    Retrieves and removes the head of the queue represented by this deque (in other words, the first ele
  • removeLast,
  • poll,
  • pollFirst,
  • getLast,
  • getFirst,
  • iterator,
  • peekFirst,
  • remove,
  • peekLast,
  • pollLast

Popular in Java

  • Start an intent from android
  • getResourceAsStream (ClassLoader)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onCreateOptionsMenu (Activity)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now