db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1451125 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: ColumnOrdering.java RowOrderingImpl.java
Date Thu, 28 Feb 2013 07:24:40 GMT
Author: kahatlen
Date: Thu Feb 28 07:24:39 2013
New Revision: 1451125

URL: http://svn.apache.org/r1451125
Log:
DERBY-6075: Use modern collections in impl/sql/compile

- Use ArrayList instead of Vector in ColumnOrdering and RowOrderingImpl

- Use ReuseFactory to allocate Integer instances for table number and
  column number

- Use library methods List.contains() and List.isEmpty()

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnOrdering.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowOrderingImpl.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnOrdering.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnOrdering.java?rev=1451125&r1=1451124&r2=1451125&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnOrdering.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnOrdering.java
Thu Feb 28 07:24:39 2013
@@ -21,12 +21,10 @@
 
 package org.apache.derby.impl.sql.compile;
 
+import java.util.ArrayList;
 import org.apache.derby.iapi.sql.compile.RowOrdering;
-import org.apache.derby.iapi.sql.compile.Optimizable;
-
 import org.apache.derby.iapi.services.sanity.SanityManager;
-
-import java.util.Vector;
+import org.apache.derby.iapi.util.ReuseFactory;
 
 class ColumnOrdering {
 
@@ -34,13 +32,13 @@ class ColumnOrdering {
 	int	myDirection;
 
 	/* A vector of column numbers (Integers) */
-	Vector columns = new Vector();
+    private final ArrayList columns = new ArrayList();
 
 	/*
 	** A vector of table numbers (Integers), corresponding to the column
 	** vector by position.
 	*/
-	Vector tables = new Vector();
+    private final ArrayList tables = new ArrayList();
 
 	/**
 	 * @param direction	See RowOrdering for possible values
@@ -112,8 +110,8 @@ class ColumnOrdering {
 	 */
 	void addColumn(int tableNumber, int columnNumber)
 	{
-		tables.add(new Integer(tableNumber));
-		columns.add(new Integer(columnNumber));
+        tables.add(ReuseFactory.getInteger(tableNumber));
+        columns.add(ReuseFactory.getInteger(columnNumber));
 	}
 
 	/**
@@ -141,7 +139,7 @@ class ColumnOrdering {
 	 */
 	boolean empty()
 	{
-		return (tables.size() == 0);
+		return tables.isEmpty();
 	}
 
 	/** Return a clone of this ColumnOrdering */
@@ -150,8 +148,8 @@ class ColumnOrdering {
 
 		for (int i = 0; i < columns.size(); i++) {
 			/* Integers are immutable, so just copy the pointers */
-			retval.columns.addElement(columns.get(i));
-			retval.tables.addElement(tables.get(i));
+			retval.columns.add(columns.get(i));
+			retval.tables.add(tables.get(i));
 		}
 
 		return retval;
@@ -159,23 +157,11 @@ class ColumnOrdering {
 
 	/** Is the given table number in this ColumnOrdering? */
 	boolean hasTable(int tableNumber) {
-		if (tables.size() == 0)
-			return false;
-
-		for (int i = 0; i < tables.size(); i++) {
-			Integer tab = (Integer) tables.get(i);
-			
-			if (tab.intValue() == tableNumber)
-				return true;
-		}
-
-		return false;
+        return tables.contains(ReuseFactory.getInteger(tableNumber));
 	}
 
 	/** Is there any table other than the given one in this ColumnOrdering? */
 	boolean hasAnyOtherTable(int tableNumber) {
-		if (tables.size() == 0)
-			return false;
 
 		for (int i = 0; i < tables.size(); i++) {
 			Integer tab = (Integer) tables.get(i);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowOrderingImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowOrderingImpl.java?rev=1451125&r1=1451124&r2=1451125&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowOrderingImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/RowOrderingImpl.java
Thu Feb 28 07:24:39 2013
@@ -21,6 +21,8 @@
 
 package org.apache.derby.impl.sql.compile;
 
+import java.util.ArrayList;
+
 import org.apache.derby.iapi.sql.compile.RowOrdering;
 import org.apache.derby.iapi.sql.compile.Optimizable;
 
@@ -28,12 +30,10 @@ import org.apache.derby.iapi.services.sa
 
 import org.apache.derby.iapi.error.StandardException;
 
-import java.util.Vector;
-
 class RowOrderingImpl implements RowOrdering {
 
 	/* This vector contains ColumnOrderings */
-	Vector ordering;
+	private final ArrayList ordering = new ArrayList();
 
 	/*
 	** This ColumnOrdering represents the columns that can be considered
@@ -49,18 +49,15 @@ class RowOrderingImpl implements RowOrde
 	** This vector contains table numbers for tables that are always ordered.
 	** This happens for one-row tables.
 	*/
-	Vector alwaysOrderedOptimizables;
+    private final ArrayList alwaysOrderedOptimizables = new ArrayList();
 
 	ColumnOrdering	currentColumnOrdering;
 
 	/* This vector contains unordered Optimizables */
-	Vector unorderedOptimizables;
+    private final ArrayList unorderedOptimizables = new ArrayList();
 
 	RowOrderingImpl() {
-		ordering = new Vector();
-		unorderedOptimizables = new Vector();
 		columnsAlwaysOrdered = new ColumnOrdering(RowOrdering.DONTCARE);
-		alwaysOrderedOptimizables = new Vector();
 	}
 	
 	/** @see RowOrdering#isColumnAlwaysOrdered */
@@ -161,7 +158,7 @@ class RowOrderingImpl implements RowOrde
 	 * Return true if the given vector of Optimizables contains an Optimizable
 	 * with the given table number.
 	 */
-	private boolean vectorContainsOptimizable(int tableNumber, Vector vec)
+	private boolean vectorContainsOptimizable(int tableNumber, ArrayList vec)
 	{
 		int i;
 
@@ -187,12 +184,13 @@ class RowOrderingImpl implements RowOrde
 								int tableNumber,
 								int columnNumber)
 	{
-		if (unorderedOptimizables.size() > 0)
+        if (!unorderedOptimizables.isEmpty()) {
 			return;
+        }
 
 		ColumnOrdering currentColumnOrdering;
 
-		if (ordering.size() == 0)
+		if (ordering.isEmpty())
 		{
 			currentColumnOrdering = new ColumnOrdering(direction);
 			ordering.add(currentColumnOrdering);
@@ -219,8 +217,9 @@ class RowOrderingImpl implements RowOrde
 	/** @see RowOrdering#nextOrderPosition */
 	public void nextOrderPosition(int direction)
 	{
-		if (unorderedOptimizables.size() > 0)
+        if (!unorderedOptimizables.isEmpty()) {
 			return;
+        }
 
 		currentColumnOrdering = new ColumnOrdering(direction);
 		ordering.add(currentColumnOrdering);
@@ -250,7 +249,7 @@ class RowOrderingImpl implements RowOrde
 		int tableNumber = (hasTableNumber ? optimizable.getTableNumber() : 0);
 		if (
 			(
-				(ordering.size() == 0) ||
+				(ordering.isEmpty()) ||
 				(
 					hasTableNumber &&
 					((ColumnOrdering) ordering.get(0)).hasTable(
@@ -321,7 +320,7 @@ class RowOrderingImpl implements RowOrde
 	 * Remove all optimizables with the given table number from the
 	 * given vector of optimizables.
 	 */
-	private void removeOptimizableFromVector(int tableNumber, Vector vec)
+	private void removeOptimizableFromVector(int tableNumber, ArrayList vec)
 	{
 		int i;
 



Mime
View raw message