commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r471173 - in /jakarta/commons/proper/collections/branches/collections_jdk5_branch: ./ src/java/org/apache/commons/collections/buffer/ src/java/org/apache/commons/collections/collection/ src/java/org/apache/commons/collections/list/ src/java...
Date Sat, 04 Nov 2006 12:07:40 GMT
Author: scolebourne
Date: Sat Nov  4 04:07:39 2006
New Revision: 471173

URL: http://svn.apache.org/viewvc?view=rev&rev=471173
Log:
Abstract*Decorator - Generify and use covariant return types

Modified:
    jakarta/commons/proper/collections/branches/collections_jdk5_branch/RELEASE-NOTES.txt
    jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
    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/list/AbstractListDecorator.java
    jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSetDecorator.java
    jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSortedSetDecorator.java

Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/RELEASE-NOTES.txt?view=diff&rev=471173&r1=471172&r2=471173
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/RELEASE-NOTES.txt
(original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/RELEASE-NOTES.txt
Sat Nov  4 04:07:39 2006
@@ -38,6 +38,10 @@
 - Removed Typed* containers such as TypedList and TypedMap
   - use generics for type safety, or Collections.checked*()
 
+- Switch Abstract*Decorator classes to expose decorated() protected method
+  instead of the decorated collection directly. Each class overrides decorated()
+  to add its type covariantly, thus getList()/getSet() etc. methods are removed
+
 
 Feedback
 --------

Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java?view=diff&rev=471173&r1=471172&r2=471173
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
(original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/AbstractBufferDecorator.java
Sat Nov  4 04:07:39 2006
@@ -53,18 +53,28 @@
      * Gets the buffer being decorated.
      * 
      * @return the decorated buffer
+     * @deprecated use decorated()
      */
     protected Buffer getBuffer() {
-        return (Buffer) getCollection();
+        return decorated();
+    }
+
+    /**
+     * Gets the buffer being decorated.
+     * 
+     * @return the decorated buffer
+     */
+    protected Buffer decorated() {
+        return (Buffer) super.decorated();
     }
 
     //-----------------------------------------------------------------------
     public Object get() {
-        return getBuffer().get();
+        return decorated().get();
     }
 
     public Object remove() {
-        return getBuffer().remove();
+        return decorated().remove();
     }
 
 }

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=471173&r1=471172&r2=471173
==============================================================================
--- 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
Sat Nov  4 04:07:39 2006
@@ -34,16 +34,17 @@
  * wrapped collection. This may be undesirable, for example if you are trying
  * to write an unmodifiable implementation it might provide a loophole.
  *
+ * @param <E> the type of the elements in the collection
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  * 
  * @author Stephen Colebourne
  * @author Paul Jack
  */
-public abstract class AbstractCollectionDecorator implements Collection {
+public abstract class AbstractCollectionDecorator<E> implements Collection<E>
{
 
     /** The collection being decorated */
-    protected Collection collection;
+    protected Collection<E> collection;
 
     /**
      * Constructor only used in deserialization, do not use otherwise.
@@ -59,7 +60,7 @@
      * @param coll  the collection to decorate, must not be null
      * @throws IllegalArgumentException if the collection is null
      */
-    protected AbstractCollectionDecorator(Collection coll) {
+    protected AbstractCollectionDecorator(Collection<E> coll) {
         if (coll == null) {
             throw new IllegalArgumentException("Collection must not be null");
         }
@@ -70,77 +71,88 @@
      * Gets the collection being decorated.
      * 
      * @return the decorated collection
+     * @deprecated use decorated()
      */
-    protected Collection getCollection() {
+    protected Collection<E> getCollection() {
+        return decorated();
+    }
+
+    /**
+     * Gets the collection being decorated.
+     * All access to the decorated collection goes via this method.
+     * 
+     * @return the decorated collection
+     */
+    protected Collection<E> decorated() {
         return collection;
     }
 
     //-----------------------------------------------------------------------
-    public boolean add(Object object) {
-        return collection.add(object);
+    public boolean add(E object) {
+        return decorated().add(object);
     }
 
-    public boolean addAll(Collection coll) {
-        return collection.addAll(coll);
+    public boolean addAll(Collection<? extends E> coll) {
+        return decorated().addAll(coll);
     }
 
     public void clear() {
-        collection.clear();
+        decorated().clear();
     }
 
     public boolean contains(Object object) {
-        return collection.contains(object);
+        return decorated().contains(object);
     }
 
     public boolean isEmpty() {
-        return collection.isEmpty();
+        return decorated().isEmpty();
     }
 
-    public Iterator iterator() {
-        return collection.iterator();
+    public Iterator<E> iterator() {
+        return decorated().iterator();
     }
 
     public boolean remove(Object object) {
-        return collection.remove(object);
+        return decorated().remove(object);
     }
 
     public int size() {
-        return collection.size();
+        return decorated().size();
     }
 
     public Object[] toArray() {
-        return collection.toArray();
+        return decorated().toArray();
     }
 
-    public Object[] toArray(Object[] object) {
-        return collection.toArray(object);
+    public <T> T[] toArray(T[] object) {
+        return decorated().toArray(object);
     }
 
-    public boolean containsAll(Collection coll) {
-        return collection.containsAll(coll);
+    public boolean containsAll(Collection<?> coll) {
+        return decorated().containsAll(coll);
     }
 
-    public boolean removeAll(Collection coll) {
-        return collection.removeAll(coll);
+    public boolean removeAll(Collection<?> coll) {
+        return decorated().removeAll(coll);
     }
 
-    public boolean retainAll(Collection coll) {
-        return collection.retainAll(coll);
+    public boolean retainAll(Collection<?> coll) {
+        return decorated().retainAll(coll);
     }
 
     public boolean equals(Object object) {
         if (object == this) {
             return true;
         }
-        return collection.equals(object);
+        return decorated().equals(object);
     }
 
     public int hashCode() {
-        return collection.hashCode();
+        return decorated().hashCode();
     }
 
     public String toString() {
-        return collection.toString();
+        return decorated().toString();
     }
 
 }

Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/AbstractListDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/AbstractListDecorator.java?view=diff&rev=471173&r1=471172&r2=471173
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/AbstractListDecorator.java
(original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/AbstractListDecorator.java
Sat Nov  4 04:07:39 2006
@@ -27,12 +27,15 @@
  * <p>
  * Methods are forwarded directly to the decorated list.
  *
+ * @param <E> the type of the elements in the list
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  * 
  * @author Stephen Colebourne
  */
-public abstract class AbstractListDecorator extends AbstractCollectionDecorator implements
List {
+public abstract class AbstractListDecorator<E>
+        extends AbstractCollectionDecorator<E>
+        implements List<E> {
 
     /**
      * Constructor only used in deserialization, do not use otherwise.
@@ -48,7 +51,7 @@
      * @param list  the list to decorate, must not be null
      * @throws IllegalArgumentException if list is null
      */
-    protected AbstractListDecorator(List list) {
+    protected AbstractListDecorator(List<E> list) {
         super(list);
     }
 
@@ -56,50 +59,60 @@
      * Gets the list being decorated.
      * 
      * @return the decorated list
+     * @deprecated use decorated()
      */
-    protected List getList() {
-        return (List) getCollection();
+    protected List<E> getList() {
+        return decorated();
+    }
+
+    /**
+     * Gets the list being decorated.
+     * 
+     * @return the decorated list
+     */
+    protected List<E> decorated() {
+        return (List<E>) super.decorated();
     }
 
     //-----------------------------------------------------------------------
-    public void add(int index, Object object) {
-        getList().add(index, object);
+    public void add(int index, E object) {
+        decorated().add(index, object);
     }
 
-    public boolean addAll(int index, Collection coll) {
-        return getList().addAll(index, coll);
+    public boolean addAll(int index, Collection<? extends E> coll) {
+        return decorated().addAll(index, coll);
     }
 
-    public Object get(int index) {
-        return getList().get(index);
+    public E get(int index) {
+        return decorated().get(index);
     }
 
     public int indexOf(Object object) {
-        return getList().indexOf(object);
+        return decorated().indexOf(object);
     }
 
     public int lastIndexOf(Object object) {
-        return getList().lastIndexOf(object);
+        return decorated().lastIndexOf(object);
     }
 
-    public ListIterator listIterator() {
-        return getList().listIterator();
+    public ListIterator<E> listIterator() {
+        return decorated().listIterator();
     }
 
-    public ListIterator listIterator(int index) {
-        return getList().listIterator(index);
+    public ListIterator<E> listIterator(int index) {
+        return decorated().listIterator(index);
     }
 
-    public Object remove(int index) {
-        return getList().remove(index);
+    public E remove(int index) {
+        return decorated().remove(index);
     }
 
-    public Object set(int index, Object object) {
-        return getList().set(index, object);
+    public E set(int index, E object) {
+        return decorated().set(index, object);
     }
 
-    public List subList(int fromIndex, int toIndex) {
-        return getList().subList(fromIndex, toIndex);
+    public List<E> subList(int fromIndex, int toIndex) {
+        return decorated().subList(fromIndex, toIndex);
     }
 
 }

Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSetDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSetDecorator.java?view=diff&rev=471173&r1=471172&r2=471173
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSetDecorator.java
(original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSetDecorator.java
Sat Nov  4 04:07:39 2006
@@ -25,12 +25,15 @@
  * <p>
  * Methods are forwarded directly to the decorated set.
  *
+ * @param <E> the type of the elements in the set
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  * 
  * @author Stephen Colebourne
  */
-public abstract class AbstractSetDecorator extends AbstractCollectionDecorator implements
Set {
+public abstract class AbstractSetDecorator<E>
+        extends AbstractCollectionDecorator<E>
+        implements Set<E> {
 
     /**
      * Constructor only used in deserialization, do not use otherwise.
@@ -46,7 +49,7 @@
      * @param set  the set to decorate, must not be null
      * @throws IllegalArgumentException if set is null
      */
-    protected AbstractSetDecorator(Set set) {
+    protected AbstractSetDecorator(Set<E> set) {
         super(set);
     }
 
@@ -54,9 +57,19 @@
      * Gets the set being decorated.
      * 
      * @return the decorated set
+     * @deprecated use decorated()
      */
-    protected Set getSet() {
-        return (Set) getCollection();
+    protected Set<E> getSet() {
+        return decorated();
+    }
+
+    /**
+     * Gets the set being decorated.
+     * 
+     * @return the decorated set
+     */
+    protected Set<E> decorated() {
+        return (Set<E>) super.decorated();
     }
 
 }

Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSortedSetDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSortedSetDecorator.java?view=diff&rev=471173&r1=471172&r2=471173
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSortedSetDecorator.java
(original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/AbstractSortedSetDecorator.java
Sat Nov  4 04:07:39 2006
@@ -25,12 +25,15 @@
  * <p>
  * Methods are forwarded directly to the decorated set.
  *
+ * @param <E> the type of the elements in the sorted set
  * @since Commons Collections 3.0
  * @version $Revision$ $Date$
  * 
  * @author Stephen Colebourne
  */
-public abstract class AbstractSortedSetDecorator extends AbstractSetDecorator implements
SortedSet {
+public abstract class AbstractSortedSetDecorator<E>
+        extends AbstractSetDecorator<E>
+        implements SortedSet<E> {
 
     /**
      * Constructor only used in deserialization, do not use otherwise.
@@ -46,7 +49,7 @@
      * @param set  the set to decorate, must not be null
      * @throws IllegalArgumentException if set is null
      */
-    protected AbstractSortedSetDecorator(Set set) {
+    protected AbstractSortedSetDecorator(Set<E> set) {
         super(set);
     }
 
@@ -54,34 +57,44 @@
      * Gets the sorted set being decorated.
      * 
      * @return the decorated set
+     * @deprecated use decorated()
      */
-    protected SortedSet getSortedSet() {
-        return (SortedSet) getCollection();
+    protected SortedSet<E> getSortedSet() {
+        return decorated();
     }
-    
+
+    /**
+     * Gets the set being decorated.
+     * 
+     * @return the decorated set
+     */
+    protected SortedSet<E> decorated() {
+        return (SortedSet<E>) super.decorated();
+    }
+
     //-----------------------------------------------------------------------
-    public SortedSet subSet(Object fromElement, Object toElement) {
-        return getSortedSet().subSet(fromElement, toElement);
+    public SortedSet<E> subSet(E fromElement, E toElement) {
+        return decorated().subSet(fromElement, toElement);
     }
 
-    public SortedSet headSet(Object toElement) {
-        return getSortedSet().headSet(toElement);
+    public SortedSet<E> headSet(E toElement) {
+        return decorated().headSet(toElement);
     }
 
-    public SortedSet tailSet(Object fromElement) {
-        return getSortedSet().tailSet(fromElement);
+    public SortedSet<E> tailSet(E fromElement) {
+        return decorated().tailSet(fromElement);
     }
 
-    public Object first() {
-        return getSortedSet().first();
+    public E first() {
+        return decorated().first();
     }
 
-    public Object last() {
-        return getSortedSet().last();
+    public E last() {
+        return decorated().last();
     }
 
-    public Comparator comparator() {
-        return getSortedSet().comparator();
+    public Comparator<? super E> comparator() {
+        return decorated().comparator();
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message