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
@Immutable 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 UnsupportedOperationExceptionThis 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 booleanadd(E e)booleanaddAll(java.util.Collection<? extends E> c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)Eelement()booleanequals(java.lang.Object o)voidforEach(java.util.function.Consumer<? super E> action)inthashCode()booleanisEmpty()java.util.Iterator<E>iterator()booleanoffer(E e)java.util.stream.Stream<E>parallelStream()Epeek()Epoll()Eremove()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanremoveIf(java.util.function.Predicate<? super E> filter)booleanretainAll(java.util.Collection<?> c)intsize()java.util.Spliterator<E>spliterator()java.util.stream.Stream<E>stream()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()
-
-
-
Method Detail
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<E>
-
iterator
public java.util.Iterator<E> iterator()
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
add
public boolean add(E e)
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<E>
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAllin interfacejava.util.Collection<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<E>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
removeIfin interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<E>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<E>
-
spliterator
public java.util.Spliterator<E> spliterator()
-
stream
public java.util.stream.Stream<E> stream()
- Specified by:
streamin interfacejava.util.Collection<E>
-
parallelStream
public java.util.stream.Stream<E> parallelStream()
- Specified by:
parallelStreamin interfacejava.util.Collection<E>
-
forEach
public void forEach(java.util.function.Consumer<? super E> action)
- Specified by:
forEachin interfacejava.lang.Iterable<E>
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Collection<E>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<E>- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-