commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r814997 [3/18] - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/ java/org/apache/commons/collections/bidimap/ java/org/apache/commons/collections/buffer/ java/org/apach...
Date Tue, 15 Sep 2009 05:30:02 GMT
Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableBidiMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableBidiMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableBidiMap.java Tue Sep 15 05:29:56 2009
@@ -38,36 +38,36 @@
  *
  * @author Stephen Colebourne
  */
-public final class UnmodifiableBidiMap
-        extends AbstractBidiMapDecorator implements Unmodifiable {
-    
+public final class UnmodifiableBidiMap<K, V>
+        extends AbstractBidiMapDecorator<K, V> implements Unmodifiable {
+
     /** The inverse unmodifiable map */
-    private UnmodifiableBidiMap inverse;
+    private UnmodifiableBidiMap<V, K> inverse;
 
     /**
      * Factory method to create an unmodifiable map.
      * <p>
      * If the map passed in is already unmodifiable, it is returned.
-     * 
+     *
      * @param map  the map to decorate, must not be null
      * @return an unmodifiable BidiMap
      * @throws IllegalArgumentException if map is null
      */
-    public static BidiMap decorate(BidiMap map) {
+    public static <K, V> BidiMap<K, V> decorate(BidiMap<K, V> map) {
         if (map instanceof Unmodifiable) {
             return map;
         }
-        return new UnmodifiableBidiMap(map);
+        return new UnmodifiableBidiMap<K, V>(map);
     }
 
     //-----------------------------------------------------------------------
     /**
      * Constructor that wraps (not copies).
-     * 
+     *
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    private UnmodifiableBidiMap(BidiMap map) {
+    private UnmodifiableBidiMap(BidiMap<K, V> map) {
         super(map);
     }
 
@@ -76,49 +76,49 @@
         throw new UnsupportedOperationException();
     }
 
-    public Object put(Object key, Object value) {
+    public V put(K key, V value) {
         throw new UnsupportedOperationException();
     }
 
-    public void putAll(Map mapToCopy) {
+    public void putAll(Map<? extends K, ? extends V> mapToCopy) {
         throw new UnsupportedOperationException();
     }
 
-    public Object remove(Object key) {
+    public V remove(Object key) {
         throw new UnsupportedOperationException();
     }
 
-    public Set entrySet() {
-        Set set = super.entrySet();
+    public Set<Map.Entry<K, V>> entrySet() {
+        Set<Map.Entry<K, V>> set = super.entrySet();
         return UnmodifiableEntrySet.decorate(set);
     }
 
-    public Set keySet() {
-        Set set = super.keySet();
+    public Set<K> keySet() {
+        Set<K> set = super.keySet();
         return UnmodifiableSet.decorate(set);
     }
 
-    public Collection values() {
-        Collection coll = super.values();
+    public Collection<V> values() {
+        Collection<V> coll = super.values();
         return UnmodifiableCollection.decorate(coll);
     }
 
     //-----------------------------------------------------------------------
-    public Object removeValue(Object value) {
+    public K removeValue(Object value) {
         throw new UnsupportedOperationException();
     }
 
-    public MapIterator mapIterator() {
-        MapIterator it = getBidiMap().mapIterator();
+    public MapIterator<K, V> mapIterator() {
+        MapIterator<K, V> it = decorated().mapIterator();
         return UnmodifiableMapIterator.decorate(it);
     }
 
-    public BidiMap inverseBidiMap() {
+    public synchronized BidiMap<V, K> inverseBidiMap() {
         if (inverse == null) {
-            inverse = new UnmodifiableBidiMap(getBidiMap().inverseBidiMap());
+            inverse = new UnmodifiableBidiMap<V, K>(decorated().inverseBidiMap());
             inverse.inverse = this;
         }
         return inverse;
     }
-    
+
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableOrderedBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableOrderedBidiMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableOrderedBidiMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableOrderedBidiMap.java Tue Sep 15 05:29:56 2009
@@ -20,8 +20,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.collections.BidiMap;
-import org.apache.commons.collections.MapIterator;
 import org.apache.commons.collections.OrderedBidiMap;
 import org.apache.commons.collections.OrderedMapIterator;
 import org.apache.commons.collections.Unmodifiable;
@@ -40,36 +38,36 @@
  *
  * @author Stephen Colebourne
  */
-public final class UnmodifiableOrderedBidiMap
-        extends AbstractOrderedBidiMapDecorator implements Unmodifiable {
-    
+public final class UnmodifiableOrderedBidiMap<K, V>
+        extends AbstractOrderedBidiMapDecorator<K, V> implements Unmodifiable {
+
     /** The inverse unmodifiable map */
-    private UnmodifiableOrderedBidiMap inverse;
+    private UnmodifiableOrderedBidiMap<V, K> inverse;
 
     /**
      * Factory method to create an unmodifiable map.
      * <p>
      * If the map passed in is already unmodifiable, it is returned.
-     * 
+     *
      * @param map  the map to decorate, must not be null
      * @return an unmodifiable OrderedBidiMap
      * @throws IllegalArgumentException if map is null
      */
-    public static OrderedBidiMap decorate(OrderedBidiMap map) {
+    public static <K, V> OrderedBidiMap<K, V> decorate(OrderedBidiMap<K, V> map) {
         if (map instanceof Unmodifiable) {
             return map;
         }
-        return new UnmodifiableOrderedBidiMap(map);
+        return new UnmodifiableOrderedBidiMap<K, V>(map);
     }
 
     //-----------------------------------------------------------------------
     /**
      * Constructor that wraps (not copies).
-     * 
+     *
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    private UnmodifiableOrderedBidiMap(OrderedBidiMap map) {
+    private UnmodifiableOrderedBidiMap(OrderedBidiMap<K, V> map) {
         super(map);
     }
 
@@ -78,55 +76,51 @@
         throw new UnsupportedOperationException();
     }
 
-    public Object put(Object key, Object value) {
+    public V put(K key, V value) {
         throw new UnsupportedOperationException();
     }
 
-    public void putAll(Map mapToCopy) {
+    public void putAll(Map<? extends K, ? extends V> mapToCopy) {
         throw new UnsupportedOperationException();
     }
 
-    public Object remove(Object key) {
+    public V remove(Object key) {
         throw new UnsupportedOperationException();
     }
 
-    public Set entrySet() {
-        Set set = super.entrySet();
+    public Set<Map.Entry<K, V>> entrySet() {
+        Set<Map.Entry<K, V>> set = super.entrySet();
         return UnmodifiableEntrySet.decorate(set);
     }
 
-    public Set keySet() {
-        Set set = super.keySet();
+    public Set<K> keySet() {
+        Set<K> set = super.keySet();
         return UnmodifiableSet.decorate(set);
     }
 
-    public Collection values() {
-        Collection coll = super.values();
+    public Collection<V> values() {
+        Collection<V> coll = super.values();
         return UnmodifiableCollection.decorate(coll);
     }
 
     //-----------------------------------------------------------------------
-    public Object removeValue(Object value) {
+    public K removeValue(Object value) {
         throw new UnsupportedOperationException();
     }
 
-    public MapIterator mapIterator() {
-        return orderedMapIterator();
-    }
-
-    public BidiMap inverseBidiMap() {
+    public OrderedBidiMap<V, K> inverseBidiMap() {
         return inverseOrderedBidiMap();
     }
-    
+
     //-----------------------------------------------------------------------
-    public OrderedMapIterator orderedMapIterator() {
-        OrderedMapIterator it = getOrderedBidiMap().orderedMapIterator();
+    public OrderedMapIterator<K, V> mapIterator() {
+        OrderedMapIterator<K, V> it = decorated().mapIterator();
         return UnmodifiableOrderedMapIterator.decorate(it);
     }
 
-    public OrderedBidiMap inverseOrderedBidiMap() {
+    public OrderedBidiMap<V, K> inverseOrderedBidiMap() {
         if (inverse == null) {
-            inverse = new UnmodifiableOrderedBidiMap(getOrderedBidiMap().inverseOrderedBidiMap());
+            inverse = new UnmodifiableOrderedBidiMap<V, K>(decorated().inverseBidiMap());
             inverse.inverse = this;
         }
         return inverse;

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableSortedBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableSortedBidiMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableSortedBidiMap.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/UnmodifiableSortedBidiMap.java Tue Sep 15 05:29:56 2009
@@ -21,9 +21,6 @@
 import java.util.Set;
 import java.util.SortedMap;
 
-import org.apache.commons.collections.BidiMap;
-import org.apache.commons.collections.MapIterator;
-import org.apache.commons.collections.OrderedBidiMap;
 import org.apache.commons.collections.OrderedMapIterator;
 import org.apache.commons.collections.SortedBidiMap;
 import org.apache.commons.collections.Unmodifiable;
@@ -43,36 +40,36 @@
  *
  * @author Stephen Colebourne
  */
-public final class UnmodifiableSortedBidiMap
-        extends AbstractSortedBidiMapDecorator implements Unmodifiable {
-    
+public final class UnmodifiableSortedBidiMap<K, V>
+        extends AbstractSortedBidiMapDecorator<K, V> implements Unmodifiable {
+
     /** The inverse unmodifiable map */
-    private UnmodifiableSortedBidiMap inverse;
+    private UnmodifiableSortedBidiMap<V, K> inverse;
 
     /**
      * Factory method to create an unmodifiable map.
      * <p>
      * If the map passed in is already unmodifiable, it is returned.
-     * 
+     *
      * @param map  the map to decorate, must not be null
      * @return an unmodifiable SortedBidiMap
      * @throws IllegalArgumentException if map is null
      */
-    public static SortedBidiMap decorate(SortedBidiMap map) {
+    public static <K, V> SortedBidiMap<K, V> decorate(SortedBidiMap<K, V> map) {
         if (map instanceof Unmodifiable) {
             return map;
         }
-        return new UnmodifiableSortedBidiMap(map);
+        return new UnmodifiableSortedBidiMap<K, V>(map);
     }
 
     //-----------------------------------------------------------------------
     /**
      * Constructor that wraps (not copies).
-     * 
+     *
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    private UnmodifiableSortedBidiMap(SortedBidiMap map) {
+    private UnmodifiableSortedBidiMap(SortedBidiMap<K, V> map) {
         super(map);
     }
 
@@ -81,77 +78,65 @@
         throw new UnsupportedOperationException();
     }
 
-    public Object put(Object key, Object value) {
+    public V put(K key, V value) {
         throw new UnsupportedOperationException();
     }
 
-    public void putAll(Map mapToCopy) {
+    public void putAll(Map<? extends K, ? extends V> mapToCopy) {
         throw new UnsupportedOperationException();
     }
 
-    public Object remove(Object key) {
+    public V remove(Object key) {
         throw new UnsupportedOperationException();
     }
 
-    public Set entrySet() {
-        Set set = super.entrySet();
+    public Set<Map.Entry<K, V>> entrySet() {
+        Set<Map.Entry<K, V>> set = super.entrySet();
         return UnmodifiableEntrySet.decorate(set);
     }
 
-    public Set keySet() {
-        Set set = super.keySet();
+    public Set<K> keySet() {
+        Set<K> set = super.keySet();
         return UnmodifiableSet.decorate(set);
     }
 
-    public Collection values() {
-        Collection coll = super.values();
+    public Collection<V> values() {
+        Collection<V> coll = super.values();
         return UnmodifiableCollection.decorate(coll);
     }
 
     //-----------------------------------------------------------------------
-    public Object removeValue(Object value) {
+    public K removeValue(Object value) {
         throw new UnsupportedOperationException();
     }
 
-    public MapIterator mapIterator() {
-        return orderedMapIterator();
-    }
-
-    public BidiMap inverseBidiMap() {
-        return inverseSortedBidiMap();
-    }
-    
     //-----------------------------------------------------------------------
-    public OrderedMapIterator orderedMapIterator() {
-        OrderedMapIterator it = getSortedBidiMap().orderedMapIterator();
+    public OrderedMapIterator<K, V> mapIterator() {
+        OrderedMapIterator<K, V> it = decorated().mapIterator();
         return UnmodifiableOrderedMapIterator.decorate(it);
     }
 
-    public OrderedBidiMap inverseOrderedBidiMap() {
-        return inverseSortedBidiMap();
-    }
-
     //-----------------------------------------------------------------------
-    public SortedBidiMap inverseSortedBidiMap() {
+    public SortedBidiMap<V, K> inverseBidiMap() {
         if (inverse == null) {
-            inverse = new UnmodifiableSortedBidiMap(getSortedBidiMap().inverseSortedBidiMap());
+            inverse = new UnmodifiableSortedBidiMap<V, K>(decorated().inverseBidiMap());
             inverse.inverse = this;
         }
         return inverse;
     }
 
-    public SortedMap subMap(Object fromKey, Object toKey) {
-        SortedMap sm = getSortedBidiMap().subMap(fromKey, toKey);
+    public SortedMap<K, V> subMap(K fromKey, K toKey) {
+        SortedMap<K, V> sm = decorated().subMap(fromKey, toKey);
         return UnmodifiableSortedMap.decorate(sm);
     }
 
-    public SortedMap headMap(Object toKey) {
-        SortedMap sm = getSortedBidiMap().headMap(toKey);
+    public SortedMap<K, V> headMap(K toKey) {
+        SortedMap<K, V> sm = decorated().headMap(toKey);
         return UnmodifiableSortedMap.decorate(sm);
     }
 
-    public SortedMap tailMap(Object fromKey) {
-        SortedMap sm = getSortedBidiMap().tailMap(fromKey);
+    public SortedMap<K, V> tailMap(K fromKey) {
+        SortedMap<K, V> sm = decorated().tailMap(fromKey);
         return UnmodifiableSortedMap.decorate(sm);
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java Tue Sep 15 05:29:56 2009
@@ -35,7 +35,7 @@
  * The BoundedFifoBuffer is a very efficient implementation of
  * <code>Buffer</code> that is of a fixed size.
  * <p>
- * The removal order of a <code>BoundedFifoBuffer</code> is based on the 
+ * The removal order of a <code>BoundedFifoBuffer</code> is based on the
  * insertion order; elements are removed in the same order in which they
  * were added.  The iteration order is the same as the removal order.
  * <p>
@@ -62,30 +62,30 @@
  * @author Stephen Colebourne
  * @author Herve Quiroz
  */
-public class BoundedFifoBuffer extends AbstractCollection
-        implements Buffer, BoundedCollection, Serializable {
+public class BoundedFifoBuffer<E> extends AbstractCollection<E>
+        implements Buffer<E>, BoundedCollection<E>, Serializable {
 
     /** Serialization version */
     private static final long serialVersionUID = 5603722811189451017L;
 
     /** Underlying storage array */
-    private transient Object[] elements;
-    
+    private transient E[] elements;
+
     /** Array index of first (oldest) buffer element */
     private transient int start = 0;
-    
-    /** 
+
+    /**
      * Index mod maxElements of the array position following the last buffer
      * element.  Buffer elements start at elements[start] and "wrap around"
-     * elements[maxElements-1], ending at elements[decrement(end)].  
-     * For example, elements = {c,a,b}, start=1, end=1 corresponds to 
+     * elements[maxElements-1], ending at elements[decrement(end)].
+     * For example, elements = {c,a,b}, start=1, end=1 corresponds to
      * the buffer [a,b,c].
      */
     private transient int end = 0;
-    
+
     /** Flag to indicate if the buffer is currently full. */
     private transient boolean full = false;
-    
+
     /** Capacity of the buffer */
     private final int maxElements;
 
@@ -104,11 +104,12 @@
      * @param size  the maximum number of elements for this fifo
      * @throws IllegalArgumentException  if the size is less than 1
      */
+    @SuppressWarnings("unchecked")
     public BoundedFifoBuffer(int size) {
         if (size <= 0) {
             throw new IllegalArgumentException("The size must be greater than 0");
         }
-        elements = new Object[size];
+        elements = (E[]) new Object[size];
         maxElements = elements.length;
     }
 
@@ -120,7 +121,7 @@
      * @param coll  the collection whose elements to add, may not be null
      * @throws NullPointerException if the collection is null
      */
-    public BoundedFifoBuffer(Collection coll) {
+    public BoundedFifoBuffer(Collection<? extends E> coll) {
         this(coll.size());
         addAll(coll);
     }
@@ -128,31 +129,32 @@
     //-----------------------------------------------------------------------
     /**
      * Write the buffer out using a custom routine.
-     * 
+     *
      * @param out  the output stream
      * @throws IOException
      */
     private void writeObject(ObjectOutputStream out) throws IOException {
         out.defaultWriteObject();
         out.writeInt(size());
-        for (Iterator it = iterator(); it.hasNext();) {
+        for (Iterator<E> it = iterator(); it.hasNext();) {
             out.writeObject(it.next());
         }
     }
 
     /**
      * Read the buffer in using a custom routine.
-     * 
+     *
      * @param in  the input stream
      * @throws IOException
      * @throws ClassNotFoundException
      */
+    @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
         in.defaultReadObject();
-        elements = new Object[maxElements];
+        elements = (E[]) new Object[maxElements];
         int size = in.readInt();
         for (int i = 0; i < size; i++) {
-            elements[i] = in.readObject();
+            elements[i] = (E) in.readObject();
         }
         start = 0;
         full = (size == maxElements);
@@ -200,7 +202,7 @@
     public boolean isFull() {
         return size() == maxElements;
     }
-    
+
     /**
      * Gets the maximum size of the collection (the bound).
      *
@@ -209,7 +211,7 @@
     public int maxSize() {
         return maxElements;
     }
-    
+
     /**
      * Clears this buffer.
      */
@@ -228,7 +230,7 @@
      * @throws NullPointerException  if the given element is null
      * @throws BufferOverflowException  if this buffer is full
      */
-    public boolean add(Object element) {
+    public boolean add(E element) {
         if (null == element) {
             throw new NullPointerException("Attempted to add null object to buffer");
         }
@@ -256,11 +258,10 @@
      * @return the least recently inserted element
      * @throws BufferUnderflowException  if the buffer is empty
      */
-    public Object get() {
+    public E get() {
         if (isEmpty()) {
             throw new BufferUnderflowException("The buffer is already empty");
         }
-
         return elements[start];
     }
 
@@ -270,12 +271,12 @@
      * @return the least recently inserted element
      * @throws BufferUnderflowException  if the buffer is empty
      */
-    public Object remove() {
+    public E remove() {
         if (isEmpty()) {
             throw new BufferUnderflowException("The buffer is already empty");
         }
 
-        Object element = elements[start];
+        E element = elements[start];
 
         if (null != element) {
             elements[start++] = null;
@@ -283,21 +284,19 @@
             if (start >= maxElements) {
                 start = 0;
             }
-
             full = false;
         }
-
         return element;
     }
 
     /**
      * Increments the internal index.
-     * 
+     *
      * @param index  the index to increment
      * @return the updated index
      */
     private int increment(int index) {
-        index++; 
+        index++;
         if (index >= maxElements) {
             index = 0;
         }
@@ -306,7 +305,7 @@
 
     /**
      * Decrements the internal index.
-     * 
+     *
      * @param index  the index to decrement
      * @return the updated index
      */
@@ -323,8 +322,8 @@
      *
      * @return an iterator over this buffer's elements
      */
-    public Iterator iterator() {
-        return new Iterator() {
+    public Iterator<E> iterator() {
+        return new Iterator<E>() {
 
             private int index = start;
             private int lastReturnedIndex = -1;
@@ -332,10 +331,9 @@
 
             public boolean hasNext() {
                 return isFirst || (index != end);
-                
             }
 
-            public Object next() {
+            public E next() {
                 if (!hasNext()) {
                     throw new NoSuchElementException();
                 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/CircularFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/CircularFifoBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/CircularFifoBuffer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/CircularFifoBuffer.java Tue Sep 15 05:29:56 2009
@@ -18,11 +18,11 @@
 
 import java.util.Collection;
 
-/** 
+/**
  * CircularFifoBuffer is a first in first out buffer with a fixed size that
  * replaces its oldest element if full.
  * <p>
- * The removal order of a <code>CircularFifoBuffer</code> is based on the 
+ * The removal order of a <code>CircularFifoBuffer</code> is based on the
  * insertion order; elements are removed in the same order in which they
  * were added.  The iteration order is the same as the removal order.
  * <p>
@@ -46,7 +46,7 @@
  * @author Stefano Fornari
  * @author Stephen Colebourne
  */
-public class CircularFifoBuffer extends BoundedFifoBuffer {
+public class CircularFifoBuffer<E> extends BoundedFifoBuffer<E> {
 
     /** Serialization version */
     private static final long serialVersionUID = -8423413834657610406L;
@@ -60,7 +60,7 @@
 
     /**
      * Constructor that creates a buffer with the specified size.
-     * 
+     *
      * @param size  the size of the buffer (cannot be changed)
      * @throws IllegalArgumentException  if the size is less than 1
      */
@@ -71,11 +71,11 @@
     /**
      * Constructor that creates a buffer from the specified collection.
      * The collection size also sets the buffer size
-     * 
+     *
      * @param coll  the collection to copy into the buffer, may not be null
      * @throws NullPointerException if the collection is null
      */
-    public CircularFifoBuffer(Collection coll) {
+    public CircularFifoBuffer(Collection<E> coll) {
         super(coll);
     }
 
@@ -86,11 +86,11 @@
      * @param element the element to add
      * @return true, always
      */
-    public boolean add(Object element) {
+    public boolean add(E element) {
         if (isFull()) {
             remove();
         }
         return super.add(element);
     }
-    
+
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java Tue Sep 15 05:29:56 2009
@@ -24,6 +24,7 @@
 
 import org.apache.commons.collections.Buffer;
 import org.apache.commons.collections.BufferUnderflowException;
+import org.apache.commons.collections.comparators.ComparableComparator;
 
 /**
  * Binary heap implementation of <code>Buffer</code> that provides for
@@ -62,8 +63,7 @@
  * @author Stephen Colebourne
  * @author Steve Phelps
  */
-public class PriorityBuffer extends AbstractCollection
-        implements Buffer, Serializable {
+public class PriorityBuffer<E> extends AbstractCollection<E> implements Buffer<E>, Serializable {
 
     /** Serialization lock. */
     private static final long serialVersionUID = 6891186490470027896L;
@@ -76,21 +76,24 @@
     /**
      * The elements in this buffer.
      */
-    protected Object[] elements;
+    protected E[] elements;
+
     /**
      * The number of elements currently in this buffer.
      */
     protected int size;
+
     /**
      * If true, the first element as determined by the sort order will 
      * be returned.  If false, the last element as determined by the
      * sort order will be returned.
      */
     protected boolean ascendingOrder;
+
     /**
      * The comparator used to order the elements
      */
-    protected Comparator comparator;
+    protected Comparator<? super E> comparator;
 
     //-----------------------------------------------------------------------
     /**
@@ -108,7 +111,7 @@
      * @param comparator  the comparator used to order the elements,
      *  null means use natural order
      */
-    public PriorityBuffer(Comparator comparator) {
+    public PriorityBuffer(Comparator<? super E> comparator) {
         this(DEFAULT_CAPACITY, true, comparator);
     }
 
@@ -131,7 +134,7 @@
      * @param comparator  the comparator used to order the elements,
      *  null means use natural order
      */
-    public PriorityBuffer(boolean ascendingOrder, Comparator comparator) {
+    public PriorityBuffer(boolean ascendingOrder, Comparator<? super E> comparator) {
         this(DEFAULT_CAPACITY, ascendingOrder, comparator);
     }
 
@@ -155,7 +158,7 @@
      *  null means use natural order
      * @throws IllegalArgumentException if <code>capacity</code> is &lt;= <code>0</code>
      */
-    public PriorityBuffer(int capacity, Comparator comparator) {
+    public PriorityBuffer(int capacity, Comparator<? super E> comparator) {
         this(capacity, true, comparator);
     }
 
@@ -183,7 +186,8 @@
      *  null means use natural order
      * @throws IllegalArgumentException if <code>capacity</code> is <code>&lt;= 0</code>
      */
-    public PriorityBuffer(int capacity, boolean ascendingOrder, Comparator comparator) {
+    @SuppressWarnings("unchecked")
+    public PriorityBuffer(int capacity, boolean ascendingOrder, Comparator<? super E> comparator) {
         super();
         if (capacity <= 0) {
             throw new IllegalArgumentException("invalid capacity");
@@ -191,8 +195,8 @@
         this.ascendingOrder = ascendingOrder;
 
         //+1 as 0 is noop
-        this.elements = new Object[capacity + 1];
-        this.comparator = comparator;
+        this.elements = (E[]) new Object[capacity + 1];
+        this.comparator = (Comparator<? super E>) (comparator == null ? ComparableComparator.INSTANCE : comparator);
     }
 
     //-----------------------------------------------------------------------
@@ -210,7 +214,7 @@
      * 
      * @return the comparator in use, null is natural order
      */
-    public Comparator comparator() {
+    public Comparator<? super E> comparator() {
         return comparator;
     }
     
@@ -227,8 +231,9 @@
     /**
      * Clears all elements from the buffer.
      */
+    @SuppressWarnings("unchecked")
     public void clear() {
-        elements = new Object[elements.length]; // for gc
+        elements = (E[]) new Object[elements.length]; // for gc
         size = 0;
     }
 
@@ -240,11 +245,11 @@
      * @param element  the element to be added
      * @return true always
      */
-    public boolean add(Object element) {
+    public boolean add(E element) {
         if (isAtCapacity()) {
             grow();
         }
-        // percolate element to it's place in tree
+        // percolate element to its place in tree
         if (ascendingOrder) {
             percolateUpMinHeap(element);
         } else {
@@ -259,12 +264,11 @@
      * @return the next element
      * @throws BufferUnderflowException if the buffer is empty
      */
-    public Object get() {
+    public E get() {
         if (isEmpty()) {
             throw new BufferUnderflowException();
-        } else {
-            return elements[1];
         }
+        return elements[1];
     }
 
     /**
@@ -273,8 +277,8 @@
      * @return the next element
      * @throws BufferUnderflowException if the buffer is empty
      */
-    public Object remove() {
-        final Object result = get();
+    public E remove() {
+        final E result = get();
         elements[1] = elements[size--];
 
         // set the unused element to 'null' so that the garbage collector
@@ -313,7 +317,7 @@
      * @param index the index for the element
      */
     protected void percolateDownMinHeap(final int index) {
-        final Object element = elements[index];
+        final E element = elements[index];
         int hole = index;
 
         while ((hole * 2) <= size) {
@@ -345,7 +349,7 @@
      * @param index the index of the element
      */
     protected void percolateDownMaxHeap(final int index) {
-        final Object element = elements[index];
+        final E element = elements[index];
         int hole = index;
 
         while ((hole * 2) <= size) {
@@ -378,7 +382,7 @@
      */
     protected void percolateUpMinHeap(final int index) {
         int hole = index;
-        Object element = elements[hole];
+        E element = elements[hole];
         while (hole > 1 && compare(element, elements[hole / 2]) < 0) {
             // save element that is being pushed down
             // as the element "bubble" is percolated up
@@ -396,7 +400,7 @@
      *
      * @param element the element
      */
-    protected void percolateUpMinHeap(final Object element) {
+    protected void percolateUpMinHeap(final E element) {
         elements[++size] = element;
         percolateUpMinHeap(size);
     }
@@ -410,7 +414,7 @@
      */
     protected void percolateUpMaxHeap(final int index) {
         int hole = index;
-        Object element = elements[hole];
+        E element = elements[hole];
 
         while (hole > 1 && compare(element, elements[hole / 2]) > 0) {
             // save element that is being pushed down
@@ -430,7 +434,7 @@
      *
      * @param element the element
      */
-    protected void percolateUpMaxHeap(final Object element) {
+    protected void percolateUpMaxHeap(final E element) {
         elements[++size] = element;
         percolateUpMaxHeap(size);
     }
@@ -443,19 +447,16 @@
      * @param b  the second object
      * @return -ve if a less than b, 0 if they are equal, +ve if a greater than b
      */
-    protected int compare(Object a, Object b) {
-        if (comparator != null) {
-            return comparator.compare(a, b);
-        } else {
-            return ((Comparable) a).compareTo(b);
-        }
+    protected int compare(E a, E b) {
+        return comparator.compare(a, b);
     }
 
     /**
      * Increases the size of the heap to support additional elements
      */
+    @SuppressWarnings("unchecked")
     protected void grow() {
-        final Object[] array = new Object[elements.length * 2];
+        final E[] array = (E[]) new Object[elements.length * 2];
         System.arraycopy(elements, 0, array, 0, elements.length);
         elements = array;
     }
@@ -466,8 +467,8 @@
      *
      * @return an iterator over this heap's elements
      */
-    public Iterator iterator() {
-        return new Iterator() {
+    public Iterator<E> iterator() {
+        return new Iterator<E>() {
 
             private int index = 1;
             private int lastReturnedIndex = -1;
@@ -476,7 +477,7 @@
                 return index <= size;
             }
 
-            public Object next() {
+            public E next() {
                 if (!hasNext()) {
                     throw new NoSuchElementException();
                 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/TransformedBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/TransformedBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/TransformedBuffer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/TransformedBuffer.java Tue Sep 15 05:29:56 2009
@@ -35,7 +35,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TransformedBuffer extends TransformedCollection implements Buffer {
+public class TransformedBuffer<E> extends TransformedCollection<E> implements Buffer<E> {
 
     /** Serialization version */
     private static final long serialVersionUID = -7901091318986132033L;
@@ -52,8 +52,8 @@
      * @return a new transformed Buffer
      * @throws IllegalArgumentException if buffer or transformer is null
      */
-    public static Buffer decorate(Buffer buffer, Transformer transformer) {
-        return new TransformedBuffer(buffer, transformer);
+    public static <E> Buffer<E> decorate(Buffer<E> buffer, Transformer<? super E, ? extends E> transformer) {
+        return new TransformedBuffer<E>(buffer, transformer);
     }
     
     /**
@@ -70,13 +70,14 @@
      * @throws IllegalArgumentException if buffer or transformer is null
      * @since Commons Collections 3.3
      */
+    // TODO: Generics
     public static Buffer decorateTransform(Buffer buffer, Transformer transformer) {
         TransformedBuffer decorated = new TransformedBuffer(buffer, transformer);
         if (transformer != null && buffer != null && buffer.size() > 0) {
             Object[] values = buffer.toArray();
             buffer.clear();
             for(int i=0; i<values.length; i++) {
-                decorated.getCollection().add(transformer.transform(values[i]));
+                decorated.decorated().add(transformer.transform(values[i]));
             }
         }
         return decorated;
@@ -93,7 +94,7 @@
      * @param transformer  the transformer to use for conversion, must not be null
      * @throws IllegalArgumentException if buffer or transformer is null
      */
-    protected TransformedBuffer(Buffer buffer, Transformer transformer) {
+    protected TransformedBuffer(Buffer<E> buffer, Transformer<? super E, ? extends E> transformer) {
         super(buffer, transformer);
     }
 
@@ -102,16 +103,16 @@
      * 
      * @return the decorated buffer
      */
-    protected Buffer getBuffer() {
-        return (Buffer) collection;
+    protected Buffer<E> getBuffer() {
+        return (Buffer<E>) collection;
     }
 
     //-----------------------------------------------------------------------
-    public Object get() {
+    public E get() {
         return getBuffer().get();
     }
 
-    public Object remove() {
+    public E remove() {
         return getBuffer().remove();
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java Tue Sep 15 05:29:56 2009
@@ -63,7 +63,7 @@
  * @author Thomas Knych
  * @author Jordan Krey
  */
-public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, Serializable {
+public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buffer<E>, Serializable {
     // invariant: buffer.length > size()
     //   ie.buffer always has at least one empty entry
 
@@ -71,9 +71,11 @@
     private static final long serialVersionUID = -3482960336579541419L;
 
     /** The array of objects in the buffer. */
-    protected transient Object[] buffer;
+    protected transient E[] buffer;
+
     /** The current head index. */
     protected transient int head;
+
     /** The current tail index. */
     protected transient int tail;
 
@@ -92,15 +94,16 @@
     /**
      * Constructs an UnboundedFifoBuffer with the specified number of elements.
      * The integer must be a positive integer.
-     * 
+     *
      * @param initialSize  the initial size of the buffer
      * @throws IllegalArgumentException  if the size is less than 1
      */
+    @SuppressWarnings("unchecked")
     public UnboundedFifoBuffer(int initialSize) {
         if (initialSize <= 0) {
             throw new IllegalArgumentException("The size must be greater than 0");
         }
-        buffer = new Object[initialSize + 1];
+        buffer = (E[]) new Object[initialSize + 1];
         head = 0;
         tail = 0;
     }
@@ -108,7 +111,7 @@
     //-----------------------------------------------------------------------
     /**
      * Write the buffer out using a custom routine.
-     * 
+     *
      * @param out  the output stream
      * @throws IOException
      */
@@ -116,25 +119,26 @@
         out.defaultWriteObject();
         out.writeInt(size());
         out.writeInt(buffer.length);
-        for (Iterator it = iterator(); it.hasNext();) {
+        for (Iterator<E> it = iterator(); it.hasNext();) {
             out.writeObject(it.next());
         }
     }
 
     /**
      * Read the buffer in using a custom routine.
-     * 
+     *
      * @param in  the input stream
      * @throws IOException
      * @throws ClassNotFoundException
      */
+    @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
         in.defaultReadObject();
         int size = in.readInt();
         int length = in.readInt();
-        buffer = new Object[length];
+        buffer = (E[]) new Object[length];
         for (int i = 0; i < size; i++) {
-            buffer[i] = in.readObject();
+            buffer[i] = (E) in.readObject();
         }
         head = 0;
         tail = size;
@@ -174,14 +178,15 @@
      * @return true, always
      * @throws NullPointerException  if the given element is null
      */
-    public boolean add(final Object obj) {
+    @SuppressWarnings("unchecked")
+    public boolean add(final E obj) {
         if (obj == null) {
             throw new NullPointerException("Attempted to add null object to buffer");
         }
 
         if (size() + 1 >= buffer.length) {
             // copy contents to a new buffer array
-            Object[] tmp = new Object[((buffer.length - 1) * 2) + 1];
+            E[] tmp = (E[]) new Object[((buffer.length - 1) * 2) + 1];
             int j = 0;
             // move head to element zero in the new array
             for (int i = head; i != tail;) {
@@ -207,7 +212,7 @@
      * @return the next object in the buffer
      * @throws BufferUnderflowException  if this buffer is empty
      */
-    public Object get() {
+    public E get() {
         if (isEmpty()) {
             throw new BufferUnderflowException("The buffer is already empty");
         }
@@ -221,12 +226,12 @@
      * @return the removed object
      * @throws BufferUnderflowException  if this buffer is empty
      */
-    public Object remove() {
+    public E remove() {
         if (isEmpty()) {
             throw new BufferUnderflowException("The buffer is already empty");
         }
 
-        Object element = buffer[head];
+        E element = buffer[head];
         if (element != null) {
             buffer[head] = null;
             head = increment(head);
@@ -236,7 +241,7 @@
 
     /**
      * Increments the internal index.
-     * 
+     *
      * @param index  the index to increment
      * @return the updated index
      */
@@ -250,7 +255,7 @@
 
     /**
      * Decrements the internal index.
-     * 
+     *
      * @param index  the index to decrement
      * @return the updated index
      */
@@ -267,8 +272,8 @@
      *
      * @return an iterator over this buffer's elements
      */
-    public Iterator iterator() {
-        return new Iterator() {
+    public Iterator<E> iterator() {
+        return new Iterator<E>() {
 
             private int index = head;
             private int lastReturnedIndex = -1;
@@ -278,7 +283,7 @@
 
             }
 
-            public Object next() {
+            public E next() {
                 if (!hasNext()) {
                     throw new NoSuchElementException();
                 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/BooleanComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/BooleanComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/BooleanComparator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/BooleanComparator.java Tue Sep 15 05:29:56 2009
@@ -32,7 +32,7 @@
  *
  * @author Rodney Waldhoff
  */
-public final class BooleanComparator implements Comparator, Serializable {
+public final class BooleanComparator implements Comparator<Boolean>, Serializable {
 
     /** Serialization version. */
     private static final long serialVersionUID = 1830042991606340609L;
@@ -127,22 +127,6 @@
 
     //-----------------------------------------------------------------------
     /**
-     * Compares two arbitrary Objects.
-     * When both arguments are <code>Boolean</code>, this method is equivalent to 
-     * {@link #compare(Boolean,Boolean) compare((Boolean)<i>obj1</i>,(Boolean)<i>obj2</i>)}.
-     * When either argument is not a <code>Boolean</code>, this methods throws
-     * a {@link ClassCastException}.
-     * 
-     * @param obj1  the first object to compare
-     * @param obj2  the second object to compare
-     * @return negative if obj1 is less, positive if greater, zero if equal
-     * @throws ClassCastException when either argument is not <code>Boolean</code>
-     */
-    public int compare(Object obj1, Object obj2) {
-        return compare((Boolean)obj1, (Boolean)obj2);
-    }
-    
-    /**
      * Compares two non-<code>null</code> <code>Boolean</code> objects
      * according to the value of {@link #sortsTrueFirst()}.
      * 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparableComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparableComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparableComparator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparableComparator.java Tue Sep 15 05:29:56 2009
@@ -40,13 +40,14 @@
  *
  * @see java.util.Collections#reverseOrder()
  */
-public class ComparableComparator implements Comparator, Serializable {
+public class ComparableComparator<E extends Comparable<? super E>> implements Comparator<E>, Serializable {
 
     /** Serialization version. */
     private static final long serialVersionUID=-291439688585137865L;
 
     /** The singleton instance. */
-    private static final ComparableComparator instance = new ComparableComparator();
+    @SuppressWarnings("unchecked")
+    public static final ComparableComparator<?> INSTANCE = new ComparableComparator();
 
     //-----------------------------------------------------------------------
     /**
@@ -58,8 +59,9 @@
      * 
      * @return the singleton ComparableComparator
      */
-    public static ComparableComparator getInstance() {
-        return instance;
+    @SuppressWarnings("unchecked")
+    public static <E extends Comparable<? super E>> ComparableComparator<E> getInstance() {
+        return (ComparableComparator<E>) INSTANCE;
     }
 
     //-----------------------------------------------------------------------
@@ -86,8 +88,8 @@
      * @throws ClassCastException when <i>obj1</i> is not a <code>Comparable</code>,
      *         or when <code>((Comparable)obj1).compareTo(obj2)</code> does
      */
-    public int compare(Object obj1, Object obj2) {
-        return ((Comparable)obj1).compareTo(obj2);
+    public int compare(E obj1, E obj2) {
+        return obj1.compareTo(obj2);
     }
 
     //-----------------------------------------------------------------------

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparatorChain.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparatorChain.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparatorChain.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ComparatorChain.java Tue Sep 15 05:29:56 2009
@@ -54,13 +54,13 @@
  * @author Morgan Delagrange
  * @version $Revision$ $Date$
  */
-public class ComparatorChain implements Comparator, Serializable {
+public class ComparatorChain<E> implements Comparator<E>, Serializable {
 
     /** Serialization version from Collections 2.0. */
     private static final long serialVersionUID = -721644942746081630L;
-    
+
     /** The list of comparators in the chain. */
-    protected List comparatorChain = null;
+    protected List<Comparator<E>> comparatorChain = null;
     /** Order - false (clear) = ascend; true (set) = descend. */
     protected BitSet orderingBits = null;
    /** Whether the chain has been "locked". */
@@ -70,32 +70,32 @@
     /**
      * Construct a ComparatorChain with no Comparators.
      * You must add at least one Comparator before calling
-     * the compare(Object,Object) method, or an 
+     * the compare(Object,Object) method, or an
      * UnsupportedOperationException is thrown
      */
     public ComparatorChain() {
-        this(new ArrayList(),new BitSet());
+        this(new ArrayList<Comparator<E>>(), new BitSet());
     }
 
     /**
      * Construct a ComparatorChain with a single Comparator,
      * sorting in the forward order
-     * 
+     *
      * @param comparator First comparator in the Comparator chain
      */
-    public ComparatorChain(Comparator comparator) {
-        this(comparator,false);
+    public ComparatorChain(Comparator<E> comparator) {
+        this(comparator, false);
     }
 
     /**
      * Construct a Comparator chain with a single Comparator,
      * sorting in the given order
-     * 
+     *
      * @param comparator First Comparator in the ComparatorChain
      * @param reverse    false = forward sort; true = reverse sort
      */
-    public ComparatorChain(Comparator comparator, boolean reverse) {
-        comparatorChain = new ArrayList();
+    public ComparatorChain(Comparator<E> comparator, boolean reverse) {
+        comparatorChain = new ArrayList<Comparator<E>>();
         comparatorChain.add(comparator);
         orderingBits = new BitSet(1);
         if (reverse == true) {
@@ -105,14 +105,14 @@
 
     /**
      * Construct a ComparatorChain from the Comparators in the
-     * List.  All Comparators will default to the forward 
+     * List.  All Comparators will default to the forward
      * sort order.
-     * 
+     *
      * @param list   List of Comparators
      * @see #ComparatorChain(List,BitSet)
      */
-    public ComparatorChain(List list) {
-        this(list,new BitSet(list.size()));
+    public ComparatorChain(List<Comparator<E>> list) {
+        this(list, new BitSet(list.size()));
     }
 
     /**
@@ -124,13 +124,13 @@
      * If that method returns <i>false</i>, the forward
      * sort order is used; a return value of <i>true</i>
      * indicates reverse sort order.
-     * 
+     *
      * @param list   List of Comparators.  NOTE: This constructor does not perform a
      *               defensive copy of the list
      * @param bits   Sort order for each Comparator.  Extra bits are ignored,
      *               unless extra Comparators are added by another method.
      */
-    public ComparatorChain(List list, BitSet bits) {
+    public ComparatorChain(List<Comparator<E>> list, BitSet bits) {
         comparatorChain = list;
         orderingBits = bits;
     }
@@ -139,23 +139,23 @@
     /**
      * Add a Comparator to the end of the chain using the
      * forward sort order
-     * 
+     *
      * @param comparator Comparator with the forward sort order
      */
-    public void addComparator(Comparator comparator) {
-        addComparator(comparator,false);
+    public void addComparator(Comparator<E> comparator) {
+        addComparator(comparator, false);
     }
 
     /**
      * Add a Comparator to the end of the chain using the
      * given sort order
-     * 
+     *
      * @param comparator Comparator to add to the end of the chain
      * @param reverse    false = forward sort order; true = reverse sort order
      */
-    public void addComparator(Comparator comparator, boolean reverse) {
+    public void addComparator(Comparator<E> comparator, boolean reverse) {
         checkLocked();
-        
+
         comparatorChain.add(comparator);
         if (reverse == true) {
             orderingBits.set(comparatorChain.size() - 1);
@@ -165,26 +165,25 @@
     /**
      * Replace the Comparator at the given index, maintaining
      * the existing sort order.
-     * 
+     *
      * @param index      index of the Comparator to replace
      * @param comparator Comparator to place at the given index
      * @exception IndexOutOfBoundsException
      *                   if index &lt; 0 or index &gt;= size()
      */
-    public void setComparator(int index, Comparator comparator) 
-    throws IndexOutOfBoundsException {
-        setComparator(index,comparator,false);
+    public void setComparator(int index, Comparator<E> comparator) throws IndexOutOfBoundsException {
+        setComparator(index, comparator, false);
     }
 
     /**
      * Replace the Comparator at the given index in the
      * ComparatorChain, using the given sort order
-     * 
+     *
      * @param index      index of the Comparator to replace
      * @param comparator Comparator to set
      * @param reverse    false = forward sort order; true = reverse sort order
      */
-    public void setComparator(int index, Comparator comparator, boolean reverse) {
+    public void setComparator(int index, Comparator<E> comparator, boolean reverse) {
         checkLocked();
 
         comparatorChain.set(index,comparator);
@@ -195,11 +194,10 @@
         }
     }
 
-
     /**
      * Change the sort order at the given index in the
      * ComparatorChain to a forward sort.
-     * 
+     *
      * @param index  Index of the ComparatorChain
      */
     public void setForwardSort(int index) {
@@ -210,7 +208,7 @@
     /**
      * Change the sort order at the given index in the
      * ComparatorChain to a reverse sort.
-     * 
+     *
      * @param index  Index of the ComparatorChain
      */
     public void setReverseSort(int index) {
@@ -220,7 +218,7 @@
 
     /**
      * Number of Comparators in the current ComparatorChain.
-     * 
+     *
      * @return Comparator count
      */
     public int size() {
@@ -231,8 +229,8 @@
      * Determine if modifications can still be made to the
      * ComparatorChain.  ComparatorChains cannot be modified
      * once they have performed a comparison.
-     * 
-     * @return true = ComparatorChain cannot be modified; false = 
+     *
+     * @return true = ComparatorChain cannot be modified; false =
      *         ComparatorChain can still be modified.
      */
     public boolean isLocked() {
@@ -256,7 +254,7 @@
     /**
      * Perform comparisons on the Objects as per
      * Comparator.compare(o1,o2).
-     * 
+     *
      * @param o1  the first object to compare
      * @param o2  the second object to compare
      * @return -1, 0, or 1
@@ -264,31 +262,29 @@
      *                   if the ComparatorChain does not contain at least one
      *                   Comparator
      */
-    public int compare(Object o1, Object o2) throws UnsupportedOperationException {
+    public int compare(E o1, E o2) throws UnsupportedOperationException {
         if (isLocked == false) {
             checkChainIntegrity();
             isLocked = true;
         }
 
         // iterate over all comparators in the chain
-        Iterator comparators = comparatorChain.iterator();
+        Iterator<Comparator<E>> comparators = comparatorChain.iterator();
         for (int comparatorIndex = 0; comparators.hasNext(); ++comparatorIndex) {
 
-            Comparator comparator = (Comparator) comparators.next();
+            Comparator<E> comparator = comparators.next();
             int retval = comparator.compare(o1,o2);
             if (retval != 0) {
                 // invert the order if it is a reverse sort
                 if (orderingBits.get(comparatorIndex) == true) {
                     if(Integer.MIN_VALUE == retval) {
                         retval = Integer.MAX_VALUE;
-                    } else {                        
+                    } else {
                         retval *= -1;
                     }
                 }
-
                 return retval;
             }
-
         }
 
         // if comparators are exhausted, return 0
@@ -299,49 +295,51 @@
     /**
      * Implement a hash code for this comparator that is consistent with
      * {@link #equals(Object) equals}.
-     * 
+     *
      * @return a suitable hash code
      * @since Commons Collections 3.0
      */
     public int hashCode() {
         int hash = 0;
-        if(null != comparatorChain) {
+        if (null != comparatorChain) {
             hash ^= comparatorChain.hashCode();
         }
-        if(null != orderingBits) {
+        if (null != orderingBits) {
             hash ^= orderingBits.hashCode();
         }
         return hash;
     }
 
     /**
-     * Returns <code>true</code> iff <i>that</i> Object is 
-     * is a {@link Comparator} whose ordering is known to be 
+     * Returns <code>true</code> iff <i>that</i> Object is
+     * is a {@link Comparator} whose ordering is known to be
      * equivalent to mine.
      * <p>
      * This implementation returns <code>true</code>
      * iff <code><i>object</i>.{@link Object#getClass() getClass()}</code>
-     * equals <code>this.getClass()</code>, and the underlying 
+     * equals <code>this.getClass()</code>, and the underlying
      * comparators and order bits are equal.
      * Subclasses may want to override this behavior to remain consistent
      * with the {@link Comparator#equals(Object)} contract.
-     * 
+     *
      * @param object  the object to compare with
      * @return true if equal
      * @since Commons Collections 3.0
      */
     public boolean equals(Object object) {
-        if(this == object) {
+        if (this == object) {
             return true;
-        } else if(null == object) {
-            return false;
-        } else if(object.getClass().equals(this.getClass())) {
-            ComparatorChain chain = (ComparatorChain)object;
-            return ( (null == orderingBits ? null == chain.orderingBits : orderingBits.equals(chain.orderingBits))
-                   && (null == comparatorChain ? null == chain.comparatorChain : comparatorChain.equals(chain.comparatorChain)) );
-        } else {
+        }
+        if (null == object) {
             return false;
         }
+        if (object.getClass().equals(this.getClass())) {
+            ComparatorChain<?> chain = (ComparatorChain<?>) object;
+            return ((null == orderingBits ? null == chain.orderingBits : orderingBits
+                    .equals(chain.orderingBits)) && (null == comparatorChain ? null == chain.comparatorChain
+                    : comparatorChain.equals(chain.comparatorChain)));
+        }
+        return false;
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/FixedOrderComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/FixedOrderComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/FixedOrderComparator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/FixedOrderComparator.java Tue Sep 15 05:29:56 2009
@@ -18,11 +18,10 @@
 
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-/** 
+/**
  * A Comparator which imposes a specific order on a specific set of Objects.
  * Objects are presented to the FixedOrderComparator in a specified order and
  * subsequent calls to {@link #compare(Object, Object) compare} yield that order.
@@ -48,55 +47,47 @@
  * @author Stephen Colebourne
  * @author Janek Bogucki
  */
-public class FixedOrderComparator implements Comparator {
+public class FixedOrderComparator<T> implements Comparator<T> {
 
-    /** 
-     * Behavior when comparing unknown Objects:
-     * unknown objects compare as before known Objects.
-     */
-    public static final int UNKNOWN_BEFORE = 0;
-
-    /** 
-     * Behavior when comparing unknown Objects:
-     * unknown objects compare as after known Objects.
-     */
-    public static final int UNKNOWN_AFTER = 1;
-
-    /** 
-     * Behavior when comparing unknown Objects:
-     * unknown objects cause a IllegalArgumentException to be thrown.
-     * This is the default behavior.
+    /**
+     * Unknown object behavior enum.
+     * @since Commons Collections 5
      */
-    public static final int UNKNOWN_THROW_EXCEPTION = 2;
+    public static enum UnknownObjectBehavior {
+        BEFORE, AFTER, EXCEPTION;
+    }
 
     /** Internal map of object to position */
-    private final Map map = new HashMap();
+    private final Map<T, Integer> map = new HashMap<T, Integer>();
+
     /** Counter used in determining the position in the map */
     private int counter = 0;
+
     /** Is the comparator locked against further change */
     private boolean isLocked = false;
+
     /** The behaviour in the case of an unknown object */
-    private int unknownObjectBehavior = UNKNOWN_THROW_EXCEPTION;
+    private UnknownObjectBehavior unknownObjectBehavior = UnknownObjectBehavior.EXCEPTION;
 
     // Constructors
     //-----------------------------------------------------------------------
-    /** 
+    /**
      * Constructs an empty FixedOrderComparator.
      */
     public FixedOrderComparator() {
         super();
     }
 
-    /** 
+    /**
      * Constructs a FixedOrderComparator which uses the order of the given array
      * to compare the objects.
      * <p>
      * The array is copied, so later changes will not affect the comparator.
-     * 
+     *
      * @param items  the items that the comparator can compare in order
      * @throws IllegalArgumentException if the array is null
      */
-    public FixedOrderComparator(Object[] items) {
+    public FixedOrderComparator(T[] items) {
         super();
         if (items == null) {
             throw new IllegalArgumentException("The list of items must not be null");
@@ -106,22 +97,22 @@
         }
     }
 
-    /** 
+    /**
      * Constructs a FixedOrderComparator which uses the order of the given list
      * to compare the objects.
      * <p>
      * The list is copied, so later changes will not affect the comparator.
-     * 
+     *
      * @param items  the items that the comparator can compare in order
      * @throws IllegalArgumentException if the list is null
      */
-    public FixedOrderComparator(List items) {
+    public FixedOrderComparator(List<T> items) {
         super();
         if (items == null) {
             throw new IllegalArgumentException("The list of items must not be null");
         }
-        for (Iterator it = items.iterator(); it.hasNext();) {
-            add(it.next());
+        for (T t : items) {
+            add(t);
         }
     }
 
@@ -130,7 +121,7 @@
     /**
      * Returns true if modifications cannot be made to the FixedOrderComparator.
      * FixedOrderComparators cannot be modified once they have performed a comparison.
-     * 
+     *
      * @return true if attempts to change the FixedOrderComparator yield an
      *  UnsupportedOperationException, false if it can be changed.
      */
@@ -140,7 +131,7 @@
 
     /**
      * Checks to see whether the comparator is now locked against further changes.
-     * 
+     *
      * @throws UnsupportedOperationException if the comparator is locked
      */
     protected void checkLocked() {
@@ -149,118 +140,108 @@
         }
     }
 
-    /** 
+    /**
      * Gets the behavior for comparing unknown objects.
-     * 
-     * @return the flag for unknown behaviour - UNKNOWN_AFTER,
-     * UNKNOWN_BEFORE or UNKNOWN_THROW_EXCEPTION
+     *
+     * @return {@link UnknownObjectBehavior}
      */
-    public int getUnknownObjectBehavior() {
+    public UnknownObjectBehavior getUnknownObjectBehavior() {
         return unknownObjectBehavior;
     }
 
-    /** 
+    /**
      * Sets the behavior for comparing unknown objects.
-     * 
+     *
      * @param unknownObjectBehavior  the flag for unknown behaviour -
      * UNKNOWN_AFTER, UNKNOWN_BEFORE or UNKNOWN_THROW_EXCEPTION
      * @throws UnsupportedOperationException if a comparison has been performed
      * @throws IllegalArgumentException if the unknown flag is not valid
      */
-    public void setUnknownObjectBehavior(int unknownObjectBehavior) {
+    public void setUnknownObjectBehavior(UnknownObjectBehavior unknownObjectBehavior) {
         checkLocked();
-        if (unknownObjectBehavior != UNKNOWN_AFTER 
-            && unknownObjectBehavior != UNKNOWN_BEFORE 
-            && unknownObjectBehavior != UNKNOWN_THROW_EXCEPTION) {
-            throw new IllegalArgumentException("Unrecognised value for unknown behaviour flag");    
+        if (unknownObjectBehavior == null) {
+            throw new IllegalArgumentException("Unknown object behavior must not be null");
         }
         this.unknownObjectBehavior = unknownObjectBehavior;
     }
 
     // Methods for adding items
     //-----------------------------------------------------------------------
-    /** 
+    /**
      * Adds an item, which compares as after all items known to the Comparator.
      * If the item is already known to the Comparator, its old position is
      * replaced with the new position.
-     * 
+     *
      * @param obj  the item to be added to the Comparator.
      * @return true if obj has been added for the first time, false if
      *  it was already known to the Comparator.
      * @throws UnsupportedOperationException if a comparison has already been made
      */
-    public boolean add(Object obj) {
+    public boolean add(T obj) {
         checkLocked();
-        Object position = map.put(obj, new Integer(counter++));
+        Integer position = map.put(obj, new Integer(counter++));
         return (position == null);
     }
 
     /**
      * Adds a new item, which compares as equal to the given existing item.
-     * 
-     * @param existingObj  an item already in the Comparator's set of 
+     *
+     * @param existingObj  an item already in the Comparator's set of
      *  known objects
      * @param newObj  an item to be added to the Comparator's set of
      *  known objects
      * @return true if newObj has been added for the first time, false if
      *  it was already known to the Comparator.
-     * @throws IllegalArgumentException if existingObject is not in the 
+     * @throws IllegalArgumentException if existingObject is not in the
      *  Comparator's set of known objects.
      * @throws UnsupportedOperationException if a comparison has already been made
      */
-    public boolean addAsEqual(Object existingObj, Object newObj) {
+    public boolean addAsEqual(T existingObj, T newObj) {
         checkLocked();
-        Integer position = (Integer) map.get(existingObj);
+        Integer position = map.get(existingObj);
         if (position == null) {
             throw new IllegalArgumentException(existingObj + " not known to " + this);
         }
-        Object result = map.put(newObj, position);
+        Integer result = map.put(newObj, position);
         return (result == null);
     }
 
     // Comparator methods
     //-----------------------------------------------------------------------
-    /** 
+    /**
      * Compares two objects according to the order of this Comparator.
      * <p>
      * It is important to note that this class will throw an IllegalArgumentException
-     * in the case of an unrecognised object. This is not specified in the 
+     * in the case of an unrecognised object. This is not specified in the
      * Comparator interface, but is the most appropriate exception.
-     * 
+     *
      * @param obj1  the first object to compare
      * @param obj2  the second object to compare
      * @return negative if obj1 is less, positive if greater, zero if equal
-     * @throws IllegalArgumentException if obj1 or obj2 are not known 
+     * @throws IllegalArgumentException if obj1 or obj2 are not known
      *  to this Comparator and an alternative behavior has not been set
      *  via {@link #setUnknownObjectBehavior(int)}.
      */
-    public int compare(Object obj1, Object obj2) {
+    public int compare(T obj1, T obj2) {
         isLocked = true;
-        Integer position1 = (Integer) map.get(obj1);
-        Integer position2 = (Integer) map.get(obj2);
+        Integer position1 = map.get(obj1);
+        Integer position2 = map.get(obj2);
         if (position1 == null || position2 == null) {
             switch (unknownObjectBehavior) {
-                case UNKNOWN_BEFORE :
-                    if (position1 == null) {
-                        return (position2 == null) ? 0 : -1;
-                    } else {
-                        return 1;
-                    }
-                case UNKNOWN_AFTER :
-                    if (position1 == null) {
-                        return (position2 == null) ? 0 : 1;
-                    } else {
-                        return -1;
-                    }
-                case UNKNOWN_THROW_EXCEPTION :
-                    Object unknownObj = (position1 == null) ? obj1 : obj2;
-                    throw new IllegalArgumentException("Attempting to compare unknown object " + unknownObj);
-                default :
-                    throw new UnsupportedOperationException("Unknown unknownObjectBehavior: " + unknownObjectBehavior);
+            case BEFORE:
+                return position1 == null ? position2 == null ? 0 : -1 : 1;
+            case AFTER:
+                return position1 == null ? position2 == null ? 0 : 1 : -1;
+            case EXCEPTION:
+                Object unknownObj = (position1 == null) ? obj1 : obj2;
+                throw new IllegalArgumentException("Attempting to compare unknown object "
+                        + unknownObj);
+            default: //could be null
+                throw new UnsupportedOperationException("Unknown unknownObjectBehavior: "
+                        + unknownObjectBehavior);
             }
-        } else {
-            return position1.compareTo(position2);
         }
+        return position1.compareTo(position2);
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ReverseComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ReverseComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ReverseComparator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/ReverseComparator.java Tue Sep 15 05:29:56 2009
@@ -19,6 +19,8 @@
 import java.io.Serializable;
 import java.util.Comparator;
 
+import org.apache.commons.collections.ComparatorUtils;
+
 /**
  * Reverses the order of another comparator by reversing the arguments
  * to its {@link #compare(Object, Object) compare} method.
@@ -30,13 +32,13 @@
  *
  * @see java.util.Collections#reverseOrder()
  */
-public class ReverseComparator implements Comparator, Serializable {
+public class ReverseComparator<E> implements Comparator<E>, Serializable {
 
     /** Serialization version from Collections 2.0. */
     private static final long serialVersionUID = 2858887242028539265L;
 
     /** The comparator being decorated. */
-    private Comparator comparator;
+    private Comparator<E> comparator;
 
     //-----------------------------------------------------------------------
     /**
@@ -60,12 +62,9 @@
      * 
      * @param comparator Comparator to reverse
      */
-    public ReverseComparator(Comparator comparator) {
-        if(comparator != null) {
-            this.comparator = comparator;
-        } else {
-            this.comparator = ComparableComparator.getInstance();
-        }
+    @SuppressWarnings("unchecked")
+    public ReverseComparator(Comparator<E> comparator) {
+        this.comparator = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : comparator;
     }
 
     //-----------------------------------------------------------------------
@@ -76,7 +75,7 @@
      * @param obj2  the second object to compare
      * @return negative if obj1 is less, positive if greater, zero if equal
      */
-    public int compare(Object obj1, Object obj2) {
+    public int compare(E obj1, E obj2) {
         return comparator.compare(obj2, obj1);
     }
 
@@ -109,16 +108,17 @@
      * @since Commons Collections 3.0
      */
     public boolean equals(Object object) {
-        if(this == object) {
+        if (this == object) {
             return true;
-        } else if(null == object) {
+        }
+        if (null == object) {
             return false;
-        } else if(object.getClass().equals(this.getClass())) {
-            ReverseComparator thatrc = (ReverseComparator)object;
+        }
+        if (object.getClass().equals(this.getClass())) {
+            ReverseComparator<?> thatrc = (ReverseComparator<?>) object;
             return comparator.equals(thatrc.comparator);
-        } else {
-            return false;
         }
+        return false;
     }
 
 }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/TransformingComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/TransformingComparator.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/TransformingComparator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/TransformingComparator.java Tue Sep 15 05:29:56 2009
@@ -18,6 +18,7 @@
 
 import java.util.Comparator;
 
+import org.apache.commons.collections.ComparatorUtils;
 import org.apache.commons.collections.Transformer;
 
 /**
@@ -31,12 +32,12 @@
  * @see org.apache.commons.collections.Transformer
  * @see org.apache.commons.collections.comparators.ComparableComparator
  */
-public class TransformingComparator implements Comparator {
+public class TransformingComparator<E> implements Comparator<E> {
     
     /** The decorated comparator. */
-    protected Comparator decorated;
+    protected Comparator<E> decorated;
     /** The transformer being used. */    
-    protected Transformer transformer;
+    protected Transformer<? super E, ? extends E> transformer;
 
     //-----------------------------------------------------------------------
     /**
@@ -45,8 +46,9 @@
      * 
      * @param transformer what will transform the arguments to <code>compare</code>
      */
-    public TransformingComparator(Transformer transformer) {
-        this(transformer, new ComparableComparator());
+    @SuppressWarnings("unchecked")
+    public TransformingComparator(Transformer<? super E, ? extends E> transformer) {
+        this(transformer, ComparatorUtils.NATURAL_COMPARATOR);
     }
 
     /**
@@ -55,7 +57,7 @@
      * @param transformer  what will transform the arguments to <code>compare</code>
      * @param decorated  the decorated Comparator
      */
-    public TransformingComparator(Transformer transformer, Comparator decorated) {
+    public TransformingComparator(Transformer<? super E, ? extends E> transformer, Comparator<E> decorated) {
         this.decorated = decorated;
         this.transformer = transformer;
     }
@@ -68,9 +70,9 @@
      * @param obj2  the second object to transform then compare
      * @return negative if obj1 is less, positive if greater, zero if equal
      */
-    public int compare(Object obj1, Object obj2) {
-        Object value1 = this.transformer.transform(obj1);
-        Object value2 = this.transformer.transform(obj2);
+    public int compare(E obj1, E obj2) {
+        E value1 = this.transformer.transform(obj1);
+        E value2 = this.transformer.transform(obj2);
         return this.decorated.compare(value1, value2);
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AndPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AndPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AndPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AndPredicate.java Tue Sep 15 05:29:56 2009
@@ -28,39 +28,39 @@
  *
  * @author Stephen Colebourne
  */
-public final class AndPredicate implements Predicate, PredicateDecorator, Serializable {
+public final class AndPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 4189014213763186912L;
-    
+
     /** The array of predicates to call */
-    private final Predicate iPredicate1;
+    private final Predicate<? super T> iPredicate1;
     /** The array of predicates to call */
-    private final Predicate iPredicate2;
-    
+    private final Predicate<? super T> iPredicate2;
+
     /**
      * Factory to create the predicate.
-     * 
+     *
      * @param predicate1  the first predicate to check, not null
      * @param predicate2  the second predicate to check, not null
      * @return the <code>and</code> predicate
      * @throws IllegalArgumentException if either predicate is null
      */
-    public static Predicate getInstance(Predicate predicate1, Predicate predicate2) {
+    public static <T> Predicate<T> getInstance(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
         if (predicate1 == null || predicate2 == null) {
             throw new IllegalArgumentException("Predicate must not be null");
         }
-        return new AndPredicate(predicate1, predicate2);
+        return new AndPredicate<T>(predicate1, predicate2);
     }
 
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param predicate1  the first predicate to check, not null
      * @param predicate2  the second predicate to check, not null
      */
-    public AndPredicate(Predicate predicate1, Predicate predicate2) {
+    public AndPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2) {
         super();
         iPredicate1 = predicate1;
         iPredicate2 = predicate2;
@@ -68,21 +68,22 @@
 
     /**
      * Evaluates the predicate returning true if both predicates return true.
-     * 
+     *
      * @param object  the input object
      * @return true if both decorated predicates return true
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
        return (iPredicate1.evaluate(object) && iPredicate2.evaluate(object));
     }
 
     /**
      * Gets the two predicates being decorated as an array.
-     * 
+     *
      * @return the predicates
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    @SuppressWarnings("unchecked")
+    public Predicate<? super T>[] getPredicates() {
         return new Predicate[] {iPredicate1, iPredicate2};
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AnyPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AnyPredicate.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AnyPredicate.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/AnyPredicate.java Tue Sep 15 05:29:56 2009
@@ -35,14 +35,14 @@
  * @author Stephen Colebourne
  * @author Matt Benson
  */
-public final class AnyPredicate implements Predicate, PredicateDecorator, Serializable {
+public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 7429999530934647542L;
-    
+
     /** The array of predicates to call */
-    private final Predicate[] iPredicates;
-    
+    private final Predicate<? super T>[] iPredicates;
+
     /**
      * Factory to create the predicate.
      * <p>
@@ -54,15 +54,16 @@
      * @throws IllegalArgumentException if the predicates array is null
      * @throws IllegalArgumentException if any predicate in the array is null
      */
-    public static Predicate getInstance(Predicate[] predicates) {
+    @SuppressWarnings("unchecked")
+    public static <T> Predicate<T> getInstance(Predicate<? super T>[] predicates) {
         FunctorUtils.validate(predicates);
         if (predicates.length == 0) {
-            return FalsePredicate.INSTANCE;
+            return FalsePredicate.<T>falsePredicate();
         }
         if (predicates.length == 1) {
-            return predicates[0];
+            return (Predicate<T>) predicates[0];
         }
-        return new AnyPredicate(FunctorUtils.copy(predicates));
+        return new AnyPredicate<T>(FunctorUtils.copy(predicates));
     }
 
     /**
@@ -76,35 +77,36 @@
      * @throws IllegalArgumentException if the predicates array is null
      * @throws IllegalArgumentException if any predicate in the array is null
      */
-    public static Predicate getInstance(Collection predicates) {
-        Predicate[] preds = FunctorUtils.validate(predicates);
+    @SuppressWarnings("unchecked")
+    public static <T> Predicate<T> getInstance(Collection<? extends Predicate<T>> predicates) {
+        Predicate<? super T>[] preds = FunctorUtils.validate(predicates);
         if (preds.length == 0) {
-            return FalsePredicate.INSTANCE;
+            return FalsePredicate.<T>falsePredicate();
         }
         if (preds.length == 1) {
-            return preds[0];
+            return (Predicate<T>) preds[0];
         }
-        return new AnyPredicate(preds);
+        return new AnyPredicate<T>(preds);
     }
 
     /**
      * Constructor that performs no validation.
      * Use <code>getInstance</code> if you want that.
-     * 
+     *
      * @param predicates  the predicates to check, not cloned, not null
      */
-    public AnyPredicate(Predicate[] predicates) {
+    public AnyPredicate(Predicate<? super T>[] predicates) {
         super();
         iPredicates = predicates;
     }
 
     /**
      * Evaluates the predicate returning true if any predicate returns true.
-     * 
+     *
      * @param object  the input object
      * @return true if any decorated predicate return true
      */
-    public boolean evaluate(Object object) {
+    public boolean evaluate(T object) {
         for (int i = 0; i < iPredicates.length; i++) {
             if (iPredicates[i].evaluate(object)) {
                 return true;
@@ -115,11 +117,11 @@
 
     /**
      * Gets the predicates, do not modify the array.
-     * 
+     *
      * @return the predicates
      * @since Commons Collections 3.1
      */
-    public Predicate[] getPredicates() {
+    public Predicate<? super T>[] getPredicates() {
         return iPredicates;
     }
 

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedClosure.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedClosure.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedClosure.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/functors/ChainedClosure.java Tue Sep 15 05:29:56 2009
@@ -18,7 +18,6 @@
 
 import java.io.Serializable;
 import java.util.Collection;
-import java.util.Iterator;
 
 import org.apache.commons.collections.Closure;
 
@@ -30,13 +29,13 @@
  *
  * @author Stephen Colebourne
  */
-public class ChainedClosure implements Closure, Serializable {
+public class ChainedClosure<E> implements Closure<E>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = -3520677225766901240L;
 
     /** The closures to call in turn */
-    private final Closure[] iClosures;
+    private final Closure<? super E>[] iClosures;
 
     /**
      * Factory method that performs validation and copies the parameter array.
@@ -46,15 +45,15 @@
      * @throws IllegalArgumentException if the closures array is null
      * @throws IllegalArgumentException if any closure in the array is null
      */
-    public static Closure getInstance(Closure[] closures) {
+    public static <E> Closure<E> getInstance(Closure<? super E>[] closures) {
         FunctorUtils.validate(closures);
         if (closures.length == 0) {
-            return NOPClosure.INSTANCE;
+            return NOPClosure.<E>getInstance();
         }
         closures = FunctorUtils.copy(closures);
-        return new ChainedClosure(closures);
+        return new ChainedClosure<E>(closures);
     }
-    
+
     /**
      * Create a new Closure that calls each closure in turn, passing the 
      * result into the next closure. The ordering is that of the iterator()
@@ -65,21 +64,22 @@
      * @throws IllegalArgumentException if the closures collection is null
      * @throws IllegalArgumentException if any closure in the collection is null
      */
-    public static Closure getInstance(Collection closures) {
+    @SuppressWarnings("unchecked")
+    public static <E> Closure<E> getInstance(Collection<Closure<E>> closures) {
         if (closures == null) {
             throw new IllegalArgumentException("Closure collection must not be null");
         }
         if (closures.size() == 0) {
-            return NOPClosure.INSTANCE;
+            return NOPClosure.<E>getInstance();
         }
         // convert to array like this to guarantee iterator() ordering
-        Closure[] cmds = new Closure[closures.size()];
+        Closure<? super E>[] cmds = new Closure[closures.size()];
         int i = 0;
-        for (Iterator it = closures.iterator(); it.hasNext();) {
-            cmds[i++] = (Closure) it.next();
+        for (Closure<? super E> closure : closures) {
+            cmds[i++] = (Closure<E>) closure;
         }
         FunctorUtils.validate(cmds);
-        return new ChainedClosure(cmds);
+        return new ChainedClosure<E>(cmds);
     }
 
     /**
@@ -90,12 +90,13 @@
      * @return the <code>chained</code> closure
      * @throws IllegalArgumentException if either closure is null
      */
-    public static Closure getInstance(Closure closure1, Closure closure2) {
+    @SuppressWarnings("unchecked")
+    public static <E> Closure<E> getInstance(Closure<? super E> closure1, Closure<? super E> closure2) {
         if (closure1 == null || closure2 == null) {
             throw new IllegalArgumentException("Closures must not be null");
         }
-        Closure[] closures = new Closure[] { closure1, closure2 };
-        return new ChainedClosure(closures);
+        Closure<E>[] closures = new Closure[] { closure1, closure2 };
+        return new ChainedClosure<E>(closures);
     }
 
     /**
@@ -104,7 +105,7 @@
      * 
      * @param closures  the closures to chain, not copied, no nulls
      */
-    public ChainedClosure(Closure[] closures) {
+    public ChainedClosure(Closure<? super E>[] closures) {
         super();
         iClosures = closures;
     }
@@ -114,7 +115,7 @@
      * 
      * @param input  the input object passed to each closure
      */
-    public void execute(Object input) {
+    public void execute(E input) {
         for (int i = 0; i < iClosures.length; i++) {
             iClosures[i].execute(input);
         }
@@ -125,7 +126,7 @@
      * @return the closures
      * @since Commons Collections 3.1
      */
-    public Closure[] getClosures() {
+    public Closure<? super E>[] getClosures() {
         return iClosures;
     }
 



Mime
View raw message