jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1542614 - in /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op: OpAssign.java OpExtend.java OpExtendAssign.java
Date Sat, 16 Nov 2013 23:37:24 GMT
Author: andy
Date: Sat Nov 16 23:37:24 2013
New Revision: 1542614

URL: http://svn.apache.org/r1542614
Log:
Abstract commonality of OpAssign and OpExtend.

Added:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtendAssign.java
Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpAssign.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtend.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpAssign.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpAssign.java?rev=1542614&r1=1542613&r2=1542614&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpAssign.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpAssign.java Sat
Nov 16 23:37:24 2013
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package com.hp.hpl.jena.sparql.algebra.op;
+package com.hp.hpl.jena.sparql.algebra.op ;
 
 import org.apache.jena.atlas.lib.Lib ;
 
@@ -29,115 +29,97 @@ import com.hp.hpl.jena.sparql.expr.Expr 
 import com.hp.hpl.jena.sparql.sse.Tags ;
 import com.hp.hpl.jena.sparql.util.NodeIsomorphismMap ;
 
-public class OpAssign extends Op1
-{
-    private VarExprList assignments ;
-    
+public class OpAssign extends OpExtendAssign {
     // These factory operations compress nested assignments if possible.
     // Not possible if it's the reassignment of something already assigned.
     // Or we could implement something like (let*).
-    
-    static public Op assign(Op op, Var var, Expr expr)
-    {
-        if ( ! ( op instanceof OpAssign ) )
+
+    static public Op assign(Op op, Var var, Expr expr) {
+        if ( !(op instanceof OpAssign) )
             return createAssign(op, var, expr) ;
-        
+
         OpAssign opAssign = (OpAssign)op ;
         if ( opAssign.assignments.contains(var) )
-            // Same variable : 
-            // Layer one assignment over the top of another 
+            // Same variable :
+            // Layer one assignment over the top of another
             return createAssign(op, var, expr) ;
 
         opAssign.add(var, expr) ;
         return opAssign ;
     }
-    
-    static public Op assign(Op op, VarExprList exprs)
-    {
-        if ( ! ( op instanceof OpAssign ) )
+
+    static public Op assign(Op op, VarExprList exprs) {
+        if ( !(op instanceof OpAssign) )
             return createAssign(op, exprs) ;
-            
+
         OpAssign opAssign = (OpAssign)op ;
-        for ( Var var : exprs.getVars() )
-        {
+        for (Var var : exprs.getVars()) {
             if ( opAssign.assignments.contains(var) )
                 return createAssign(op, exprs) ;
         }
-            
+
         opAssign.assignments.addAll(exprs) ;
         return opAssign ;
     }
-    
+
     /** Make a OpAssign - guaranteed to return an OpAssign */
-    public static OpAssign assignDirect(Op op, VarExprList exprs)
-    {
+    public static OpAssign assignDirect(Op op, VarExprList exprs) {
         return new OpAssign(op, exprs) ;
     }
 
-    static private Op createAssign(Op op, Var var, Expr expr)
-    {
+    static private Op createAssign(Op op, Var var, Expr expr) {
         return new OpAssign(op, new VarExprList(var, expr)) ;
-    }   
-    
-    static private Op createAssign(Op op, VarExprList exprs)
-    {
+    }
+
+    static private Op createAssign(Op op, VarExprList exprs) {
         // Create, copying the var-expr list
         VarExprList x = new VarExprList() ;
         x.addAll(exprs) ;
         return new OpAssign(op, x) ;
-    }   
-    
-    private OpAssign(Op subOp)
-    {
-        super(subOp) ;
-        assignments = new VarExprList() ;
     }
-    
-    private OpAssign(Op subOp, VarExprList exprs)
-    {
+
+    private OpAssign(Op subOp) {
         super(subOp) ;
-        assignments = exprs ;
-    }
-    
-    @Override
-    public String getName() { return Tags.tagAssign ; }
-    
-    private void add(Var var, Expr expr)
-    {
-        // This checks for duplicate assignment. 
-        assignments.add(var, expr) ;
     }
 
-    public VarExprList getVarExprList() { return assignments ; }
+    private OpAssign(Op subOp, VarExprList exprs) {
+        super(subOp, exprs) ;
+    }
 
     @Override
-    public int hashCode()
-    { return assignments.hashCode() ^ getSubOp().hashCode() ; }
+    public String getName() {
+        return Tags.tagAssign ;
+    }
 
     @Override
-    public void visit(OpVisitor opVisitor)
-    { opVisitor.visit(this) ; }
+    public void visit(OpVisitor opVisitor) {
+        opVisitor.visit(this) ;
+    }
 
     @Override
-    public Op1 copy(Op subOp)
-    {
+    public Op1 copy(Op subOp) {
         OpAssign op = new OpAssign(subOp, new VarExprList(getVarExprList())) ;
         return op ;
     }
-
+    
     @Override
-    public boolean equalTo(Op other, NodeIsomorphismMap labelMap)
-    {
-        if ( ! ( other instanceof OpAssign) )
+    public boolean equalTo(Op other, NodeIsomorphismMap labelMap) {
+        if ( !(other instanceof OpAssign) )
             return false ;
         OpAssign assign = (OpAssign)other ;
-        
-        if ( ! Lib.equal(assignments, assign.assignments) )
+
+        if ( !Lib.equal(assignments, assign.assignments) )
             return false ;
         return getSubOp().equalTo(assign.getSubOp(), labelMap) ;
     }
 
     @Override
-    public Op apply(Transform transform, Op subOp)
-    { return transform.transform(this, subOp) ; }
+    public Op apply(Transform transform, Op subOp) {
+        return transform.transform(this, subOp) ;
+    }
+
+    @Override
+    public OpExtendAssign copy(Op subOp, VarExprList varExprList) {
+        return new OpAssign(subOp, varExprList) ;
+    }
 }

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtend.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtend.java?rev=1542614&r1=1542613&r2=1542614&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtend.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtend.java Sat
Nov 16 23:37:24 2013
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package com.hp.hpl.jena.sparql.algebra.op;
+package com.hp.hpl.jena.sparql.algebra.op ;
 
 import org.apache.jena.atlas.lib.Lib ;
 
@@ -29,117 +29,101 @@ import com.hp.hpl.jena.sparql.expr.Expr 
 import com.hp.hpl.jena.sparql.sse.Tags ;
 import com.hp.hpl.jena.sparql.util.NodeIsomorphismMap ;
 
-/** This is the operation in stadard SPARQL 1.1
- *  OpAssign is specifically in support of LET.
+/**
+ * This is the operation in stadard SPARQL 1.1 OpAssign is specifically in
+ * support of LET.
  */
-public class OpExtend extends Op1
-{
-    private VarExprList assignments ;
-    
+public class OpExtend extends OpExtendAssign {
     // There factory operations compress nested assignments if possible.
     // Not possible if it's the reassignment of something already assigned.
     // Or we could implement something like (let*).
-    
-    static public Op extend(Op op, Var var, Expr expr)
-    {
-        if ( ! ( op instanceof OpExtend ) )
+
+    static public Op extend(Op op, Var var, Expr expr) {
+        if ( !(op instanceof OpExtend) )
             return createExtend(op, var, expr) ;
-        
-        OpExtend opAssign = (OpExtend)op ;
-        if ( opAssign.assignments.contains(var) )
+
+        OpExtend opExtend = (OpExtend)op ;
+        if ( opExtend.assignments.contains(var) )
             return createExtend(op, var, expr) ;
 
-        opAssign.assignments.add(var, expr) ;
-        return opAssign ;
+        opExtend.assignments.add(var, expr) ;
+        return opExtend ;
     }
-    
-    static public Op extend(Op op, VarExprList exprs)
-    {
-        if ( ! ( op instanceof OpExtend ) )
+
+    static public Op extend(Op op, VarExprList exprs) {
+        if ( !(op instanceof OpExtend) )
             return createExtend(op, exprs) ;
-            
-        OpExtend opAssign = (OpExtend)op ;
-        for ( Var var : exprs.getVars() )
-        {
-            if ( opAssign.assignments.contains(var) )
+
+        OpExtend opExtend = (OpExtend)op ;
+        for (Var var : exprs.getVars()) {
+            if ( opExtend.assignments.contains(var) )
                 return createExtend(op, exprs) ;
         }
-            
-        opAssign.assignments.addAll(exprs) ;
-        return opAssign ;
+
+        opExtend.assignments.addAll(exprs) ;
+        return opExtend ;
     }
-    
+
     /** Make a OpExtend - guaranteed to return an OpExtend */
-    public static OpExtend extendDirect(Op op, VarExprList exprs)
-    {
+    public static OpExtend extendDirect(Op op, VarExprList exprs) {
         return new OpExtend(op, exprs) ;
     }
 
-    static private Op createExtend(Op op, Var var, Expr expr)
-    {
+    static private Op createExtend(Op op, Var var, Expr expr) {
         VarExprList x = new VarExprList() ;
         x.add(var, expr) ;
         return new OpExtend(op, x) ;
-    }   
-    
-    static private Op createExtend(Op op, VarExprList exprs)
-    {
+    }
+
+    static private Op createExtend(Op op, VarExprList exprs) {
         // Create, copying the var-expr list
         VarExprList x = new VarExprList() ;
         x.addAll(exprs) ;
         return new OpExtend(op, x) ;
-    }   
-    
-    private OpExtend(Op subOp)
-    {
-        super(subOp) ;
-        assignments = new VarExprList() ;
     }
-    
-    private OpExtend(Op subOp, VarExprList exprs)
-    {
+
+    private OpExtend(Op subOp) {
         super(subOp) ;
-        assignments = exprs ;
     }
-    
-    @Override
-    public String getName() { return Tags.tagExtend ; }
-    
-    // Need to protect this with checking for var already used.
-    // See the factories in statics above. 
-    private void add(Var var, Expr expr)
-    { assignments.add(var, expr) ; }
 
-    public VarExprList getVarExprList() { return assignments ; }
+    private OpExtend(Op subOp, VarExprList exprs) {
+        super(subOp, exprs) ;
+    }
 
     @Override
-    public int hashCode()
-    { return assignments.hashCode() ^ getSubOp().hashCode() ; }
+    public String getName() {
+        return Tags.tagExtend ;
+    }
 
     @Override
-    public void visit(OpVisitor opVisitor)
-    { opVisitor.visit(this) ; }
+    public void visit(OpVisitor opVisitor) {
+        opVisitor.visit(this) ;
+    }
 
     @Override
-    public Op1 copy(Op subOp)
-    {
+    public Op1 copy(Op subOp) {
         OpExtend op = new OpExtend(subOp, new VarExprList(getVarExprList())) ;
         return op ;
     }
 
     @Override
-    public boolean equalTo(Op other, NodeIsomorphismMap labelMap)
-    {
-        if ( ! ( other instanceof OpExtend) )
+    public boolean equalTo(Op other, NodeIsomorphismMap labelMap) {
+        if ( !(other instanceof OpExtend) )
             return false ;
         OpExtend assign = (OpExtend)other ;
-        
-        if ( ! Lib.equal(assignments, assign.assignments) )
+
+        if ( !Lib.equal(assignments, assign.assignments) )
             return false ;
         return getSubOp().equalTo(assign.getSubOp(), labelMap) ;
     }
 
     @Override
-    public Op apply(Transform transform, Op subOp)
-    { return transform.transform(this, subOp) ; }
+    public Op apply(Transform transform, Op subOp) {
+        return transform.transform(this, subOp) ;
+    }
+
+    @Override
+    public OpExtendAssign copy(Op subOp, VarExprList varExprList) {
+        return new OpExtend(subOp, varExprList) ;
+    }
 }

Added: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtendAssign.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtendAssign.java?rev=1542614&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtendAssign.java
(added)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/op/OpExtendAssign.java
Sat Nov 16 23:37:24 2013
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 at
+ *
+ *     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 com.hp.hpl.jena.sparql.algebra.op ;
+
+import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.sparql.core.VarExprList ;
+import com.hp.hpl.jena.sparql.expr.Expr ;
+
+public abstract class OpExtendAssign extends Op1 {
+    protected final VarExprList assignments ;
+
+    protected OpExtendAssign(Op subOp) {
+        super(subOp) ;
+        assignments = new VarExprList() ;
+    }
+
+    protected OpExtendAssign(Op subOp, VarExprList exprs) {
+        super(subOp) ;
+        assignments = exprs ;
+    }
+
+    final
+    protected void add(Var var, Expr expr) {
+        assignments.add(var, expr) ;
+    }
+
+    final
+    public VarExprList getVarExprList() {
+        return assignments ;
+    }
+
+    @Override
+    final 
+    public int hashCode()
+    { return getName().hashCode() ^ assignments.hashCode() ^ getSubOp().hashCode() ; }
+
+    public abstract OpExtendAssign copy(Op subOp, VarExprList varExprList) ;
+}



Mime
View raw message