db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1486780 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/store/access/DiskHashtable.java testing/org/apache/derbyTesting/functionTests/tests/store/TestDiskHashtable.java
Date Tue, 28 May 2013 07:03:47 GMT
Author: kahatlen
Date: Tue May 28 07:03:46 2013
New Revision: 1486780

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

Remove SuppressWarnings annotation in DiskHashtable and use strongly
typed variables instead of an overloaded Object variable to prevent
the warnings.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDiskHashtable.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java?rev=1486780&r1=1486779&r2=1486780&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java
Tue May 28 07:03:46 2013
@@ -20,10 +20,11 @@
  */
 package org.apache.derby.iapi.store.access;
 
+import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Properties;
-import java.util.Vector;
 import org.apache.derby.shared.common.reference.SQLState;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.types.DataValueDescriptor;
@@ -251,13 +252,13 @@ public class DiskHashtable 
         return getRemove(key, false, false);
     }
 
-    @SuppressWarnings("unchecked")
     private Object getRemove(Object key, boolean remove, boolean existenceOnly)
         throws StandardException
     {
         int hashCode = key.hashCode();
         int rowCount = 0;
-        Object retValue = null;
+        DataValueDescriptor[] firstRow = null;
+        List<DataValueDescriptor[]> allRows = null;
 
         scanKey[0].setValue( hashCode);
         ScanController scan = 
@@ -286,32 +287,29 @@ public class DiskHashtable 
                     if( existenceOnly)
                         return this;
 
+                    DataValueDescriptor[] clonedRow =
+                            BackingStoreHashtable.shallowCloneRow(row);
+
                     rowCount++;
                     if( rowCount == 1)
                     {
                         // if there is only one matching row just return row. 
-                        retValue = BackingStoreHashtable.shallowCloneRow( row);
+                        firstRow = clonedRow;
                     }
                     else 
                     {
-                        // if there is more than one row, return a vector of
+                        // If there is more than one row, return a list of
                         // the rows.
                         //
-                        Vector<Object> v;
-                        if( rowCount == 2)
+                        if (allRows == null)
                         {
                             // convert the "single" row retrieved from the
                             // first trip in the loop, to a vector with the
                             // first two rows.
-                            v = new Vector<Object>( 2);
-                            v.add( retValue);
-                            retValue = v;
-                        }
-                        else
-                        {
-                            v = (Vector<Object>) retValue;
+                            allRows = new ArrayList<DataValueDescriptor[]>(2);
+                            allRows.add(firstRow);
                         }
-                        v.add( BackingStoreHashtable.shallowCloneRow( row));
+                        allRows.add(clonedRow);
                     }
                     if( remove)
                     {
@@ -321,7 +319,7 @@ public class DiskHashtable 
                     }
                     if( remove_duplicates)
                         // This must be the only row with the key
-                        return retValue;
+                        return clonedRow;
                 }
             }
         }
@@ -329,7 +327,15 @@ public class DiskHashtable 
         {
             scan.close();
         }
-        return retValue;
+
+        if (allRows == null) {
+            // No duplicates. Return the single row, or null if no row was
+            // found for the given key.
+            return firstRow;
+        } else {
+            // Return list of all duplicate values.
+            return allRows;
+        }
     } // end of getRemove
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDiskHashtable.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDiskHashtable.java?rev=1486780&r1=1486779&r2=1486780&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDiskHashtable.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDiskHashtable.java
Tue May 28 07:03:46 2013
@@ -29,6 +29,7 @@ import java.sql.Statement;
 import java.util.BitSet;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Vector;
 
 import org.apache.derby.iapi.error.PublicAPI;
@@ -334,9 +335,9 @@ public class TestDiskHashtable 
             }
             if( el instanceof DataValueDescriptor[])
                 checkElement( (DataValueDescriptor[]) el, rowCount, rows, found);
-            else if( el instanceof Vector)
+            else if (el instanceof List)
             {
-                Vector v = (Vector) el;
+                List v = (List) el;
                 for( int i = 0; i < v.size(); i++)
                     checkElement( (DataValueDescriptor[]) v.get(i), rowCount, rows, found);
             }
@@ -397,12 +398,12 @@ public class TestDiskHashtable 
             DataValueDescriptor[] row1 = (DataValueDescriptor[]) r1;
             DataValueDescriptor[] row2;
             
-            if( r2 instanceof Vector)
+            if (r2 instanceof List)
             {
-                Vector v2 = (Vector) r2;
+                List v2 = (List) r2;
                 if( v2.size() != 1)
                     return false;
-                row2 = (DataValueDescriptor[]) v2.elementAt(0);
+                row2 = (DataValueDescriptor[]) v2.get(0);
             }
             else if( r2 instanceof DataValueDescriptor[])
                 row2 = (DataValueDescriptor[]) r2;
@@ -418,17 +419,17 @@ public class TestDiskHashtable 
             }
             return true;
         }
-        if( r1 instanceof Vector)
+        if (r1 instanceof List)
         {
-            if( !(r2 instanceof Vector))
+            if (!(r2 instanceof List))
                 return false;
-            Vector v1 = (Vector) r1;
-            Vector v2 = (Vector) r2;
+            List v1 = (List) r1;
+            List v2 = (List) r2;
             if( v1.size() != v2.size())
                 return false;
             for( int i = v1.size() - 1; i >= 0; i--)
             {
-                if( ! rowsEqual( v1.elementAt( i), v2.elementAt(i)))
+                if (!rowsEqual(v1.get(i), v2.get(i)))
                     return false;
             }
             return true;



Mime
View raw message