Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.

Also see the following revisions:

    ------------------------------------------------------------------------
    r555925 | skestle | 2007-07-13 03:39:24 -0700 (Fri, 13 Jul 2007) | 2 lines
    
    Added Edwin Tellman's patch for COLLECTIONS-243.  
    It all seems pretty reasonable, and it should all be checked again as the project is worked through
    ------------------------------------------------------------------------
    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()
    ------------------------------------------------------------------------
    r471173 | scolebourne | 2006-11-04 04:07:39 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Abstract*Decorator - Generify and use covariant return types
    ------------------------------------------------------------------------


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-15 05:54:41 +00:00
parent 8fb4813c01
commit 10af29350d
1 changed files with 34 additions and 30 deletions

View File

@ -16,6 +16,7 @@
*/
package org.apache.commons.collections.collection;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
@ -34,16 +35,21 @@ import java.util.Iterator;
* wrapped collection. This may be undesirable, for example if you are trying
* to write an unmodifiable implementation it might provide a loophole.
*
* @param <E> the type of the elements in the collection
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
* @author Paul Jack
*/
public abstract class AbstractCollectionDecorator implements Collection {
public abstract class AbstractCollectionDecorator<E>
implements Collection<E>, Serializable {
/** Serialization version */
private static final long serialVersionUID = 6249888059822088500L;
/** The collection being decorated */
protected Collection collection;
protected Collection<E> collection;
/**
* Constructor only used in deserialization, do not use otherwise.
@ -59,7 +65,7 @@ public abstract class AbstractCollectionDecorator implements Collection {
* @param coll the collection to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
protected AbstractCollectionDecorator(Collection coll) {
protected AbstractCollectionDecorator(Collection<E> coll) {
if (coll == null) {
throw new IllegalArgumentException("Collection must not be null");
}
@ -68,79 +74,77 @@ public abstract class AbstractCollectionDecorator implements Collection {
/**
* Gets the collection being decorated.
* All access to the decorated collection goes via this method.
*
* @return the decorated collection
*/
protected Collection getCollection() {
protected Collection<E> decorated() {
return collection;
}
//-----------------------------------------------------------------------
public boolean add(Object object) {
return collection.add(object);
public boolean add(E object) {
return decorated().add(object);
}
public boolean addAll(Collection coll) {
return collection.addAll(coll);
public boolean addAll(Collection<? extends E> coll) {
return decorated().addAll(coll);
}
public void clear() {
collection.clear();
decorated().clear();
}
public boolean contains(Object object) {
return collection.contains(object);
return decorated().contains(object);
}
public boolean isEmpty() {
return collection.isEmpty();
return decorated().isEmpty();
}
public Iterator iterator() {
return collection.iterator();
public Iterator<E> iterator() {
return decorated().iterator();
}
public boolean remove(Object object) {
return collection.remove(object);
return decorated().remove(object);
}
public int size() {
return collection.size();
return decorated().size();
}
public Object[] toArray() {
return collection.toArray();
return decorated().toArray();
}
public Object[] toArray(Object[] object) {
return collection.toArray(object);
public <T> T[] toArray(T[] object) {
return decorated().toArray(object);
}
public boolean containsAll(Collection coll) {
return collection.containsAll(coll);
public boolean containsAll(Collection<?> coll) {
return decorated().containsAll(coll);
}
public boolean removeAll(Collection coll) {
return collection.removeAll(coll);
public boolean removeAll(Collection<?> coll) {
return decorated().removeAll(coll);
}
public boolean retainAll(Collection coll) {
return collection.retainAll(coll);
public boolean retainAll(Collection<?> coll) {
return decorated().retainAll(coll);
}
public boolean equals(Object object) {
if (object == this) {
return true;
}
return collection.equals(object);
return object == this || decorated().equals(object);
}
public int hashCode() {
return collection.hashCode();
return decorated().hashCode();
}
public String toString() {
return collection.toString();
return decorated().toString();
}
}