commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r825147 - in /commons/proper/collections/trunk/src/test/org/apache/commons/collections: bidimap/AbstractTestSortedBidiMap.java bidimap/TestDualTreeBidiMap2.java map/AbstractTestMap.java
Date Wed, 14 Oct 2009 14:16:22 GMT
Author: mbenson
Date: Wed Oct 14 14:16:22 2009
New Revision: 825147

URL: http://svn.apache.org/viewvc?rev=825147&view=rev
Log:
refactor; avoid more generic array classcastexceptions

Modified:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java?rev=825147&r1=825146&r2=825147&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java
Wed Oct 14 14:16:22 2009
@@ -42,17 +42,13 @@
  */
 public abstract class AbstractTestSortedBidiMap<K extends Comparable<K>, V extends
Comparable<V>> extends AbstractTestOrderedBidiMap<K, V> {
 
-    protected List<K> sortedKeys = new ArrayList<K>();
+    protected List<K> sortedKeys;
     protected List<V> sortedValues = new ArrayList<V>();
     protected SortedSet<V> sortedNewValues = new TreeSet<V>();
 
-    @SuppressWarnings("unchecked")
     public AbstractTestSortedBidiMap(String testName) {
         super(testName);
-        Object[] sampleKeys = getSampleKeys();
-        for (Object key : sampleKeys) {
-            sortedKeys.add((K) key);
-        }
+        sortedKeys = getAsList(getSampleKeys());
         Collections.sort(sortedKeys);
         sortedKeys = Collections.unmodifiableList(sortedKeys);
 
@@ -62,10 +58,7 @@
         sortedValues.addAll(map.values());
         sortedValues = Collections.unmodifiableList(sortedValues);
 
-        Object[] newSampleValues = getNewSampleValues();
-        for (Object value : newSampleValues) {
-            sortedNewValues.add((V) value);
-        }
+        sortedNewValues.addAll(this.<V> getAsList(getNewSampleValues()));
     }
 
 //    public AbstractTestSortedBidiMap() {

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=825147&r1=825146&r2=825147&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
Wed Oct 14 14:16:22 2009
@@ -49,7 +49,7 @@
     public static void main(String[] args) {
         TestRunner.run(suite());
     }
-    
+
     public static Test suite() {
         return BulkTest.makeSuite(TestDualTreeBidiMap2.class);
     }
@@ -87,7 +87,7 @@
             ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
             Object dest = in.readObject();
             in.close();
-            
+
             SortedBidiMap bidi = (SortedBidiMap) dest;
             assertNotNull(obj.comparator());
             assertNotNull(bidi.comparator());
@@ -99,7 +99,7 @@
         SortedBidiMap<K, V> sm = makeFullMap();
 
         // Sort by the comparator used in the makeEmptyBidiMap() method
-        List<K> newSortedKeys = Arrays.asList(getSampleKeys());
+        List<K> newSortedKeys = getAsList(getSampleKeys());
         Collections.sort(newSortedKeys, new ReverseComparator<K>(ComparableComparator.<K>getInstance()));
         newSortedKeys = Collections.unmodifiableList(newSortedKeys);
 
@@ -124,7 +124,7 @@
     public String[] ignoredTests() {
         return new String[] {"TestDualTreeBidiMap2.bulkTestInverseMap.bulkTestInverseMap"};
     }
-    
+
 //    public void testCreate() throws Exception {
 //        resetEmpty();
 //        writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/DualTreeBidiMap.emptyCollection.version3.Test2.obj");

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java?rev=825147&r1=825146&r2=825147&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/AbstractTestMap.java
Wed Oct 14 14:16:22 2009
@@ -315,11 +315,20 @@
         return (V[]) getOtherNonNullStringElements();
     }
 
+    @SuppressWarnings("unchecked")
+    protected <E> List<E> getAsList(Object[] o) {
+        ArrayList<E> result = new ArrayList<E>();
+        for (Object element : o) {
+            result.add((E) element);
+        }
+        return result;
+    }
+
     /**
      * Returns a list of string elements suitable for return by
      * {@link #getOtherKeys()} or {@link #getOtherValues}.
      *
-     * <p>Override getOtherElements to returnthe results of this method if your
+     * <p>Override getOtherElements to return the results of this method if your
      * collection does not support heterogenous elements or the null element.
      * </p>
      */
@@ -1100,7 +1109,7 @@
         Map.Entry<K, V> test = cloneMapEntry(entry);
         assertEquals(true, entrySet.contains(test));
     }
-    
+
     @SuppressWarnings("unchecked")
     public void testEntrySetContains3() {
         resetFull();
@@ -1307,7 +1316,7 @@
         public boolean isGetStructuralModify() {
             return AbstractTestMap.this.isGetStructuralModify();
         }
-        
+
         public boolean isTestSerialization() {
             return false;
         }
@@ -1464,11 +1473,11 @@
         public boolean isAddSupported() {
             return false;
         }
-        
+
         public boolean isRemoveSupported() {
             return AbstractTestMap.this.isRemoveSupported();
         }
-        
+
         public boolean isTestSerialization() {
             return false;
         }
@@ -1536,7 +1545,7 @@
         public boolean isRemoveSupported() {
             return AbstractTestMap.this.isRemoveSupported();
         }
-        
+
         public boolean isTestSerialization() {
             return false;
         }



Mime
View raw message