On Tue, 2008-03-25 at 20:50 +0100, Mario Torre wrote:
> This patch is the first of a series that I'm preparing about
> CopyOnWriteArrayList, my goal is to pass the public domain JCK on this
> class.
> 
> 2008-03-25  Mario Torre  <[EMAIL PROTECTED]>
> 
>       * java/util/concurrent/CopyOnWriteArrayList.java (clone): clone
>         method in CopyOnWriteArrayList should just do a shallow copy.
>         Fixed.
>       (equals): new method, override from base class.
>       (toString): likewise.
> 

:) Good start for fixing stuff

Here is the patch :)

Mario
-- 
Mario Torre, Software Developer, http://www.jroller.com/neugens/
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com   * Tel: +49-721-663 968-53
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA  FC7C 4086 63E3 80F2 40CF

USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim
Geschäftsführer: Dr. James J. Hunt

Please, support open standards:
http://opendocumentfellowship.org/petition/
http://www.nosoftwarepatents.com/
### Eclipse Workspace Patch 1.0
#P classpath
Index: java/util/concurrent/CopyOnWriteArrayList.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/concurrent/CopyOnWriteArrayList.java,v
retrieving revision 1.6
diff -u -r1.6 CopyOnWriteArrayList.java
--- java/util/concurrent/CopyOnWriteArrayList.java	12 Mar 2008 23:39:51 -0000	1.6
+++ java/util/concurrent/CopyOnWriteArrayList.java	25 Mar 2008 19:44:21 -0000
@@ -45,6 +45,7 @@
 import java.lang.reflect.Array;
 
 import java.util.AbstractList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.ConcurrentModificationException;
 import java.util.Iterator;
@@ -52,6 +53,7 @@
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
 import java.util.RandomAccess;
+import java.util.concurrent.ConcurrentSkipListMap.Iter;
 
 /**
  * A thread-safe implementation of an ArrayList. A CopyOnWriteArrayList is
@@ -286,7 +288,6 @@
     try
       {
         clone = (CopyOnWriteArrayList<E>) super.clone();
-        clone.data = (E[]) data.clone();
       }
     catch (CloneNotSupportedException e)
       {
@@ -691,6 +692,43 @@
     return size;
   }
 
+  public String toString()
+  {
+    return Arrays.toString(this.data);
+  }
+
+  public boolean equals(Object o)
+  {
+    if (o == null)
+      return false;
+    
+    if (this == o)
+      return true;
+    
+    boolean _equals = false;
+    
+    // let's see if 'o' is a list, if so, we need to compare the elements
+    // as returned by the iterator
+    if (o instanceof List)
+      {
+        List<?> source = (List<?>) o;
+        
+        if (source.size() != this.size())
+          return false;
+        
+        Iterator<?> sourceIterator = source.iterator();
+        for (E element : this)
+          {
+            if (!element.equals(sourceIterator.next()))
+              return false;
+          }
+
+        _equals = true;
+      }
+     
+    return _equals;
+  }
+  
   /**
    * Return an Iterator containing the elements of this list.
    * The Iterator uses a snapshot of the state of the internal storage
@@ -1056,7 +1094,7 @@
       size--;
       return o;
     }
-        
+    
     /**
      * Specified by AbstractList.subList to delegate to the backing list.
      *

Reply via email to