[Mulgara-svn] r940 - trunk/src/jar/query/java/org/mulgara/query

pag at mulgara.org pag at mulgara.org
Thu May 15 02:34:38 UTC 2008


Author: pag
Date: 2008-05-14 19:34:38 -0700 (Wed, 14 May 2008)
New Revision: 940

Added:
   trunk/src/jar/query/java/org/mulgara/query/ConstraintBinaryOperation.java
Removed:
   trunk/src/jar/query/java/org/mulgara/query/ConstraintFilteredOperation.java
Modified:
   trunk/src/jar/query/java/org/mulgara/query/ConstraintConjunction.java
   trunk/src/jar/query/java/org/mulgara/query/ConstraintDifference.java
   trunk/src/jar/query/java/org/mulgara/query/ConstraintOperation.java
   trunk/src/jar/query/java/org/mulgara/query/ConstraintOptionalJoin.java
Log:
Refactored out the notion of 'Binary Operation' from ConstraintOptionalJoin so that ConstraintDifference would share these properties. This meant changing a method in ConstraintFilteredOperation to a static method in ConstraintOperation. This is a better location as the method was simply a utility and did not deserve to be in a common inherited class.

Added: trunk/src/jar/query/java/org/mulgara/query/ConstraintBinaryOperation.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/ConstraintBinaryOperation.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/mulgara/query/ConstraintBinaryOperation.java	2008-05-15 02:34:38 UTC (rev 940)
@@ -0,0 +1,63 @@
+package org.mulgara.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A common base class for operations that can only take binary operands.
+ * The {@link ConstraintOperation} class explicitly flattens out it's parameters, and this
+ * class avoids that, while still providing the functionality of that class.
+ *
+ * @created May 14, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public abstract class ConstraintBinaryOperation extends ConstraintOperation {
+
+  /**
+   * A binary-only constructor.
+   * @param lhs The LHS for the operation.
+   * @param rhs The RHS for the operation.
+   */
+  public ConstraintBinaryOperation(ConstraintExpression lhs, ConstraintExpression rhs) {
+    super(testedList(lhs, rhs));
+  }
+
+  /**
+   * Validate parameters and set them up as a list.
+   * @param lhs The main pattern
+   * @param rhs The optional pattern
+   * @return A 2 element list containing {lhs, rhs}
+   */
+  protected static List<ConstraintExpression> testedList(ConstraintExpression lhs, ConstraintExpression rhs) {
+    // Validate "lhs" parameter
+    if (lhs == null) throw new IllegalArgumentException("Null \"lhs\" parameter");
+  
+    // Validate "rhs" parameter
+    if (rhs == null) throw new IllegalArgumentException("Null \"optional\" parameter");
+  
+    // Initialize fields
+    List<ConstraintExpression> ops = new ArrayList<ConstraintExpression>(2);
+    ops.add(lhs);
+    ops.add(rhs);
+    return ops;
+  }
+
+  /**
+   * Get the LHS of this operation
+   * @return The LHS operand.
+   */
+  protected ConstraintExpression getLhs() {
+    return elements.get(0);
+  }
+
+  /**
+   * Get the RHS of this operation
+   * @return The RHS operand.
+   */
+  protected ConstraintExpression getRhs() {
+    return elements.get(1);
+  }
+
+}
\ No newline at end of file

