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

public final Class UnmodifiableBoundedCollection<E>

extends AbstractCollectionDecorator<E>
implements BoundedCollection<E>, Unmodifiable
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.Unmodifiable, org.apache.commons.collections4.BoundedCollection, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
the type of elements in this collection
Imports
java.util.Collection, .Iterator, java.util.function.Predicate, org.apache.commons.collections4.BoundedCollection, .Unmodifiable, org.apache.commons.collections4.iterators.UnmodifiableIterator

UnmodifiableBoundedCollection decorates another BoundedCollection to ensure it can't be altered.

If a BoundedCollection is first wrapped in some other collection decorator, such as synchronized or predicated, the BoundedCollection methods are no longer accessible. The factory on this class will attempt to retrieve the bounded nature by examining the package scope variables.

This class is Serializable from Commons Collections 3.1.

Attempts to modify it will result in an UnsupportedOperationException.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
private
UnmodifiableBoundedCollection(final BoundedCollection<? extends E>
the collection to decorate, must not be null
coll
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final E
element whose presence in this collection is to be ensured
object
)

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

Implements java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation).
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).
protected BoundedCollection<E>
public boolean
isFull()

Implements org.apache.commons.collections4.BoundedCollection.isFull.

Returns true if this collection is full and no new elements can be added.
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 int
maxSize()

Implements org.apache.commons.collections4.BoundedCollection.maxSize.

Gets the maximum size of the collection (the bound).
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 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(final 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 collection
E
>
BoundedCollection<E>

Returns:

a new unmodifiable bounded collection
unmodifiableBoundedCollection
(final BoundedCollection<? extends E>
the BoundedCollection to decorate, must not be null
coll
)

Factory method to create an unmodifiable bounded collection.

public static <
the type of the elements in the collection
E
>
BoundedCollection<E>

Returns:

a new unmodifiable bounded collection
unmodifiableBoundedCollection
(Collection<? extends E>
the BoundedCollection to decorate, must not be null
coll
)

Factory method to create an unmodifiable bounded collection.

Inherited from org.apache.commons.collections4.collection.AbstractCollectionDecorator:
containscontainsAllisEmptysetCollectionsizetoArraytoArraytoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.collection.AbstractCollectionDecorator.serialVersionUID.

Serialization version

Constructor Detail

UnmodifiableBoundedCollectionback to summary
private UnmodifiableBoundedCollection(final BoundedCollection<? extends E> coll)

Constructor that wraps (not copies).

Parameters
coll:BoundedCollection<? extends E>

the collection to decorate, must not be null

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

Method Detail

addback to summary
public boolean add(final E object)

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

Implements java.util.Collection.add.

Doc from java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Parameters
object:E

element whose presence in this collection is to be ensured

Returns:boolean

true if this collection changed as a result of the call

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
decoratedback to summary
protected BoundedCollection<E> decorated()

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

Doc from org.apache.commons.collections4.collection.AbstractCollectionDecorator.decorated.

Gets the collection being decorated. All access to the decorated collection goes via this method.

Returns:BoundedCollection<E>

the decorated collection

Annotations
@Override
isFullback to summary
public boolean isFull()

Implements org.apache.commons.collections4.BoundedCollection.isFull.

Doc from org.apache.commons.collections4.BoundedCollection.isFull.

Returns true if this collection is full and no new elements can be added.

Returns:boolean

true if the collection is full.

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
maxSizeback to summary
public int maxSize()

Implements org.apache.commons.collections4.BoundedCollection.maxSize.

Doc from org.apache.commons.collections4.BoundedCollection.maxSize.

Gets the maximum size of the collection (the bound).

Returns:int

the maximum number of elements the collection can hold.

Annotations
@Override
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
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(final 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
unmodifiableBoundedCollectionback to summary
public static <E> BoundedCollection<E> unmodifiableBoundedCollection(final BoundedCollection<? extends E> coll)

Factory method to create an unmodifiable bounded collection.

Parameters
<E>
the type of the elements in the collection
coll:BoundedCollection<? extends E>

the BoundedCollection to decorate, must not be null

Returns:BoundedCollection<E>

a new unmodifiable bounded collection

Exceptions
NullPointerException:
if coll is null
Since
4.0
unmodifiableBoundedCollectionback to summary
public static <E> BoundedCollection<E> unmodifiableBoundedCollection(Collection<? extends E> coll)

Factory method to create an unmodifiable bounded collection.

This method is capable of drilling down through up to 1000 other decorators to find a suitable BoundedCollection.

Parameters
<E>
the type of the elements in the collection
coll:Collection<? extends E>

the BoundedCollection to decorate, must not be null

Returns:BoundedCollection<E>

a new unmodifiable bounded collection

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if coll is null
IllegalArgumentException:
if coll is not a BoundedCollection
Since
4.0