Refactored RepartitionComputerFactory

git-svn-id: https://hyracks.googlecode.com/svn/trunk@28 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/RepartitionComputerFactory.java b/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/RepartitionComputerFactory.java
new file mode 100644
index 0000000..dbb1780
--- /dev/null
+++ b/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/RepartitionComputerFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.hyracks.coreops;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITuplePartitionComputer;
+import edu.uci.ics.hyracks.api.dataflow.value.ITuplePartitionComputerFactory;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.comm.io.FrameTupleAccessor;
+
+public class RepartitionComputerFactory implements ITuplePartitionComputerFactory {
+    private static final long serialVersionUID = 1L;
+
+    private int factor;
+    private ITuplePartitionComputerFactory delegateFactory;
+
+    public RepartitionComputerFactory(int factor, ITuplePartitionComputerFactory delegate) {
+        this.factor = factor;
+        this.delegateFactory = delegate;
+    }
+
+    @Override
+    public ITuplePartitionComputer createPartitioner() {
+        return new ITuplePartitionComputer() {
+            private ITuplePartitionComputer delegate = delegateFactory.createPartitioner();
+
+            @Override
+            public int partition(FrameTupleAccessor accessor, int tIndex, int nParts) throws HyracksDataException {
+                return delegate.partition(accessor, tIndex, factor * nParts) / factor;
+            }
+        };
+    }
+}
\ No newline at end of file
diff --git a/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/join/GraceHashJoinOperatorDescriptor.java b/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/join/GraceHashJoinOperatorDescriptor.java
index 79d88af..c38b9ce 100644
--- a/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/join/GraceHashJoinOperatorDescriptor.java
+++ b/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/join/GraceHashJoinOperatorDescriptor.java
@@ -40,6 +40,7 @@
 import edu.uci.ics.hyracks.comm.util.FrameUtils;
 import edu.uci.ics.hyracks.context.HyracksContext;
 import edu.uci.ics.hyracks.coreops.FieldHashPartitionComputerFactory;
+import edu.uci.ics.hyracks.coreops.RepartitionComputerFactory;
 import edu.uci.ics.hyracks.coreops.base.AbstractActivityNode;
 import edu.uci.ics.hyracks.coreops.base.AbstractOperatorDescriptor;
 
@@ -264,10 +265,6 @@
 
             IOperatorNodePushable op = new IOperatorNodePushable() {
                 private InMemoryHashJoin joiner;
-                private ITuplePartitionComputer hpc0 = new FieldHashPartitionComputerFactory(keys0,
-                        hashFunctionFactories).createPartitioner();
-                private ITuplePartitionComputer hpc1 = new FieldHashPartitionComputerFactory(keys1,
-                        hashFunctionFactories).createPartitioner();
 
                 private IFrameWriter writer;
                 private FileChannel[] channelsR;
@@ -281,8 +278,10 @@
                     channelsS = (FileChannel[]) env.get(LARGERELATION);
                     numPartitions = (Integer) env.get(NUM_PARTITION);
 
-                    ITuplePartitionComputer hpcRep0 = new RepartitionComputer(numPartitions, hpc0);
-                    ITuplePartitionComputer hpcRep1 = new RepartitionComputer(numPartitions, hpc1);
+                    ITuplePartitionComputer hpcRep0 = new RepartitionComputerFactory(numPartitions,
+                            new FieldHashPartitionComputerFactory(keys0, hashFunctionFactories)).createPartitioner();
+                    ITuplePartitionComputer hpcRep1 = new RepartitionComputerFactory(numPartitions,
+                            new FieldHashPartitionComputerFactory(keys1, hashFunctionFactories)).createPartitioner();
 
                     writer.open();// open for probe
 
diff --git a/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/join/RepartitionComputer.java b/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/join/RepartitionComputer.java
deleted file mode 100644
index c5c3af8..0000000
--- a/hyracks/hyracks-core/src/main/java/edu/uci/ics/hyracks/coreops/join/RepartitionComputer.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.coreops.join;
-
-import edu.uci.ics.hyracks.api.dataflow.value.ITuplePartitionComputer;
-import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.comm.io.FrameTupleAccessor;
-
-public class RepartitionComputer implements ITuplePartitionComputer {
-    private int factor;
-    private ITuplePartitionComputer delegate;
-
-    public RepartitionComputer(int factor, ITuplePartitionComputer delegate) {
-        super();
-        this.factor = factor;
-        this.delegate = delegate;
-    }
-
-    @Override
-    public int partition(FrameTupleAccessor accessor, int tIndex, int nParts) throws HyracksDataException {
-        return delegate.partition(accessor, tIndex, factor * nParts) / factor;
-    }
-}
\ No newline at end of file