db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1486782 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/BackingStoreHashtable.java
Date Tue, 28 May 2013 07:09:56 GMT
Author: kahatlen
Date: Tue May 28 07:09:56 2013
New Revision: 1486782

URL: http://svn.apache.org/r1486782
Log:
DERBY-5840: Clean up compiler warnings introduced by using Java 5 language features

Remove the @SuppressWarnings("unchecked") annotation from
BackingStoreHashtable and introduce a specialized sub-class of
ArrayList to make the casts type safe.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/BackingStoreHashtable.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/BackingStoreHashtable.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/BackingStoreHashtable.java?rev=1486782&r1=1486781&r2=1486782&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/BackingStoreHashtable.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/BackingStoreHashtable.java
Tue May 28 07:09:56 2013
@@ -394,7 +394,6 @@ public class BackingStoreHashtable
      *
 	 * @exception  StandardException  Standard exception policy.
      **/
-    @SuppressWarnings("unchecked")
     private void add_row_to_hash_table(DataValueDescriptor[] row, boolean needsToClone)
 		throws StandardException
     {
@@ -405,30 +404,31 @@ public class BackingStoreHashtable
         {
             row = cloneRow(row);
         }
+
         Object key = KeyHasher.buildHashKey(row, key_column_numbers);
-        Object  duplicate_value = null;
+        Object duplicate_value = hash_table.put(key, row);
 
-        if ((duplicate_value = hash_table.put(key, row)) == null)
+        if (duplicate_value == null)
             doSpaceAccounting( row, false);
         else
         {
             if (!remove_duplicates)
             {
-                List<Object> row_vec;
+                RowList row_vec;
 
                 // inserted a duplicate
-                if (duplicate_value instanceof List)
+                if (duplicate_value instanceof RowList)
                 {
                     doSpaceAccounting( row, false);
-                    row_vec = (List<Object>) duplicate_value;
+                    row_vec = (RowList) duplicate_value;
                 }
                 else
                 {
                     // allocate list to hold duplicates
-                    row_vec = new ArrayList<Object>(2);
+                    row_vec = new RowList(2);
 
                     // insert original row into vector
-                    row_vec.add(duplicate_value);
+                    row_vec.add((DataValueDescriptor[]) duplicate_value);
                     doSpaceAccounting( row, true);
                 }
 
@@ -441,8 +441,6 @@ public class BackingStoreHashtable
                 hash_table.put(key, row_vec);
             }
         }
-
-        row = null;
     }
 
     private void doSpaceAccounting(DataValueDescriptor[] row,
@@ -792,4 +790,26 @@ public class BackingStoreHashtable
             return diskEnumeration.nextElement();
         }
     } // end of class BackingStoreHashtableEnumeration
+
+    /**
+     * List of {@code DataValueDescriptor[]} instances that represent rows.
+     * This class is used when the hash table contains multiple rows for the
+     * same hash key.
+     */
+    private static class RowList extends ArrayList<DataValueDescriptor[]> {
+
+        private RowList(int initialCapacity) {
+            super(initialCapacity);
+        }
+
+        // The class is mostly empty and provides no functionality in addition
+        // to what's provided by ArrayList<DataValueDescriptor[]>. The main
+        // purpose of the class is to allow type-safe casts from Object. These
+        // casts are needed because the hash table can store both DVD[] and
+        // List<DVD[]>, so its declared type is HashMap<Object, Object>.
+        // Because of type erasure, casts to ArrayList<DataValueDescriptor[]>
+        // will make the compiler generate unchecked conversion warnings.
+        // Casts to RowList, on the other hand, won't cause warnings, as there
+        // are no parameterized types and type erasure doesn't come into play.
+    }
 }



Mime
View raw message