mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-06 01:59:08 +00:00
Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.
Also see the following revisions: ------------------------------------------------------------------------ r471575 | scolebourne | 2006-11-05 15:58:08 -0800 (Sun, 05 Nov 2006) | 1 line Generify and remove AbstractSerializableCollectionDecorator ------------------------------------------------------------------------ r471202 | scolebourne | 2006-11-04 06:21:44 -0800 (Sat, 04 Nov 2006) | 1 line Remove getCollection() - use covariant decorated() ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815041 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d0072e5872
commit
914f0907aa
@ -29,13 +29,14 @@ import org.apache.commons.collections.iterators.UnmodifiableIterator;
|
||||
* <p>
|
||||
* Attempts to modify it will result in an UnsupportedOperationException.
|
||||
*
|
||||
* @param <E> the type of the elements in the collection
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public final class UnmodifiableCollection
|
||||
extends AbstractSerializableCollectionDecorator
|
||||
public final class UnmodifiableCollection<E>
|
||||
extends AbstractCollectionDecorator<E>
|
||||
implements Unmodifiable {
|
||||
|
||||
/** Serialization version */
|
||||
@ -46,17 +47,18 @@ public final class UnmodifiableCollection
|
||||
* <p>
|
||||
* If the collection passed in is already unmodifiable, it is returned.
|
||||
*
|
||||
* @param <T> the type of the elements in the collection
|
||||
* @param coll the collection to decorate, must not be null
|
||||
* @return an unmodifiable collection
|
||||
* @throws IllegalArgumentException if collection is null
|
||||
*/
|
||||
public static Collection decorate(Collection coll) {
|
||||
public static <T> Collection<T> decorate(Collection<T> coll) {
|
||||
if (coll instanceof Unmodifiable) {
|
||||
return coll;
|
||||
}
|
||||
return new UnmodifiableCollection(coll);
|
||||
return new UnmodifiableCollection<T>(coll);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Constructor that wraps (not copies).
|
||||
@ -64,20 +66,20 @@ public final class UnmodifiableCollection
|
||||
* @param coll the collection to decorate, must not be null
|
||||
* @throws IllegalArgumentException if collection is null
|
||||
*/
|
||||
private UnmodifiableCollection(Collection coll) {
|
||||
private UnmodifiableCollection(Collection<E> coll) {
|
||||
super(coll);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Iterator iterator() {
|
||||
return UnmodifiableIterator.decorate(getCollection().iterator());
|
||||
public Iterator<E> iterator() {
|
||||
return UnmodifiableIterator.decorate(decorated().iterator());
|
||||
}
|
||||
|
||||
public boolean add(Object object) {
|
||||
public boolean add(E object) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean addAll(Collection coll) {
|
||||
public boolean addAll(Collection<? extends E> coll) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -89,11 +91,11 @@ public final class UnmodifiableCollection
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection coll) {
|
||||
public boolean removeAll(Collection<?> coll) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection coll) {
|
||||
public boolean retainAll(Collection<?> coll) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user