commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1023949 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java
Date Mon, 18 Oct 2010 18:54:29 GMT
Author: sebb
Date: Mon Oct 18 18:54:29 2010
New Revision: 1023949

URL: http://svn.apache.org/viewvc?rev=1023949&view=rev
Log:
COLLECTIONS-364 DualTreeBidiMap.readObject() uses wrong comparator to create reverseMap

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java?rev=1023949&r1=1023948&r2=1023949&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/bidimap/DualTreeBidiMap.java
Mon Oct 18 18:54:29 2010
@@ -387,7 +387,7 @@ public class DualTreeBidiMap<K, V> exten
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
         in.defaultReadObject();
         normalMap = new TreeMap(comparator);
-        reverseMap = new TreeMap(comparator);
+        reverseMap = new TreeMap(valueComparator);
         Map map = (Map) in.readObject();
         putAll(map);
     }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java?rev=1023949&r1=1023948&r2=1023949&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java
Mon Oct 18 18:54:29 2010
@@ -22,6 +22,7 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.TreeMap;
@@ -41,6 +42,7 @@ import org.apache.commons.collections.co
  * @author Stephen Colebourne
  * @author Jonas Van Poucke
  */
+@SuppressWarnings("boxing")
 public class TestDualTreeBidiMap2<K extends Comparable<K>, V extends Comparable<V>>
extends AbstractTestSortedBidiMap<K, V> {
 
     public static Test suite() {
@@ -70,6 +72,16 @@ public class TestDualTreeBidiMap2<K exte
         assertTrue(bidi.comparator() instanceof ReverseComparator);
     }
 
+    public void testComparator2() {
+        DualTreeBidiMap<String, Integer> dtbm = new DualTreeBidiMap<String, Integer>(
+                String.CASE_INSENSITIVE_ORDER, null);
+        dtbm.put("two", 0);
+        dtbm.put("one", 1);
+        assertEquals("one", dtbm.firstKey());
+        assertEquals("two", dtbm.lastKey());
+        
+    }
+
     public void testSerializeDeserializeCheckComparator() throws Exception {
         SortedBidiMap<?, ?> obj = makeObject();
         if (obj instanceof Serializable && isTestSerialization()) {
@@ -82,13 +94,39 @@ public class TestDualTreeBidiMap2<K exte
             Object dest = in.readObject();
             in.close();
 
-            SortedBidiMap bidi = (SortedBidiMap) dest;
+            SortedBidiMap<?,?> bidi = (SortedBidiMap<?,?>) dest;
             assertNotNull(obj.comparator());
             assertNotNull(bidi.comparator());
             assertTrue(bidi.comparator() instanceof ReverseComparator);
         }
     }
 
+    private static class IntegerComparator implements Comparator<Integer>, java.io.Serializable{
+        private static final long serialVersionUID = 1L;
+        public int compare(Integer o1, Integer o2) {
+            return o1.compareTo(o2);
+        }
+    }
+
+    public void testCollections364() throws Exception {
+        DualTreeBidiMap<String, Integer> original = new DualTreeBidiMap<String,
Integer>(
+                String.CASE_INSENSITIVE_ORDER, new IntegerComparator());
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream(buffer);
+        out.writeObject(original);
+        out.close();
+
+        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
+        @SuppressWarnings("unchecked")
+        DualTreeBidiMap<String, Integer> deserialised = (DualTreeBidiMap<String,
Integer>) in.readObject();
+        in.close();
+
+        assertNotNull(original.comparator());
+        assertNotNull(deserialised.comparator());
+        assertEquals(original.comparator().getClass(), deserialised.comparator().getClass());
+        assertEquals(original.valueComparator().getClass(), deserialised.valueComparator().getClass());
+    }
+
     public void testSortOrder() throws Exception {
         SortedBidiMap<K, V> sm = makeFullMap();
 



Mime
View raw message