Modified: trunk/src/jar/query/java/org/mulgara/query/ConstraintConjunction.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/ConstraintConjunction.java	2008-05-15 02:30:19 UTC (rev 939)
+++ trunk/src/jar/query/java/org/mulgara/query/ConstraintConjunction.java	2008-05-15 02:34:38 UTC (rev 940)
@@ -51,7 +51,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class ConstraintConjunction extends ConstraintFilteredOperation {
+public class ConstraintConjunction extends ConstraintOperation {
 
   /**
    * Allow newer compiled version of the stub to operate when changes

Modified: trunk/src/jar/query/java/org/mulgara/query/ConstraintDifference.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/ConstraintDifference.java	2008-05-15 02:30:19 UTC (rev 939)
+++ trunk/src/jar/query/java/org/mulgara/query/ConstraintDifference.java	2008-05-15 02:34:38 UTC (rev 940)
@@ -35,20 +35,11 @@
  * subexpressions.
  *
  * @created 2005-03-08
- *
  * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- *
- * @version $Revision: 1.2 $
- *
- * @modified $Date: 2005/05/29 08:32:39 $
- *
- * @maintenanceAuthor $Author: raboczi $
- *
  * @copyright &copy; 2005 <A href="mailto:pgearon at users.sourceforge.net">Paul Gearon</A>
- *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class ConstraintDifference extends ConstraintFilteredOperation {
+public class ConstraintDifference extends ConstraintBinaryOperation {
 
   /**
    * Allow newer compiled version of the stub to operate when changes

Deleted: trunk/src/jar/query/java/org/mulgara/query/ConstraintFilteredOperation.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/ConstraintFilteredOperation.java	2008-05-15 02:30:19 UTC (rev 939)
+++ trunk/src/jar/query/java/org/mulgara/query/ConstraintFilteredOperation.java	2008-05-15 02:34:38 UTC (rev 940)
@@ -1,81 +0,0 @@
-/**
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-package org.mulgara.query;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * A constraint operation where the result uses an intersection of variables from the parameters.
- *
- * @created Aug 20, 2007
- * @author Paul Gearon
- * @copyright &copy; 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public abstract class ConstraintFilteredOperation extends ConstraintOperation {
-
-  /**
-   * Create a binary operation for requiring intersecting variables.
-   * @param lhs The first constraint operations.
-   * @param rhs The second constraint operations.
-   */
-  public ConstraintFilteredOperation(ConstraintExpression lhs, ConstraintExpression rhs) {
-    super(lhs, rhs);
-  }
-
-
-  /**
-   * Create an operation for requiring intersecting variables.
-   * @param elements The list of expressions to use as parameters.
-   */
-  public ConstraintFilteredOperation(List<ConstraintExpression> elements) {
-    super(elements);
-  }
-
-  /**
-   * Remove the constraint expressions from the product that have non-intersecting variables.
-   *
-   * @param product The list of constraints to test and modify.
-   */
-  protected void filter(List<ConstraintExpression> product) {
-  
-    Set<Variable> o1 = new HashSet<Variable>();
-  
-    // Variables which occur at least once.
-    Set<Variable> o2 = new HashSet<Variable>();
-  
-    // Variables which occur two or more times.
-    // Get a set of variables which occur two or more times.
-    for (ConstraintExpression oc: product) {
-  
-      Set<Variable> ocVars = oc.getVariables();
-      Set<Variable> vars = new HashSet<Variable>(ocVars);
-      vars.retainAll(o1);
-      o2.addAll(vars);
-      o1.addAll(ocVars);
-    }
-  
-    // remove the expressions which have non-intersecting variables
-    for (Iterator<ConstraintExpression> pIt = product.iterator(); pIt.hasNext(); ) {
-  
-      ConstraintExpression oc = pIt.next();
-      Set<Variable> vars = new HashSet<Variable>(oc.getVariables());
-      vars.retainAll(o2);
-  
-      if (vars.isEmpty()) pIt.remove();
-    }
-  }
-
-}
\ No newline at end of file

Modified: trunk/src/jar/query/java/org/mulgara/query/ConstraintOperation.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/ConstraintOperation.java	2008-05-15 02:30:19 UTC (rev 939)
+++ trunk/src/jar/query/java/org/mulgara/query/ConstraintOperation.java	2008-05-15 02:34:38 UTC (rev 940)
@@ -216,4 +216,40 @@
    * @return The Name value
    */
   abstract String getName();
+
+
+  /**
+   * Remove the constraint expressions from the product that have non-intersecting variables.
+   *
+   * @param product The list of constraints to test and modify.
+   */
+  protected static void filter(List<ConstraintExpression> product) {
+  
+    Set<Variable> o1 = new HashSet<Variable>();
+  
+    // Variables which occur at least once.
+    Set<Variable> o2 = new HashSet<Variable>();
+  
+    // Variables which occur two or more times.
+    // Get a set of variables which occur two or more times.
+    for (ConstraintExpression oc: product) {
+  
+      Set<Variable> ocVars = oc.getVariables();
+      Set<Variable> vars = new HashSet<Variable>(ocVars);
+      vars.retainAll(o1);
+      o2.addAll(vars);
+      o1.addAll(ocVars);
+    }
+  
+    // remove the expressions which have non-intersecting variables
+    for (Iterator<ConstraintExpression> pIt = product.iterator(); pIt.hasNext(); ) {
+  
+      ConstraintExpression oc = pIt.next();
+      Set<Variable> vars = new HashSet<Variable>(oc.getVariables());
+      vars.retainAll(o2);
+  
+      if (vars.isEmpty()) pIt.remove();
+    }
+  }
+
 }

