Package io.microsphere.collection
Class UnmodifiableQueue<E>
- java.lang.Object
-
- io.microsphere.collection.UnmodifiableQueue<E>
-
- Type Parameters:
E
- the type of elements held in this queue
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Queue<E>
- Direct Known Subclasses:
UnmodifiableDeque
public class UnmodifiableQueue<E> extends java.lang.Object implements java.util.Queue<E>, java.io.Serializable
An unmodifiable view of aQueue
. This implementation decorates a given queue and prevents any modification operations from succeeding. All mutation methods, such asadd(E)
,remove(java.lang.Object)
,offer(E)
, and others, throw anUnsupportedOperationException
.The behavior of this class is undefined if the underlying queue is modified directly while this view exists. It is intended to be used for creating immutable snapshots of queues where modification attempts are not allowed.
Example Usage
Queue<String> mutableQueue = new LinkedList<>(); mutableQueue.add("Hello"); Queue<String> unmodifiableQueue = new UnmodifiableQueue<>(mutableQueue); unmodifiableQueue.add("World"); // throws UnsupportedOperationException
This class is serializable if the underlying queue is serializable.
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
Queue
,CollectionUtils.unmodifiableIterator(Iterator)
, Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
boolean
addAll(java.util.Collection<? extends E> c)
void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
E
element()
boolean
equals(java.lang.Object o)
void
forEach(java.util.function.Consumer<? super E> action)
int
hashCode()
boolean
isEmpty()
java.util.Iterator<E>
iterator()
boolean
offer(E e)
java.util.stream.Stream<E>
parallelStream()
E
peek()
E
poll()
E
remove()
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
removeIf(java.util.function.Predicate<? super E> filter)
boolean
retainAll(java.util.Collection<?> c)
int
size()
java.util.Spliterator<E>
spliterator()
java.util.stream.Stream<E>
stream()
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
java.lang.String
toString()
-
-
-
Method Detail
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<E>
-
iterator
public java.util.Iterator<E> iterator()
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfacejava.util.Collection<E>
-
add
public boolean add(E e)
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<E>
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAll
in interfacejava.util.Collection<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<E>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
removeIf
in interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAll
in interfacejava.util.Collection<E>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<E>
-
spliterator
public java.util.Spliterator<E> spliterator()
-
stream
public java.util.stream.Stream<E> stream()
- Specified by:
stream
in interfacejava.util.Collection<E>
-
parallelStream
public java.util.stream.Stream<E> parallelStream()
- Specified by:
parallelStream
in interfacejava.util.Collection<E>
-
forEach
public void forEach(java.util.function.Consumer<? super E> action)
- Specified by:
forEach
in interfacejava.lang.Iterable<E>
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Collection<E>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<E>
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-