Author: scolebourne
Date: Sun Nov  5 15:58:08 2006
New Revision: 471575

URL: http://svn.apache.org/viewvc?view=rev&rev=471575
Log:
Generify and remove AbstractSerializableCollectionDecorator

Removed:
    
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractSerializableCollectionDecorator.java
Modified:
    
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java
    
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/PredicatedCollection.java
    
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/SynchronizedCollection.java
    
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java
    
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java
    
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java

Modified: 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java?view=diff&rev=471575&r1=471574&r2=471575
==============================================================================
--- 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java
 (original)
+++ 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java
 Sun Nov  5 15:58:08 2006
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.collections.collection;
 
+import java.io.Serializable;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -41,7 +42,11 @@
  * @author Stephen Colebourne
  * @author Paul Jack
  */
-public abstract class AbstractCollectionDecorator<E> implements Collection<E> {
+public abstract class AbstractCollectionDecorator<E>
+        implements Collection<E>, Serializable {
+
+    /** Serialization version */
+    private static final long serialVersionUID = 6249888059822088500L;
 
     /** The collection being decorated */
     protected Collection<E> collection;

Modified: 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/PredicatedCollection.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/PredicatedCollection.java?view=diff&rev=471575&r1=471574&r2=471575
==============================================================================
--- 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/PredicatedCollection.java
 (original)
+++ 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/PredicatedCollection.java
 Sun Nov  5 15:58:08 2006
@@ -17,7 +17,6 @@
 package org.apache.commons.collections.collection;
 
 import java.util.Collection;
-import java.util.Iterator;
 
 import org.apache.commons.collections.Predicate;
 
@@ -34,19 +33,20 @@
  * <p>
  * This class is Serializable from Commons Collections 3.1.
  *
+ * @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 class PredicatedCollection extends 
AbstractSerializableCollectionDecorator {
+public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
 
     /** Serialization version */
     private static final long serialVersionUID = -5259182142076705162L;
 
     /** The predicate to use */
-    protected final Predicate predicate;
+    protected final Predicate<? super E> predicate;
 
     /**
      * Factory method to create a predicated (validating) collection.
@@ -54,14 +54,15 @@
      * If there are any elements already in the collection being decorated, 
they
      * are validated.
      * 
+     * @param <T> the type of the elements in the collection
      * @param coll  the collection to decorate, must not be null
      * @param predicate  the predicate to use for validation, must not be null
      * @return a new predicated collection
      * @throws IllegalArgumentException if collection or predicate is null
      * @throws IllegalArgumentException if the collection contains invalid 
elements
      */
-    public static Collection decorate(Collection coll, Predicate predicate) {
-        return new PredicatedCollection(coll, predicate);
+    public static <T> Collection<T> decorate(Collection<T> coll, Predicate<? 
super T> predicate) {
+        return new PredicatedCollection<T>(coll, predicate);
     }
 
     //-----------------------------------------------------------------------
@@ -76,14 +77,14 @@
      * @throws IllegalArgumentException if collection or predicate is null
      * @throws IllegalArgumentException if the collection contains invalid 
elements
      */
-    protected PredicatedCollection(Collection coll, Predicate predicate) {
+    protected PredicatedCollection(Collection<E> coll, Predicate<? super E> 
predicate) {
         super(coll);
         if (predicate == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
         this.predicate = predicate;
-        for (Iterator it = coll.iterator(); it.hasNext(); ) {
-            validate(it.next());
+        for (E item : coll) {
+            validate(item);
         }
     }
 
@@ -96,7 +97,7 @@
      * @param object  the object being added
      * @throws IllegalArgumentException if the add is invalid
      */
-    protected void validate(Object object) {
+    protected void validate(E object) {
         if (predicate.evaluate(object) == false) {
             throw new IllegalArgumentException("Cannot add Object '" + object 
+ "' - Predicate rejected it");
         }
@@ -111,7 +112,7 @@
      * @return the result of adding to the underlying collection
      * @throws IllegalArgumentException if the add is invalid
      */
-    public boolean add(Object object) {
+    public boolean add(E object) {
         validate(object);
         return decorated().add(object);
     }
@@ -125,9 +126,9 @@
      * @return the result of adding to the underlying collection
      * @throws IllegalArgumentException if the add is invalid
      */
-    public boolean addAll(Collection coll) {
-        for (Iterator it = coll.iterator(); it.hasNext(); ) {
-            validate(it.next());
+    public boolean addAll(Collection<? extends E> coll) {
+        for (E item : coll) {
+            validate(item);
         }
         return decorated().addAll(coll);
     }

Modified: 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/SynchronizedCollection.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/SynchronizedCollection.java?view=diff&rev=471575&r1=471574&r2=471575
==============================================================================
--- 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/SynchronizedCollection.java
 (original)
+++ 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/SynchronizedCollection.java
 Sun Nov  5 15:58:08 2006
@@ -34,32 +34,34 @@
  * <p>
  * This class is Serializable from Commons Collections 3.1.
  *
+ * @param <E> the type of the elements in the collection
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  * 
  * @author Stephen Colebourne
  */
-public class SynchronizedCollection implements Collection, Serializable {
+public class SynchronizedCollection<E> implements Collection<E>, Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = 2412805092710877986L;
 
     /** The collection to decorate */
-    protected final Collection collection;
+    protected final Collection<E> collection;
     /** The object to lock on, needed for List/SortedSet views */
     protected final Object lock;
 
     /**
      * Factory method to create a synchronized collection.
      * 
+     * @param <T> the type of the elements in the collection
      * @param coll  the collection to decorate, must not be null
      * @return a new synchronized collection
      * @throws IllegalArgumentException if collection is null
      */
-    public static Collection decorate(Collection coll) {
-        return new SynchronizedCollection(coll);
+    public static <T> Collection<T> decorate(Collection<T> coll) {
+        return new SynchronizedCollection<T>(coll);
     }
-    
+
     //-----------------------------------------------------------------------
     /**
      * Constructor that wraps (not copies).
@@ -67,7 +69,7 @@
      * @param collection  the collection to decorate, must not be null
      * @throws IllegalArgumentException if the collection is null
      */
-    protected SynchronizedCollection(Collection collection) {
+    protected SynchronizedCollection(Collection<E> collection) {
         if (collection == null) {
             throw new IllegalArgumentException("Collection must not be null");
         }
@@ -82,7 +84,7 @@
      * @param lock  the lock object to use, must not be null
      * @throws IllegalArgumentException if the collection is null
      */
-    protected SynchronizedCollection(Collection collection, Object lock) {
+    protected SynchronizedCollection(Collection<E> collection, Object lock) {
         if (collection == null) {
             throw new IllegalArgumentException("Collection must not be null");
         }
@@ -90,40 +92,49 @@
         this.lock = lock;
     }
 
+    /**
+     * Gets the collection being decorated.
+     * 
+     * @return the decorated collection
+     */
+    protected Collection<E> decorated() {
+        return collection;
+    }
+
     //-----------------------------------------------------------------------
-    public boolean add(Object object) {
+    public boolean add(E object) {
         synchronized (lock) {
-            return collection.add(object);
+            return decorated().add(object);
         }
     }
 
-    public boolean addAll(Collection coll) {
+    public boolean addAll(Collection<? extends E> coll) {
         synchronized (lock) {
-            return collection.addAll(coll);
+            return decorated().addAll(coll);
         }
     }
 
     public void clear() {
         synchronized (lock) {
-            collection.clear();
+            decorated().clear();
         }
     }
 
     public boolean contains(Object object) {
         synchronized (lock) {
-            return collection.contains(object);
+            return decorated().contains(object);
         }
     }
 
-    public boolean containsAll(Collection coll) {
+    public boolean containsAll(Collection<?> coll) {
         synchronized (lock) {
-            return collection.containsAll(coll);
+            return decorated().containsAll(coll);
         }
     }
 
     public boolean isEmpty() {
         synchronized (lock) {
-            return collection.isEmpty();
+            return decorated().isEmpty();
         }
     }
 
@@ -137,43 +148,43 @@
      * 
      * @return an iterator that must be manually synchronized on the collection
      */
-    public Iterator iterator() {
-        return collection.iterator();
+    public Iterator<E> iterator() {
+        return decorated().iterator();
     }
 
     public Object[] toArray() {
         synchronized (lock) {
-            return collection.toArray();
+            return decorated().toArray();
         }
     }
 
-    public Object[] toArray(Object[] object) {
+    public <T> T[] toArray(T[] object) {
         synchronized (lock) {
-            return collection.toArray(object);
+            return decorated().toArray(object);
         }
     }
 
     public boolean remove(Object object) {
         synchronized (lock) {
-            return collection.remove(object);
+            return decorated().remove(object);
         }
     }
 
-    public boolean removeAll(Collection coll) {
+    public boolean removeAll(Collection<?> coll) {
         synchronized (lock) {
-            return collection.removeAll(coll);
+            return decorated().removeAll(coll);
         }
     }
 
-    public boolean retainAll(Collection coll) {
+    public boolean retainAll(Collection<?> coll) {
         synchronized (lock) {
-            return collection.retainAll(coll);
+            return decorated().retainAll(coll);
         }
     }
 
     public int size() {
         synchronized (lock) {
-            return collection.size();
+            return decorated().size();
         }
     }
 
@@ -182,19 +193,19 @@
             if (object == this) {
                 return true;
             }
-            return collection.equals(object);
+            return decorated().equals(object);
         }
     }
 
     public int hashCode() {
         synchronized (lock) {
-            return collection.hashCode();
+            return decorated().hashCode();
         }
     }
 
     public String toString() {
         synchronized (lock) {
-            return collection.toString();
+            return decorated().toString();
         }
     }
 

Modified: 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java?view=diff&rev=471575&r1=471574&r2=471575
==============================================================================
--- 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java
 (original)
+++ 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java
 Sun Nov  5 15:58:08 2006
@@ -18,7 +18,6 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.collections.Transformer;
@@ -33,18 +32,19 @@
  * <p>
  * This class is Serializable from Commons Collections 3.1.
  *
+ * @param <E> the type of the elements in the collection
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  * 
  * @author Stephen Colebourne
  */
-public class TransformedCollection extends 
AbstractSerializableCollectionDecorator {
+public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
 
     /** Serialization version */
     private static final long serialVersionUID = 8692300188161871514L;
 
     /** The transformer to use */
-    protected final Transformer transformer;
+    protected final Transformer<E, E> transformer;
 
     /**
      * Factory method to create a transforming collection.
@@ -52,15 +52,16 @@
      * If there are any elements already in the collection being decorated, 
they
      * are NOT transformed.
      * 
+     * @param <T> the type of the elements in the collection
      * @param coll  the collection to decorate, must not be null
      * @param transformer  the transformer to use for conversion, must not be 
null
      * @return a new transformed collection
      * @throws IllegalArgumentException if collection or transformer is null
      */
-    public static Collection decorate(Collection coll, Transformer 
transformer) {
-        return new TransformedCollection(coll, transformer);
+    public static <T> Collection<T> decorate(Collection<T> coll, 
Transformer<T, T> transformer) {
+        return new TransformedCollection<T>(coll, transformer);
     }
-    
+
     //-----------------------------------------------------------------------
     /**
      * Constructor that wraps (not copies).
@@ -72,7 +73,7 @@
      * @param transformer  the transformer to use for conversion, must not be 
null
      * @throws IllegalArgumentException if collection or transformer is null
      */
-    protected TransformedCollection(Collection coll, Transformer transformer) {
+    protected TransformedCollection(Collection<E> coll, Transformer<E, E> 
transformer) {
         super(coll);
         if (transformer == null) {
             throw new IllegalArgumentException("Transformer must not be null");
@@ -88,7 +89,7 @@
      * @param object  the object to transform
      * @return a transformed object
      */
-    protected Object transform(Object object) {
+    protected E transform(E object) {
         return transformer.transform(object);
     }
 
@@ -100,21 +101,21 @@
      * @param coll  the collection to transform
      * @return a transformed object
      */
-    protected Collection transform(Collection coll) {
-        List list = new ArrayList(coll.size());
-        for (Iterator it = coll.iterator(); it.hasNext(); ) {
-            list.add(transform(it.next()));
+    protected Collection<E> transform(Collection<? extends E> coll) {
+        List<E> list = new ArrayList<E>(coll.size());
+        for (E item : coll) {
+            list.add(transform(item));
         }
         return list;
     }
 
     //-----------------------------------------------------------------------
-    public boolean add(Object object) {
+    public boolean add(E object) {
         object = transform(object);
         return decorated().add(object);
     }
 
-    public boolean addAll(Collection coll) {
+    public boolean addAll(Collection<? extends E> coll) {
         coll = transform(coll);
         return decorated().addAll(coll);
     }

Modified: 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java?view=diff&rev=471575&r1=471574&r2=471575
==============================================================================
--- 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java
 (original)
+++ 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java
 Sun Nov  5 15:58:08 2006
@@ -40,7 +40,7 @@
  * @author Stephen Colebourne
  */
 public final class UnmodifiableBoundedCollection
-        extends AbstractSerializableCollectionDecorator
+        extends AbstractCollectionDecorator
         implements BoundedCollection {
 
     /** Serialization version */

Modified: 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java?view=diff&rev=471575&r1=471574&r2=471575
==============================================================================
--- 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java
 (original)
+++ 
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java
 Sun Nov  5 15:58:08 2006
@@ -27,13 +27,14 @@
  * <p>
  * This class is Serializable from Commons Collections 3.1.
  *
+ * @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 */
@@ -44,17 +45,18 @@
      * <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).
@@ -62,20 +64,20 @@
      * @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() {
+    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();
     }
 
@@ -87,11 +89,11 @@
         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();
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to