Modified: trunk/src/jar/query/java/org/mulgara/query/ConstraintOptionalJoin.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/ConstraintOptionalJoin.java	2008-05-15 02:30:19 UTC (rev 939)
+++ trunk/src/jar/query/java/org/mulgara/query/ConstraintOptionalJoin.java	2008-05-15 02:34:38 UTC (rev 940)
@@ -27,8 +27,6 @@
 
 package org.mulgara.query;
 
-import java.util.ArrayList;
-import java.util.List;
 
 import org.mulgara.query.filter.Filter;
 import org.mulgara.query.filter.value.Bool;
@@ -42,7 +40,7 @@
  * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
  */
 
-public class ConstraintOptionalJoin extends ConstraintOperation {
+public class ConstraintOptionalJoin extends ConstraintBinaryOperation {
 
   /**
    * Allow newer compiled version of the stub to operate when changes
@@ -50,7 +48,7 @@
    * NOTE : update this serialVersionUID when a method or a public member is
    * deleted.
    */
-  private static final long serialVersionUID = 4059489277371655516L;
+  private static final long serialVersionUID = -6776376724963178229L;
 
   private Filter filter = Bool.TRUE;
 
@@ -60,7 +58,7 @@
    * @param rhs another non-<code>null</code> constraint expression
    */
   public ConstraintOptionalJoin(ConstraintExpression lhs, ConstraintExpression rhs) {
-    super(testedList(lhs, rhs));
+    super(lhs, rhs);
   }
 
   /**
@@ -70,43 +68,23 @@
    * @param filter Filters the join.
    */
   public ConstraintOptionalJoin(ConstraintExpression lhs, ConstraintExpression rhs, Filter filter) {
-    super(testedList(lhs, rhs));
+    super(lhs, rhs);
     if (filter == null) throw new IllegalArgumentException("Null \"filter\" parameter");
     this.filter = filter;
   }
 
   /**
-   * Validate parameters and set them up as a list.
-   * @param lhs The main pattern
-   * @param rhs The optional pattern
-   * @return A 2 element list containing {lhs, rhs}
-   */
-  private static List<ConstraintExpression> testedList(ConstraintExpression lhs, ConstraintExpression rhs) {
-    // Validate "lhs" parameter
-    if (lhs == null) throw new IllegalArgumentException("Null \"lhs\" parameter");
-
-    // Validate "rhs" parameter
-    if (rhs == null) throw new IllegalArgumentException("Null \"optional\" parameter");
-
-    // Initialize fields
-    List<ConstraintExpression> ops = new ArrayList<ConstraintExpression>(2);
-    ops.add(lhs);
-    ops.add(rhs);
-    return ops;
-  }
-
-  /**
    * @return Get the LHS "main" parameter
    */
   public ConstraintExpression getMain() {
-    return elements.get(0);
+    return getLhs();
   }
 
   /**
    * @return Get the RHS "optional" parameter
    */
   public ConstraintExpression getOptional() {
-    return elements.get(1);
+    return getRhs();
   }
 
   /**




More information about the Mulgara-svn mailing list