public class UnmodifiableCollection<E> extends java.lang.Object implements java.util.Collection<E>, java.io.Serializable
Collection prohibiting all calls which would
modify its contents. As the construction of this class is performed in
constant time it is preferred over copying the collection (which takes linear
time). Using this class is also preferred to using the
unmodifiableX() in class Collections as they return the
collection base type that does not signal, that the object is unmodifiable.
Using the classes in this package makes unmodifiability more explicit.
All prohibited methods throw an UnsupportedOperationException. The
class is nearly the same as the one returned by
Collections.unmodifiableCollection(Collection), but by making it a
public class we can make the return value of some methods more explicit.
This collection is serializable if the wrapped collection is serializable.
| Constructor and Description |
|---|
UnmodifiableCollection(java.util.Collection<E> c)
Creates a new unmodifiable collection from another collection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E arg0)
Operation is not supported.
|
boolean |
addAll(java.util.Collection<? extends E> arg0)
Operation is not supported.
|
void |
clear()
Operation is not supported.
|
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> other) |
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
boolean |
isEmpty() |
UnmodifiableIterator<E> |
iterator() |
boolean |
remove(java.lang.Object arg0)
Operation is not supported.
|
boolean |
removeAll(java.util.Collection<?> arg0)
Operation is not supported.
|
boolean |
retainAll(java.util.Collection<?> arg0)
Operation is not supported.
|
int |
size() |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
java.lang.String |
toString()
Returns a string representation of this collection.
|
public UnmodifiableCollection(java.util.Collection<E> c)
public boolean contains(java.lang.Object o)
contains in interface java.util.Collection<E>public boolean containsAll(java.util.Collection<?> other)
containsAll in interface java.util.Collection<E>public UnmodifiableIterator<E> iterator()
public java.lang.Object[] toArray()
toArray in interface java.util.Collection<E>public boolean add(E arg0)
add in interface java.util.Collection<E>public boolean addAll(java.util.Collection<? extends E> arg0)
addAll in interface java.util.Collection<E>public void clear()
clear in interface java.util.Collection<E>public boolean remove(java.lang.Object arg0)
remove in interface java.util.Collection<E>public boolean removeAll(java.util.Collection<?> arg0)
removeAll in interface java.util.Collection<E>public boolean retainAll(java.util.Collection<?> arg0)
retainAll in interface java.util.Collection<E>public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in interface java.util.Collection<E>equals in class java.lang.Object