Package org.pepsoft.util
Class LifoBlockingDeque<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.LinkedBlockingDeque<E>
org.pepsoft.util.LifoBlockingDeque<E>
- Type Parameters:
E- The element type of the queue.
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,BlockingDeque<E>,BlockingQueue<E>,Deque<E>,Queue<E>
A
LinkedBlockingDeque of which the non ordered element addition methods add elements at the start of the
queue rather than the end. When used as a Queue this will result in a LIFO (last in first out) queue.
Note: that this means it breaks the contract of Deque.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd an element to the start of the queue.booleanAdd an element to the start of the queue, if there is space, without blocking.booleanAdd an element to the start of the queue, if there is space, waiting for the specified amount of time if necessary for space to become available.voidAdd an element to the start of the queue, waiting indefinitely for space to become available if necessary.Methods inherited from class java.util.concurrent.LinkedBlockingDeque
addAll, addFirst, addLast, clear, contains, descendingIterator, drainTo, drainTo, element, forEach, getFirst, getLast, iterator, offerFirst, offerFirst, offerLast, offerLast, peek, peekFirst, peekLast, poll, poll, pollFirst, pollFirst, pollLast, pollLast, pop, push, putFirst, putLast, remainingCapacity, remove, remove, removeAll, removeFirst, removeFirstOccurrence, removeIf, removeLast, removeLastOccurrence, retainAll, size, spliterator, take, takeFirst, takeLast, toArray, toArray, toStringMethods inherited from class java.util.AbstractCollection
containsAll, isEmptyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
-
Constructor Details
-
LifoBlockingDeque
public LifoBlockingDeque()
-
-
Method Details
-
add
Add an element to the start of the queue.- Specified by:
addin interfaceBlockingDeque<E>- Specified by:
addin interfaceBlockingQueue<E>- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceDeque<E>- Specified by:
addin interfaceQueue<E>- Overrides:
addin classLinkedBlockingDeque<E>- Parameters:
e- The element to add.- Returns:
true- Throws:
IllegalStateException- If there is no space on the queue.
-
offer
Add an element to the start of the queue, if there is space, without blocking.- Specified by:
offerin interfaceBlockingDeque<E>- Specified by:
offerin interfaceBlockingQueue<E>- Specified by:
offerin interfaceDeque<E>- Specified by:
offerin interfaceQueue<E>- Overrides:
offerin classLinkedBlockingDeque<E>- Parameters:
e- The element to add.- Returns:
trueif the element was added orfalseif there was no space.
-
offer
Add an element to the start of the queue, if there is space, waiting for the specified amount of time if necessary for space to become available.- Specified by:
offerin interfaceBlockingDeque<E>- Specified by:
offerin interfaceBlockingQueue<E>- Overrides:
offerin classLinkedBlockingDeque<E>- Parameters:
e- The element to add.timeout- The maximum amount of time to wait for space to become available.unit- The unit oftimeout.- Returns:
trueif the element was added orfalseif there was no space after waiting the specified amount of time.- Throws:
InterruptedException- If the thread was interrupted while waiting for space to become available.
-
put
Add an element to the start of the queue, waiting indefinitely for space to become available if necessary.- Specified by:
putin interfaceBlockingDeque<E>- Specified by:
putin interfaceBlockingQueue<E>- Overrides:
putin classLinkedBlockingDeque<E>- Parameters:
e- The element to add.- Throws:
InterruptedException- If the thread was interrupted while waiting for space to become available.
-