Package io.microsphere.collection
Class UnmodifiableDeque<E>
- java.lang.Object
-
- io.microsphere.collection.UnmodifiableQueue<E>
-
- io.microsphere.collection.UnmodifiableDeque<E>
-
- Type Parameters:
E
- the type of elements held in this deque
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Deque<E>
,java.util.Queue<E>
public class UnmodifiableDeque<E> extends UnmodifiableQueue<E> implements java.util.Deque<E>, java.io.Serializable
An unmodifiable view of aDeque
. This implementation decorates a given deque and prevents any modification operations from succeeding. All mutation methods, such asaddFirst(E)
,addLast(E)
,push(E)
, and others, throw anUnsupportedOperationException
.The behavior of this class is undefined if the underlying deque is modified directly while this view exists. It is intended to be used for creating immutable snapshots of deques where modification attempts are not allowed.
Example Usage
Deque<String> mutableDeque = new LinkedList<>(); mutableDeque.addFirst("World"); Deque<String> unmodifiableDeque = new UnmodifiableDeque<>(mutableDeque); unmodifiableDeque.addFirst("Hello"); // throws UnsupportedOperationException
This class is serializable if the underlying deque is serializable.
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
Deque
,CollectionUtils.unmodifiableIterator(Iterator)
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description UnmodifiableDeque(java.util.Deque<E> deque)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFirst(E e)
void
addLast(E e)
java.util.Iterator<E>
descendingIterator()
E
getFirst()
E
getLast()
boolean
offerFirst(E e)
boolean
offerLast(E e)
E
peekFirst()
E
peekLast()
E
pollFirst()
E
pollLast()
E
pop()
void
push(E e)
E
removeFirst()
boolean
removeFirstOccurrence(java.lang.Object o)
E
removeLast()
boolean
removeLastOccurrence(java.lang.Object o)
-
Methods inherited from class io.microsphere.collection.UnmodifiableQueue
add, addAll, clear, contains, containsAll, element, equals, forEach, hashCode, isEmpty, iterator, offer, parallelStream, peek, poll, remove, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
-
-
-
-
Constructor Detail
-
UnmodifiableDeque
public UnmodifiableDeque(java.util.Deque<E> deque)
-
-
Method Detail
-
removeFirstOccurrence
public boolean removeFirstOccurrence(java.lang.Object o)
- Specified by:
removeFirstOccurrence
in interfacejava.util.Deque<E>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object o)
- Specified by:
removeLastOccurrence
in interfacejava.util.Deque<E>
-
-