jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1306230 - in /incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql: engine/main/VarFinder.java util/VarUtils.java
Date Wed, 28 Mar 2012 09:48:43 GMT
Author: andy
Date: Wed Mar 28 09:48:43 2012
New Revision: 1306230

URL: http://svn.apache.org/viewvc?rev=1306230&view=rev
Log:
DRYness.

Modified:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/VarFinder.java
    incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/VarUtils.java

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/VarFinder.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/VarFinder.java?rev=1306230&r1=1306229&r2=1306230&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/VarFinder.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/VarFinder.java
Wed Mar 28 09:48:43 2012
@@ -18,14 +18,13 @@
 
 package com.hp.hpl.jena.sparql.engine.main;
 
+import static com.hp.hpl.jena.sparql.util.VarUtils.* ;
 import java.util.HashSet ;
 import java.util.List ;
 import java.util.Map ;
 import java.util.Map.Entry ;
 import java.util.Set ;
 
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.sparql.algebra.Op ;
 import com.hp.hpl.jena.sparql.algebra.OpVisitorBase ;
 import com.hp.hpl.jena.sparql.algebra.op.OpAssign ;
@@ -69,27 +68,6 @@ public class VarFinder
         return VarUsageVisitor.apply(op).filterMentions ;
     }
 
-    // See also VarUtils.
-    
-    private static void vars(Set<Var> vars, Triple triple)
-    {
-        slot(vars, triple.getSubject()) ;
-        slot(vars, triple.getPredicate()) ;
-        slot(vars, triple.getObject()) ;
-    }
-    
-    private static void vars(Set<Var> acc, BasicPattern pattern)
-    {
-        for ( Triple triple : pattern )
-            vars(acc, triple) ;
-    }
-
-    private static void slot(Set<Var> vars, Node node)
-    {
-        if ( Var.isVar(node) )
-            vars.add(Var.alloc(node)) ;
-    }
-
     VarUsageVisitor varUsageVisitor ;
     
     public VarFinder(Op op)
@@ -129,25 +107,16 @@ public class VarFinder
         @Override
         public void visit(OpQuadPattern quadPattern)
         {
-            slot(defines, quadPattern.getGraphNode()) ;
+            addVar(defines, quadPattern.getGraphNode()) ;
             BasicPattern triples = quadPattern.getBasicPattern() ;
-            vars(defines, triples) ;
-//            List quads = quadPattern.getQuads() ;
-//            for ( Iterator iter = quads.iterator() ; iter.hasNext(); )
-//            {
-//                Quad quad = (Quad)iter.next() ;
-//                //slot(quad.getGraph()) ;
-//                slot(defines, quad.getSubject()) ;
-//                slot(defines, quad.getPredicate()) ;
-//                slot(defines, quad.getObject()) ;
-//            }
+            addVars(defines, triples) ;
         }
 
         @Override
         public void visit(OpBGP opBGP)
         {
             BasicPattern triples = opBGP.getPattern() ;
-            vars(defines, triples) ;
+            addVars(defines, triples) ;
         }
         
         @Override
@@ -232,7 +201,7 @@ public class VarFinder
         @Override
         public void visit(OpGraph opGraph)
         {
-            slot(defines, opGraph.getNode()) ;
+            addVar(defines, opGraph.getNode()) ;
             opGraph.getSubOp().visit(this) ;
         }
         

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/VarUtils.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/VarUtils.java?rev=1306230&r1=1306229&r2=1306230&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/VarUtils.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/VarUtils.java
Wed Mar 28 09:48:43 2012
@@ -24,6 +24,7 @@ import java.util.Set ;
 
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.BasicPattern ;
 import com.hp.hpl.jena.sparql.core.TriplePath ;
 import com.hp.hpl.jena.sparql.core.Var ;
 
@@ -42,22 +43,31 @@ public class VarUtils
         addVar(acc, t.getPredicate()) ;
         addVar(acc, t.getObject()) ;
     }
-    
+
     public static void addVarsFromTriplePath(Collection<Var> acc, TriplePath tpath)
     {
         addVar(acc, tpath.getSubject()) ;
         addVar(acc, tpath.getObject()) ;
     }
-    
+
     public static void addVar(Collection<Var> acc, Node n)
     {
         if ( n == null )
             return ;
-        
+
         if ( n.isVariable() )
             acc.add(Var.alloc(n)) ;
     }
-    
-    
+
+    public static void addVars(Collection<Var> acc, BasicPattern pattern)
+    {
+        addVars(acc, pattern.getList()) ;
+    }
+
+    public static void addVars(Collection<Var> acc, Collection<Triple> triples)
+    {
+        for ( Triple triple : triples )
+            addVarsFromTriple(acc, triple) ;
+    }
 
 }



Mime
View raw message