[teiid-commits] teiid SVN: r1654 - in trunk/engine/src: test/java/com/metamatrix/query/sql/proc and 1 other directory.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Fri Dec 11 17:49:47 EST 2009
Author: shawkins
Date: 2009-12-11 17:49:47 -0500 (Fri, 11 Dec 2009)
New Revision: 1654
Modified:
trunk/engine/src/main/java/com/metamatrix/query/sql/proc/Block.java
trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestBlock.java
Log:
TEIID-905 fix for block clone
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/proc/Block.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/proc/Block.java 2009-12-11 22:46:42 UTC (rev 1653)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/proc/Block.java 2009-12-11 22:49:47 UTC (rev 1654)
@@ -22,26 +22,28 @@
package com.metamatrix.query.sql.proc;
-import java.util.*;
-import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+
import com.metamatrix.core.util.EquivalenceUtil;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
/**
* <p> This class represents a group of <code>Statement</code> objects. The
* statements are stored on this object in the order in which they are added.</p>
*/
-public class Block implements LanguageObject {
+public class Block implements LanguageObject {
// list of statements on this block
- private List statements;
+ private List<Statement> statements;
/**
* Constructor for Block.
*/
public Block() {
- statements = new ArrayList();
+ statements = new ArrayList<Statement>();
}
/**
@@ -57,7 +59,7 @@
* Get all the statements contained on this block.
* @return A list of <code>Statement</code>s contained in this block
*/
- public List getStatements() {
+ public List<Statement> getStatements() {
return statements;
}
@@ -65,7 +67,7 @@
* Set the statements contained on this block.
* @param statements A list of <code>Statement</code>s contained in this block
*/
- public void setStatements(List statements) {
+ public void setStatements(List<Statement> statements) {
this.statements = statements;
}
@@ -91,11 +93,8 @@
*/
public Object clone() {
Block copy = new Block();
- if(!statements.isEmpty()) {
- Iterator stmtIter = statements.iterator();
- while(stmtIter.hasNext()) {
- copy.addStatement((Statement) stmtIter.next());
- }
+ for (Statement statement : statements) {
+ copy.addStatement((Statement)statement.clone());
}
return copy;
}
@@ -129,18 +128,7 @@
* @return Hash code
*/
public int hashCode() {
- // For speed, this hash code relies only on the hash codes of its select
- // and criteria clauses, not on the from, order by, or option clauses
- int myHash = 0;
-
- myHash = HashCodeUtil.hashCode(myHash, this.getStatements());
- if(!this.getStatements().isEmpty()) {
- Iterator stmtIter = this.getStatements().iterator();
- while(stmtIter.hasNext()) {
- myHash = HashCodeUtil.hashCode(myHash, stmtIter.next());
- }
- }
- return myHash;
+ return statements.hashCode();
}
/**
Modified: trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestBlock.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestBlock.java 2009-12-11 22:46:42 UTC (rev 1653)
+++ trunk/engine/src/test/java/com/metamatrix/query/sql/proc/TestBlock.java 2009-12-11 22:49:47 UTC (rev 1654)
@@ -60,13 +60,13 @@
public void testGetStatements1() {
Block b1 = sample1();
- List stmts = b1.getStatements();
+ List<Statement> stmts = b1.getStatements();
assertTrue("Incorrect number of statements in the Block", (stmts.size() == 4)); //$NON-NLS-1$
}
public void testGetStatements2() {
Block b1 = sample1();
- Statement stmt = (Statement) b1.getStatements().get(1);
+ Statement stmt = b1.getStatements().get(1);
assertTrue("Incorrect statement in the Block", stmt.equals(TestCommandStatement.sample1())); //$NON-NLS-1$
}
@@ -79,7 +79,7 @@
public void testaddStatement2() {
Block b1 = (Block) sample2().clone();
b1.addStatement(TestCommandStatement.sample2());
- Statement stmt = (Statement) b1.getStatements().get(4);
+ Statement stmt = b1.getStatements().get(4);
assertTrue("Incorrect statement in the Block", stmt.equals(TestCommandStatement.sample2())); //$NON-NLS-1$
}
@@ -102,5 +102,12 @@
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, b1, b2);
}
+
+ public void testClone() {
+ Block b1 = sample1();
+ Block b2 = (Block)b1.clone();
+ UnitTestUtil.helpTestEquivalence(0, b1, b2);
+ assertNotSame(b1.getStatements().get(0), b2.getStatements().get(0));
+ }
}
More information about the teiid-commits
mailing list