Top Description Fields Constructors Methods
org.apache.commons.collections4.queue

public final Class UnmodifiableQueue<E>

extends AbstractQueueDecorator<E>
implements Unmodifiable
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.Unmodifiable
Type Parameters
<E>
the type of elements held in this queue
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, java.util.Collection, .Iterator, .Queue, java.util.function.Predicate, org.apache.commons.collections4.Unmodifiable, org.apache.commons.collections4.iterators.UnmodifiableIterator

Decorates another Queue to ensure it can't be altered.

Attempts to modify it will result in an UnsupportedOperationException.

Since
4.0

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
private
UnmodifiableQueue(final Queue<? extends E>
the queue to decorate, must not be null
queue
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final Object
the element to add
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements java.util.Queue.add, java.util.Collection.add.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
public boolean
addAll(final Collection<? extends E>
collection containing elements to be added to this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation).
public void
clear()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.clear.

Implements java.util.Collection.clear.

Removes all of the elements from this collection (optional operation).
public Iterator<E>
iterator()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.iterator.

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.
public boolean
offer(final E
the element to add
obj
)

Overrides org.apache.commons.collections4.queue.AbstractQueueDecorator.offer.

Implements java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
public E
poll()

Overrides org.apache.commons.collections4.queue.AbstractQueueDecorator.poll.

Implements java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the collection in using a custom routine.

public boolean
remove(final Object
element to be removed from this collection, if present
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation).
public E
remove()

Overrides org.apache.commons.collections4.queue.AbstractQueueDecorator.remove.

Implements java.util.Queue.remove.

Retrieves and removes the head of this queue.
public boolean
removeAll(final Collection<?>
collection containing elements to be removed from this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements java.util.Collection.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation).
public boolean
removeIf(Predicate<? super E>
a predicate which returns true for elements to be removed
filter
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeIf.

Overrides default java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate.
public boolean
retainAll(final Collection<?>
collection containing elements to be retained in this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements java.util.Collection.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation).
public static <
the type of the elements in the queue
E
>
Queue<E>

Returns:

an unmodifiable Queue
unmodifiableQueue
(final Queue<? extends E>
the queue to decorate, must not be null
queue
)

Factory method to create an unmodifiable queue.

private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the collection out using a custom routine.

Inherited from org.apache.commons.collections4.queue.AbstractQueueDecorator:
decoratedelementpeek

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.queue.AbstractQueueDecorator.serialVersionUID.

Serialization version

Constructor Detail

UnmodifiableQueueback to summary
private UnmodifiableQueue(final Queue<? extends E> queue)

Constructor that wraps (not copies).

Parameters
queue:Queue<? extends E>

the queue to decorate, must not be null

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if queue is null

Method Detail

addback to summary
public boolean add(final Object object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements java.util.Queue.add, java.util.Collection.add.

Doc from java.util.Queue.add.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Parameters
object:Object

the element to add

Returns:boolean

true (as specified by Collection#add)

Annotations
@Override
addAllback to summary
public boolean addAll(final Collection<? extends E> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll.

Doc from java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.

Parameters
coll:Collection<? extends E>

collection containing elements to be added to this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
clearback to summary
public void clear()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.clear.

Implements java.util.Collection.clear.

Doc from java.util.Collection.clear.

Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.iterator.

Implements java.util.Collection.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<E>

an Iterator over the elements in this collection

Annotations
@Override
offerback to summary
public boolean offer(final E obj)

Overrides org.apache.commons.collections4.queue.AbstractQueueDecorator.offer.

Implements java.util.Queue.offer.

Doc from java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add, which can fail to insert an element only by throwing an exception.

Parameters
obj:E

the element to add

Returns:boolean

true if the element was added to this queue, else false

Annotations
@Override
pollback to summary
public E poll()

Overrides org.apache.commons.collections4.queue.AbstractQueueDecorator.poll.

Implements java.util.Queue.poll.

Doc from java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the collection in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Annotations
@SuppressWarnings:unchecked
Exceptions
IOException:
if an I/O error occurs while reading from the input stream
ClassNotFoundException:
if the class of a serialized object can not be found
removeback to summary
public boolean remove(final Object object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements java.util.Collection.remove.

Doc from java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).

Parameters
object:Object

element to be removed from this collection, if present

Returns:boolean

true if an element was removed as a result of this call

Annotations
@Override
removeback to summary
public E remove()

Overrides org.apache.commons.collections4.queue.AbstractQueueDecorator.remove.

Implements java.util.Queue.remove.

Doc from java.util.Queue.remove.

Retrieves and removes the head of this queue. This method differs from poll() only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

Annotations
@Override
removeAllback to summary
public boolean removeAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements java.util.Collection.removeAll.

Doc from java.util.Collection.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.

Parameters
coll:Collection<?>

collection containing elements to be removed from this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
removeIfback to summary
public boolean removeIf(Predicate<? super E> filter)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeIf.

Overrides default java.util.Collection.removeIf.

Doc from java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.

Parameters
filter:Predicate<? super E>

a predicate which returns true for elements to be removed

Returns:boolean

true if any elements were removed

Annotations
@Override
Since
4.4
retainAllback to summary
public boolean retainAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements java.util.Collection.retainAll.

Doc from java.util.Collection.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

Parameters
coll:Collection<?>

collection containing elements to be retained in this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
unmodifiableQueueback to summary
public static <E> Queue<E> unmodifiableQueue(final Queue<? extends E> queue)

Factory method to create an unmodifiable queue.

If the queue passed in is already unmodifiable, it is returned.

Parameters
<E>
the type of the elements in the queue
queue:Queue<? extends E>

the queue to decorate, must not be null

Returns:Queue<E>

an unmodifiable Queue

Exceptions
NullPointerException:
if queue is null
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the collection out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an I/O error occurs while writing to the output stream