FastRemovalDequeue (Apache Tomcat 9.0.102 API Documentation)
Description: declaration: package: org.apache.jasper.util, class: FastRemovalDequeue

Package org.apache.jasper.util

# Class FastRemovalDequeue<T>

java.lang.Object
org.apache.jasper.util.FastRemovalDequeue<T>

Type Parameters:
  `T` - The type of elements in the queue

public class FastRemovalDequeue<T> extends Object
The FastRemovalDequeue is a Dequeue that supports constant time removal of entries. This is achieved by using a doubly linked list and wrapping any object added to the collection with an Entry type, that is returned to the consumer. When removing an object from the list, the consumer provides this Entry object. The Entry type is nearly opaque to the consumer of the queue. The only public member is the getter for any object displaced when adding a new object to the queue. This can be used to destroy that object. The Entry object contains the links pointing to the neighbours in the doubly linked list, so that removal of an Entry does not need to search for it but instead can be done in constant time. The implementation is fully thread-safe. Invalidation of Entry objects during removal from the list is done by setting their "valid" field to false. All public methods which take Entry objects as arguments are NOP if the entry is no longer valid. A typical use of the FastRemovalDequeue is a list of entries in sorted order, where the sort position of an object will only switch to first or last. Whenever the sort position needs to change, the consumer can remove the object and reinsert it in front or at the end in constant time. So keeping the list sorted is very cheap.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `FastRemovalDequeue.Entry`
  Implementation of a doubly linked list entry.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected FastRemovalDequeue<T>.Entry`
  `first`
  First element of the queue.
  `protected FastRemovalDequeue<T>.Entry`
  `last`
  Last element of the queue.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FastRemovalDequeue(int maxSize)`
  Initialize empty queue.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getSize()`
  Retrieve the size of the list.
  `void`
  `moveFirst(FastRemovalDequeue<T>.Entry element)`
  Moves the element in front.
  `void`
  `moveLast(FastRemovalDequeue<T>.Entry element)`
  Moves the element to the back.
  `T`
  `pop()`
  Removes the last element of the list and returns its content.
  `FastRemovalDequeue<T>.Entry`
  `push(T object)`
  Adds an object to the start of the list and returns the entry created for said object.
  `void`
  `remove(FastRemovalDequeue<T>.Entry element)`
  Removes any element of the list and returns its content.
  `FastRemovalDequeue<T>.Entry`
  `unpop(T object)`
  Adds an object to the end of the list and returns the entry created for said object.
  `T`
  `unpush()`
  Removes the first element of the list and returns its content.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### first

    protected FastRemovalDequeue<T>.Entry first
    First element of the queue.

  - ### last

    protected FastRemovalDequeue<T>.Entry last
    Last element of the queue.

- ## Constructor Details

  - ### FastRemovalDequeue

    public FastRemovalDequeue(int maxSize)
    Initialize empty queue.
    Parameters:
      `maxSize` - The maximum size to which the queue will be allowed to grow

- ## Method Details

  - ### getSize

    public int getSize()
    Retrieve the size of the list. This method also needs to be externally synchronized to ensure correct publication of changes.
    Returns:
      the size of the list.

  - ### push

    public FastRemovalDequeue<T>.Entry push(T object)
    Adds an object to the start of the list and returns the entry created for said object. The entry can later be reused for moving the entry.
    Parameters:
      `object` - the object to prepend to the start of the list.
    Returns:
      an entry for use when the object should be moved.

  - ### unpop

    public FastRemovalDequeue<T>.Entry unpop(T object)
    Adds an object to the end of the list and returns the entry created for said object. The entry can later be reused for moving the entry.
    Parameters:
      `object` - the object to append to the end of the list.
    Returns:
      an entry for use when the object should be moved.

  - ### unpush

    public T unpush()
    Removes the first element of the list and returns its content.
    Returns:
      the content of the first element of the list.

  - ### pop

    public T pop()
    Removes the last element of the list and returns its content.
    Returns:
      the content of the last element of the list.

  - ### remove

    public void remove(FastRemovalDequeue<T>.Entry element)
    Removes any element of the list and returns its content.
    Parameters:
      `element` - The element to remove

  - ### moveFirst

    public void moveFirst(FastRemovalDequeue<T>.Entry element)
    Moves the element in front. Could also be implemented as remove() and push(), but explicitly coding might be a bit faster.
    Parameters:
      `element` - the entry to move in front.

  - ### moveLast

    public void moveLast(FastRemovalDequeue<T>.Entry element)
    Moves the element to the back. Could also be implemented as remove() and unpop(), but explicitly coding might be a bit faster.
    Parameters:
      `element` - the entry to move to the back.