Class UnmodifiableCollection<E>
java.lang.Object
org.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
org.apache.commons.collections4.collection.UnmodifiableCollection<E>
- Type Parameters:
E- The type of the elements in the collection.
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,Unmodifiable
public final class UnmodifiableCollection<E>
extends AbstractCollectionDecorator<E>
implements Unmodifiable
Decorates another
Collection to ensure it can't be altered.
This class is Serializable from Commons Collections 3.1.
Attempts to modify it will result in an UnsupportedOperationException.
- Since:
- 3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longSerialization version -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateUnmodifiableCollection(Collection<? extends E> coll) Constructs and wraps (not copies). -
Method Summary
Modifier and TypeMethodDescriptionbooleanAlways throwsUnsupportedOperationException.booleanaddAll(Collection<? extends E> coll) Always throwsUnsupportedOperationException.voidclear()Always throwsUnsupportedOperationException.iterator()booleanAlways throwsUnsupportedOperationException.booleanremoveAll(Collection<?> coll) Always throwsUnsupportedOperationException.booleanAlways throwsUnsupportedOperationException.booleanretainAll(Collection<?> coll) Always throwsUnsupportedOperationException.static <T> Collection<T> unmodifiableCollection(Collection<? extends T> coll) Creates an unmodifiable collection.Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator
contains, containsAll, decorated, isEmpty, setCollection, size, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, spliterator, stream
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version- See Also:
-
-
Constructor Details
-
UnmodifiableCollection
Constructs and wraps (not copies).- Parameters:
coll- The collection to decorate, must not be null.- Throws:
NullPointerException- if collection is null.
-
-
Method Details
-
unmodifiableCollection
Creates an unmodifiable collection.If the collection passed in is already unmodifiable, it is returned.
- Type Parameters:
T- The type of the elements in the collection.- Parameters:
coll- The collection to decorate, must not be null.- Returns:
- An unmodifiable collection.
- Throws:
NullPointerException- if collection is null.- Since:
- 4.0
-
add
Always throwsUnsupportedOperationException.- Specified by:
addin interfaceCollection<E>- Overrides:
addin classAbstractCollectionDecorator<E>- Parameters:
object- Ignored.- Throws:
UnsupportedOperationException- Always thrown.
-
addAll
Always throwsUnsupportedOperationException.- Specified by:
addAllin interfaceCollection<E>- Overrides:
addAllin classAbstractCollectionDecorator<E>- Throws:
UnsupportedOperationException- Always thrown.
-
clear
public void clear()Always throwsUnsupportedOperationException.- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollectionDecorator<E>- Throws:
UnsupportedOperationException- Always thrown.
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Overrides:
iteratorin classAbstractCollectionDecorator<E>
-
remove
Always throwsUnsupportedOperationException.- Specified by:
removein interfaceCollection<E>- Overrides:
removein classAbstractCollectionDecorator<E>- Parameters:
object- Ignored.- Throws:
UnsupportedOperationException- Always thrown.
-
removeAll
Always throwsUnsupportedOperationException.- Specified by:
removeAllin interfaceCollection<E>- Overrides:
removeAllin classAbstractCollectionDecorator<E>- Parameters:
coll- Ignored.- Throws:
UnsupportedOperationException- Always thrown.
-
removeIf
Always throwsUnsupportedOperationException.- Specified by:
removeIfin interfaceCollection<E>- Overrides:
removeIfin classAbstractCollectionDecorator<E>- Parameters:
filter- Ignored.- Throws:
UnsupportedOperationException- Always thrown.- Since:
- 4.4
-
retainAll
Always throwsUnsupportedOperationException.- Specified by:
retainAllin interfaceCollection<E>- Overrides:
retainAllin classAbstractCollectionDecorator<E>- Parameters:
coll- Ignored.- Throws:
UnsupportedOperationException- Always thrown.
-