You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/07/14 11:17:31 UTC

[1/5] jena git commit: Remove junk

Repository: jena
Updated Branches:
  refs/heads/master c25470da5 -> 20ac8e6f7


Remove junk


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/51044329
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/51044329
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/51044329

Branch: refs/heads/master
Commit: 51044329622d3287286f1394a266bdf9326541c4
Parents: c25470d
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Jul 13 20:20:53 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Jul 13 21:43:30 2015 +0100

----------------------------------------------------------------------
 .../ElementTransformCleanGroupsOfOne.java       | 53 ++++----------------
 1 file changed, 11 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/51044329/jena-arq/src/main/java/org/apache/jena/sparql/syntax/syntaxtransform/ElementTransformCleanGroupsOfOne.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/syntax/syntaxtransform/ElementTransformCleanGroupsOfOne.java b/jena-arq/src/main/java/org/apache/jena/sparql/syntax/syntaxtransform/ElementTransformCleanGroupsOfOne.java
index d1300c3..0757c22 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/syntax/syntaxtransform/ElementTransformCleanGroupsOfOne.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/syntax/syntaxtransform/ElementTransformCleanGroupsOfOne.java
@@ -27,56 +27,24 @@ import org.apache.jena.sparql.syntax.* ;
  *  They do matter for <code>OPTIONAL { { ?s ?p ?o FILTER(?foo) } }</code>.
  */
 public class ElementTransformCleanGroupsOfOne extends ElementTransformCopyBase {
-
+    // Improvements: scan group elements to work out for non-reducable adjacents.
+    // These ones may clash with an adjeact one in the group above.
+    // ElementTransformCleanGroupsOfOne -> ElementTransformCleanGroups
+    
     public ElementTransformCleanGroupsOfOne() {}
     
     @Override
     public Element transform(ElementGroup eltGroup, List<Element> elts) {
-        if ( elts.size() != 1 ) {
-            // Adjecent elements be sorted out?
-            boolean isSafe = true ;
-            for ( Element elt : elts ) {
-                if ( isSafe ) {
-                    // is it a group ? or one?
-                    
-                }
-                    
-                
-                if ( ( elt instanceof ElementTriplesBlock ) ||
-                     ( elt instanceof ElementPathBlock ) ||
-                     ( elt instanceof ElementFilter ) ) {
-                    isSafe = false ;
-                }
-                    
-            }
-            
-            
+        if ( elts.size() != 1 )
             return super.transform(eltGroup, elts) ;
-            
-        }
         Element elt = elts.get(0) ;
-        // Improvements: scan group elements to work out for non-reducable adjacentts.  
         if ( ( elt instanceof ElementTriplesBlock ) ||
-                ( elt instanceof ElementPathBlock ) ||
-                ( elt instanceof ElementFilter ) )
+             ( elt instanceof ElementPathBlock ) ||
+             ( elt instanceof ElementFilter ) )
             return super.transform(eltGroup, elts) ;    // No transformation.
         return elt ;
-        
-        // Remove if:
-        //???  Do this one level up (!= 1) and look for adajacent safe to collapse items
     }
 
-    // Plan B work from one level above.
-    
-    private boolean containsFilter(ElementGroup eltGroup) {
-        return eltGroup.getElements().stream().anyMatch(el2 ->( el2 instanceof ElementFilter ) ) ;
-//        for ( Element el2 : eltGroup.getElements() ) {
-//            if ( el2 instanceof ElementFilter )
-//                return true ;
-//        }
-//        return false ;
-    }
-    
     // Special case: If Optional, and the original had a {{}} protected filter, keep {{}}
     // transform/ElementGroup has already run so undo if necessary.
     @Override
@@ -92,8 +60,6 @@ public class ElementTransformCleanGroupsOfOne extends ElementTransformCopyBase {
         // Step 1 : does the original eltOptional has a {{}} RHS? 
         Element x = eltOptional.getOptionalElement() ;
         
-        
-        
         if ( ! ( x instanceof ElementGroup ) )
             // No. But it is not possible in written query syntax to have a nongroup as the RHS. 
             return super.transform(eltOptional, transformedElt) ;
@@ -121,7 +87,10 @@ public class ElementTransformCleanGroupsOfOne extends ElementTransformCopyBase {
         } 
         // No need to protect - process as usual.
         return super.transform(eltOptional, transformedElt) ;
-
+    }
+    
+    private boolean containsFilter(ElementGroup eltGroup) {
+        return eltGroup.getElements().stream().anyMatch(el2 ->( el2 instanceof ElementFilter ) ) ;
     }
     
     // Removed layers of groups of one.  Return inner most group.


[5/5] jena git commit: JENA-989 : Output '.' between items in an ElementPathBlock.

Posted by an...@apache.org.
JENA-989 : Output '.' between items in an ElementPathBlock.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/20ac8e6f
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/20ac8e6f
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/20ac8e6f

Branch: refs/heads/master
Commit: 20ac8e6f768888981f312a5ce6008ffdbc9f2fd9
Parents: 85ed839
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jul 14 10:15:45 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jul 14 10:17:12 2015 +0100

----------------------------------------------------------------------
 .../sparql/serializer/FormatterElement.java     | 24 ++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/20ac8e6f/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
index 6bd17eb..a8bea2e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
@@ -112,30 +112,46 @@ public class FormatterElement extends FormatterBase
 
     @Override
     public void visit(ElementPathBlock el) {
+        // Write path block - don't put in a final trailing "." 
         if ( el.isEmpty() ) {
             out.println("# Empty BGP") ;
             return ;
         }
 
         // Split into BGP-path-BGP-...
+        // where the BGPs may be empty.
         PathBlock pBlk = el.getPattern() ;
         BasicPattern bgp = new BasicPattern() ;
-        boolean first = true ;
+        boolean first = true ;      // Has anything been output?
         for ( TriplePath tp : pBlk ) {
             if ( tp.isTriple() ) {
                 bgp.add(tp.asTriple()) ;
                 continue ;
             }
-            flush(bgp) ;
-            out.println(" .") ;
+            
+            if ( !bgp.isEmpty() ) {
+                if ( !first )
+                    out.println(" .") ;
+                flush(bgp) ;
+                first = false ;
+            }
+            if ( !first )
+                out.println(" .") ;
             // Path
             printSubject(tp.getSubject()) ;
             out.print(" ") ;
             PathWriter.write(out, tp.getPath(), context.getPrologue()) ;
             out.print(" ") ;
             printObject(tp.getObject()) ;
+            first = false ;
+        }
+        // Flush any stored triple patterns.
+        if ( !bgp.isEmpty() ) {
+            if ( !first )
+                out.println(" .") ;
+            flush(bgp) ;
+            first = false ;
         }
-        flush(bgp) ;
     }
 
     private void flush(BasicPattern bgp) {


[4/5] jena git commit: Tests for JENA-989

Posted by an...@apache.org.
Tests for JENA-989


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/85ed839b
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/85ed839b
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/85ed839b

Branch: refs/heads/master
Commit: 85ed839b0d184995810a3fe0e232c184d47ede36
Parents: 3c0a62f
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jul 14 10:11:46 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jul 14 10:16:59 2015 +0100

----------------------------------------------------------------------
 jena-arq/testing/ARQ/Serialization/func.sh      |  1 -
 jena-arq/testing/ARQ/Serialization/manifest.ttl | 24 ++++++++++++++++++++
 .../testing/ARQ/Serialization/syntax-path-01.rq |  5 ++++
 .../testing/ARQ/Serialization/syntax-path-02.rq |  5 ++++
 .../testing/ARQ/Serialization/syntax-path-03.rq |  6 +++++
 .../testing/ARQ/Serialization/syntax-path-04.rq |  6 +++++
 .../testing/ARQ/Serialization/syntax-path-05.rq |  7 ++++++
 .../testing/ARQ/Serialization/syntax-path-06.rq |  8 +++++++
 8 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/func.sh
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/func.sh b/jena-arq/testing/ARQ/Serialization/func.sh
index a901b3c..e8ba65f 100644
--- a/jena-arq/testing/ARQ/Serialization/func.sh
+++ b/jena-arq/testing/ARQ/Serialization/func.sh
@@ -16,7 +16,6 @@ function createManifest
     mf:entries
     ( 
 EOF
-    # Queries good syntax
     for f in *.rq *.arq
       do
       cat >> manifest.ttl <<EOF

http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/manifest.ttl
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/manifest.ttl b/jena-arq/testing/ARQ/Serialization/manifest.ttl
index 828a301..981a8d3 100644
--- a/jena-arq/testing/ARQ/Serialization/manifest.ttl
+++ b/jena-arq/testing/ARQ/Serialization/manifest.ttl
@@ -472,6 +472,30 @@
          rdf:type   mfx:TestSerialization ;
          mf:action  <syntax-pat-04.rq> ; 
       ]
+      [  mf:name    "syntax-path-01.rq" ;
+         rdf:type   mfx:TestSerialization ;
+         mf:action  <syntax-path-01.rq> ; 
+      ]
+      [  mf:name    "syntax-path-02.rq" ;
+         rdf:type   mfx:TestSerialization ;
+         mf:action  <syntax-path-02.rq> ; 
+      ]
+      [  mf:name    "syntax-path-03.rq" ;
+         rdf:type   mfx:TestSerialization ;
+         mf:action  <syntax-path-03.rq> ; 
+      ]
+      [  mf:name    "syntax-path-04.rq" ;
+         rdf:type   mfx:TestSerialization ;
+         mf:action  <syntax-path-04.rq> ; 
+      ]
+      [  mf:name    "syntax-path-05.rq" ;
+         rdf:type   mfx:TestSerialization ;
+         mf:action  <syntax-path-05.rq> ; 
+      ]
+      [  mf:name    "syntax-path-06.rq" ;
+         rdf:type   mfx:TestSerialization ;
+         mf:action  <syntax-path-06.rq> ; 
+      ]
       [  mf:name    "syntax-qname-01.rq" ;
          rdf:type   mfx:TestSerialization ;
          mf:action  <syntax-qname-01.rq> ; 

http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/syntax-path-01.rq
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/syntax-path-01.rq b/jena-arq/testing/ARQ/Serialization/syntax-path-01.rq
new file mode 100644
index 0000000..15a5b29
--- /dev/null
+++ b/jena-arq/testing/ARQ/Serialization/syntax-path-01.rq
@@ -0,0 +1,5 @@
+PREFIX : <http://example/>
+
+SELECT * {
+  :s :p* ?x .
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/syntax-path-02.rq
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/syntax-path-02.rq b/jena-arq/testing/ARQ/Serialization/syntax-path-02.rq
new file mode 100644
index 0000000..eb9da30
--- /dev/null
+++ b/jena-arq/testing/ARQ/Serialization/syntax-path-02.rq
@@ -0,0 +1,5 @@
+PREFIX : <http://example/>
+
+SELECT * {
+  :s (:p*/:q?) ?x .
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/syntax-path-03.rq
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/syntax-path-03.rq b/jena-arq/testing/ARQ/Serialization/syntax-path-03.rq
new file mode 100644
index 0000000..b094699
--- /dev/null
+++ b/jena-arq/testing/ARQ/Serialization/syntax-path-03.rq
@@ -0,0 +1,6 @@
+PREFIX : <http://example/>
+
+SELECT * {
+  ?s ?p ?o .
+  :s :p* ?x .
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/syntax-path-04.rq
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/syntax-path-04.rq b/jena-arq/testing/ARQ/Serialization/syntax-path-04.rq
new file mode 100644
index 0000000..b094699
--- /dev/null
+++ b/jena-arq/testing/ARQ/Serialization/syntax-path-04.rq
@@ -0,0 +1,6 @@
+PREFIX : <http://example/>
+
+SELECT * {
+  ?s ?p ?o .
+  :s :p* ?x .
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/syntax-path-05.rq
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/syntax-path-05.rq b/jena-arq/testing/ARQ/Serialization/syntax-path-05.rq
new file mode 100644
index 0000000..dfda59f
--- /dev/null
+++ b/jena-arq/testing/ARQ/Serialization/syntax-path-05.rq
@@ -0,0 +1,7 @@
+PREFIX : <http://example/>
+
+SELECT * {
+  ?s ?p ?o1 .
+  :s :p* ?x .
+  ?s ?p ?o2 .
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/85ed839b/jena-arq/testing/ARQ/Serialization/syntax-path-06.rq
----------------------------------------------------------------------
diff --git a/jena-arq/testing/ARQ/Serialization/syntax-path-06.rq b/jena-arq/testing/ARQ/Serialization/syntax-path-06.rq
new file mode 100644
index 0000000..e80012c
--- /dev/null
+++ b/jena-arq/testing/ARQ/Serialization/syntax-path-06.rq
@@ -0,0 +1,8 @@
+PREFIX : <http://example/>
+
+SELECT * {
+  ?s ?p ?o1 .
+  :s :p* ?x1,?x2 .
+  ?s ?p ?o2 .
+  :s :p* ?x1; (:q1|:q2) ?x2 .
+}


[3/5] jena git commit: Reformat

Posted by an...@apache.org.
Reformat

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3c0a62f6
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3c0a62f6
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3c0a62f6

Branch: refs/heads/master
Commit: 3c0a62f6222ed64feb60b40c494590e35cdd2895
Parents: d306f53
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Jul 14 08:55:44 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Jul 14 08:55:44 2015 +0100

----------------------------------------------------------------------
 .../sparql/serializer/FormatterElement.java     | 357 ++++++++-----------
 1 file changed, 147 insertions(+), 210 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3c0a62f6/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
index 4abb1fa..6bd17eb 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/serializer/FormatterElement.java
@@ -79,35 +79,31 @@ public class FormatterElement extends FormatterBase
     
     public static final int TRIPLES_COLUMN_GAP = 2 ;
 
-    public FormatterElement(IndentedWriter out, SerializationContext context)
-    {
+    public FormatterElement(IndentedWriter out, SerializationContext context) {
         super(out, context) ;
     }
-    
-    public static void format(IndentedWriter out, SerializationContext cxt, Element el)
-    {
+
+    public static void format(IndentedWriter out, SerializationContext cxt, Element el) {
         FormatterElement fmt = new FormatterElement(out, cxt) ;
         fmt.startVisit() ;
         el.visit(fmt) ;
         fmt.finishVisit() ;
     }
-    
-    
-    public static String asString(Element el)
-    {
+
+    public static String asString(Element el) {
         SerializationContext cxt = new SerializationContext() ;
         IndentedLineBuffer b = new IndentedLineBuffer() ;
         FormatterElement.format(b, cxt, el) ;
         return b.toString() ;
     }
 
-    public boolean topMustBeGroup() { return false ; }
-    
+    public boolean topMustBeGroup() {
+        return false ;
+    }
+
     @Override
-    public void visit(ElementTriplesBlock el)
-    {
-        if ( el.isEmpty() )
-        {
+    public void visit(ElementTriplesBlock el) {
+        if ( el.isEmpty() ) {
             out.println("# Empty BGP") ;
             return ;
         }
@@ -116,32 +112,30 @@ public class FormatterElement extends FormatterBase
 
     @Override
     public void visit(ElementPathBlock el) {
-      if ( el.isEmpty() ) 
-      {
-          out.println("# Empty BGP") ;
-          return ;
-      }
-        
-      // Split into BGP-path-BGP-...
-      PathBlock pBlk = el.getPattern() ;
-      BasicPattern bgp = new BasicPattern() ;
-      boolean first = true ;
-      for ( TriplePath tp : pBlk )
-      {
-          if ( tp.isTriple() ) {
-              bgp.add(tp.asTriple());
-              continue ;
-          }
-          flush(bgp) ;
-          out.println(" .") ;    
-          // Path
-          printSubject(tp.getSubject()) ;
-          out.print(" ") ;
-          PathWriter.write(out, tp.getPath(), context.getPrologue()) ;
-          out.print(" ") ;
-          printObject(tp.getObject()) ;
-      }
-      flush(bgp) ;
+        if ( el.isEmpty() ) {
+            out.println("# Empty BGP") ;
+            return ;
+        }
+
+        // Split into BGP-path-BGP-...
+        PathBlock pBlk = el.getPattern() ;
+        BasicPattern bgp = new BasicPattern() ;
+        boolean first = true ;
+        for ( TriplePath tp : pBlk ) {
+            if ( tp.isTriple() ) {
+                bgp.add(tp.asTriple()) ;
+                continue ;
+            }
+            flush(bgp) ;
+            out.println(" .") ;
+            // Path
+            printSubject(tp.getSubject()) ;
+            out.print(" ") ;
+            PathWriter.write(out, tp.getPath(), context.getPrologue()) ;
+            out.print(" ") ;
+            printObject(tp.getObject()) ;
+        }
+        flush(bgp) ;
     }
 
     private void flush(BasicPattern bgp) {
@@ -179,22 +173,21 @@ public class FormatterElement extends FormatterBase
     }
 
     @Override
-    public void visit(ElementFilter el)
-    {
+    public void visit(ElementFilter el) {
         out.print("FILTER ") ;
         Expr expr = el.getExpr() ;
         FmtExprSPARQL v = new FmtExprSPARQL(out, context) ;
-        
+
         // This assumes that complex expressions are bracketted
         // (parens) as necessary except for some cases:
-        //   Plain variable or constant
-        
+        // Plain variable or constant
+
         boolean addParens = false ;
         if ( expr.isVariable() )
             addParens = true ;
         if ( expr.isConstant() )
             addParens = true ;
-        
+
         if ( addParens )
             out.print("( ") ;
         v.format(expr) ;
@@ -203,10 +196,9 @@ public class FormatterElement extends FormatterBase
     }
 
     @Override
-    public void visit(ElementAssign el)
-    {
+    public void visit(ElementAssign el) {
         out.print("LET (") ;
-        out.print("?"+el.getVar().getVarName()) ;
+        out.print("?" + el.getVar().getVarName()) ;
         out.print(" := ") ;
         FmtExprSPARQL v = new FmtExprSPARQL(out, context) ;
         v.format(el.getExpr()) ;
@@ -214,31 +206,27 @@ public class FormatterElement extends FormatterBase
     }
 
     @Override
-    public void visit(ElementBind el)
-    {
+    public void visit(ElementBind el) {
         out.print("BIND(") ;
         FmtExprSPARQL v = new FmtExprSPARQL(out, context) ;
         v.format(el.getExpr()) ;
         out.print(" AS ") ;
-        out.print("?"+el.getVar().getVarName()) ;
+        out.print("?" + el.getVar().getVarName()) ;
         out.print(")") ;
     }
 
     @Override
-    public void visit(ElementData el)
-    {
+    public void visit(ElementData el) {
         QuerySerializer.outputDataBlock(out, el.getVars(), el.getRows(), context.getPrologue()) ;
     }
 
     @Override
-    public void visit(ElementUnion el)
-    {
-        if ( el.getElements().size() == 1 )
-        {
+    public void visit(ElementUnion el) {
+        if ( el.getElements().size() == 1 ) {
             // If this is an element of just one, just do it inplace
             // Can't happen from a parsed query.
             // Now can :-)
-            
+
             // SPARQL 1.1 inline UNION.
             // Same as OPTIONAL, MINUS
             out.print("UNION") ;
@@ -249,67 +237,58 @@ public class FormatterElement extends FormatterBase
             return ;
         }
 
-        if ( UNION_MARKERS )
-        {
+        if ( UNION_MARKERS ) {
             out.print("{") ;
             out.newline() ;
             out.pad() ;
         }
-            
+
         out.incIndent(INDENT) ;
-        
-        boolean first = true ;
-        for ( Element subElement : el.getElements() )
-        {
 
-            if ( !first )
-            {
-                out.decIndent( INDENT );
-                out.newline();
-                out.print( "UNION" );
-                out.newline();
-                out.incIndent( INDENT );
+        boolean first = true ;
+        for ( Element subElement : el.getElements() ) {
+            if ( !first ) {
+                out.decIndent(INDENT) ;
+                out.newline() ;
+                out.print("UNION") ;
+                out.newline() ;
+                out.incIndent(INDENT) ;
             }
-            visitAsGroup( subElement );
-            first = false;
+            visitAsGroup(subElement) ;
+            first = false ;
         }
-        
+
         out.decIndent(INDENT) ;
 
-        if ( UNION_MARKERS )
-        {
+        if ( UNION_MARKERS ) {
             out.newline() ;
             out.print("}") ;
         }
     }
 
-    
     @Override
-    public void visit(ElementGroup el)
-    {
+    public void visit(ElementGroup el) {
         out.print("{") ;
         int initialRowNumber = out.getRow() ;
         out.incIndent(INDENT) ;
-        if ( ! GROUP_FIRST_ON_SAME_LINE )
-            out.newline() ;  
-        
+        if ( !GROUP_FIRST_ON_SAME_LINE )
+            out.newline() ;
+
         int row1 = out.getRow() ;
         out.pad() ;
-    
+
         boolean first = true ;
         Element lastElt = null ;
 
-        for ( Element subElement : el.getElements())
-        {
+        for ( Element subElement : el.getElements() ) {
             // Some adjacent elements need a DOT:
             // ElementTriplesBlock, ElementPathBlock
-            if ( ! first )
-            {
+            if ( !first ) {
                 // Need to move on after the last thing printed.
                 // Check for necessary DOT as separator
                 if ( GROUP_SEP_DOT || needsDotSeparator(lastElt, subElement) )
                     out.print(" . ") ;
-                out.newline() ;    
+                out.newline() ;
             }
             subElement.visit(this) ;
             first = false ;
@@ -328,19 +307,16 @@ public class FormatterElement extends FormatterBase
         out.print("}") ;
     }
 
-    private static boolean needsDotSeparator(Element el1, Element el2)
-    {
+    private static boolean needsDotSeparator(Element el1, Element el2) {
         return needsDotSeparator(el1) && needsDotSeparator(el2) ;
     }
-    
-    private static boolean needsDotSeparator(Element el)
-    {
-        return ( el instanceof ElementTriplesBlock ) || ( el instanceof ElementPathBlock ) ;
+
+    private static boolean needsDotSeparator(Element el) {
+        return (el instanceof ElementTriplesBlock) || (el instanceof ElementPathBlock) ;
     }
 
     @Override
-    public void visit(ElementOptional el)
-    {
+    public void visit(ElementOptional el) {
         out.print("OPTIONAL") ;
         out.incIndent(INDENT) ;
         out.newline() ;
@@ -348,62 +324,51 @@ public class FormatterElement extends FormatterBase
         out.decIndent(INDENT) ;
     }
 
-
     @Override
-    public void visit(ElementNamedGraph el)
-    {
+    public void visit(ElementNamedGraph el) {
         visitNodePattern("GRAPH", el.getGraphNameNode(), el.getElement()) ;
     }
 
     @Override
-    public void visit(ElementService el)
-    {
+    public void visit(ElementService el) {
         String x = "SERVICE" ;
         if ( el.getSilent() )
             x = "SERVICE SILENT" ;
         visitNodePattern(x, el.getServiceNode(), el.getElement()) ;
     }
 
-    private void visitNodePattern(String label, Node node, Element subElement)
-    {
+    private void visitNodePattern(String label, Node node, Element subElement) {
         int len = label.length() ;
         out.print(label) ;
         out.print(" ") ;
-        String nodeStr = ( node == null ) ? "*" : slotToString(node) ;
+        String nodeStr = (node == null) ? "*" : slotToString(node) ;
         out.print(nodeStr) ;
         len += nodeStr.length() ;
-        if ( GRAPH_FIXED_INDENT )
-        {
+        if ( GRAPH_FIXED_INDENT ) {
             out.incIndent(INDENT) ;
             out.newline() ; // NB and newline
-        }
-        else
-        {
+        } else {
             out.print(" ") ;
             len++ ;
             out.incIndent(len) ;
         }
         visitAsGroup(subElement) ;
-        
+
         if ( GRAPH_FIXED_INDENT )
             out.decIndent(INDENT) ;
         else
             out.decIndent(len) ;
     }
 
-    private void visitElement1(String label, Element1 el)
-    {
+    private void visitElement1(String label, Element1 el) {
 
         int len = label.length() ;
         out.print(label) ;
         len += label.length() ;
-        if ( ELEMENT1_FIXED_INDENT )
-        {
+        if ( ELEMENT1_FIXED_INDENT ) {
             out.incIndent(INDENT) ;
             out.newline() ; // NB and newline
-        }
-        else
-        {
+        } else {
             out.print(" ") ;
             len++ ;
             out.incIndent(len) ;
@@ -416,78 +381,66 @@ public class FormatterElement extends FormatterBase
     }
 
     @Override
-    public void visit(ElementExists el)
-    {
+    public void visit(ElementExists el) {
         visitElement1("EXISTS", el) ;
     }
 
     @Override
-    public void visit(ElementNotExists el)
-    {
+    public void visit(ElementNotExists el) {
         visitElement1("NOT EXISTS", el) ;
     }
-    
+
     @Override
-    public void visit(ElementMinus el)
-    {
+    public void visit(ElementMinus el) {
         out.print("MINUS") ;
         out.incIndent(INDENT) ;
         out.newline() ;
         visitAsGroup(el.getMinusElement()) ;
         out.decIndent(INDENT) ;
     }
-    
+
     @Override
-    public void visit(ElementSubQuery el)
-    {
+    public void visit(ElementSubQuery el) {
         out.print("{ ") ;
         out.incIndent(INDENT) ;
         Query q = el.getQuery() ;
-        
+
         // Serialize with respect to the existing context
-        QuerySerializerFactory factory = SerializerRegistry.get().getQuerySerializerFactory(Syntax.syntaxARQ);
-        QueryVisitor serializer = factory.create(Syntax.syntaxARQ, context, out);
-        q.visit(serializer);
-        
+        QuerySerializerFactory factory = SerializerRegistry.get().getQuerySerializerFactory(Syntax.syntaxARQ) ;
+        QueryVisitor serializer = factory.create(Syntax.syntaxARQ, context, out) ;
+        q.visit(serializer) ;
+
         out.decIndent(INDENT) ;
         out.print("}") ;
     }
 
-    public void visitAsGroup(Element el)
-    {
-        boolean needBraces = ! ( ( el instanceof ElementGroup ) || ( el instanceof ElementSubQuery ) ) ; 
-        
-        if ( needBraces )
-        {
+    public void visitAsGroup(Element el) {
+        boolean needBraces = !((el instanceof ElementGroup) || (el instanceof ElementSubQuery)) ;
+
+        if ( needBraces ) {
             out.print("{ ") ;
             out.incIndent(INDENT) ;
         }
-        
+
         el.visit(this) ;
-        
-        if ( needBraces )
-        {
+
+        if ( needBraces ) {
             out.decIndent(INDENT) ;
             out.print("}") ;
         }
     }
 
-    // Work variables.
-    // Assumes not threaded
-    
     int subjectWidth = -1 ;
     int predicateWidth = -1 ;
     
     @Override
-    protected void formatTriples(BasicPattern triples)
-    {
-        if ( ! PRETTY_PRINT )
-        {
+    protected void formatTriples(BasicPattern triples) {
+        if ( !PRETTY_PRINT ) {
             super.formatTriples(triples) ;
             return ;
         }
-        
-        // TODO RDF Collections - spot the parsers pattern 
+
+        // TODO RDF Collections - spot the parsers pattern
         if ( triples.isEmpty() )
             return ;
 
@@ -496,25 +449,23 @@ public class FormatterElement extends FormatterBase
             subjectWidth = TRIPLES_SUBJECT_COLUMN ;
         if ( predicateWidth > TRIPLES_PROPERTY_COLUMN )
             predicateWidth = TRIPLES_PROPERTY_COLUMN ;
-        
+
         // Loops:
-        List<Triple> subjAcc = new ArrayList<>() ;    // Accumulate all triples with the same subject.
-        Node subj = null ;                  // Subject being accumulated
-        
-        boolean first = true ;             // Print newlines between blocks.
-        
+        List<Triple> subjAcc = new ArrayList<>() ; // Accumulate all triples
+                                                   // with the same subject.
+        Node subj = null ; // Subject being accumulated
+
+        boolean first = true ; // Print newlines between blocks.
+
         int indent = -1 ;
-        for ( Triple t : triples )
-        {
-            if ( subj != null && t.getSubject().equals(subj) )
-            {
+        for ( Triple t : triples ) {
+            if ( subj != null && t.getSubject().equals(subj) ) {
                 subjAcc.add(t) ;
                 continue ;
             }
-            
-            if ( subj != null )
-            {
-                if ( ! first )
+
+            if ( subj != null ) {
+                if ( !first )
                     out.println(" .") ;
                 formatSameSubject(subj, subjAcc) ;
                 first = false ;
@@ -527,19 +478,17 @@ public class FormatterElement extends FormatterBase
             subjAcc.clear() ;
             subjAcc.add(t) ;
         }
-        
+
         // Flush accumulator
-        if ( subj != null && subjAcc.size() != 0 )
-        {
-            if ( ! first )
+        if ( subj != null && subjAcc.size() != 0 ) {
+            if ( !first )
                 out.println(" .") ;
             first = false ;
             formatSameSubject(subj, subjAcc) ;
         }
     }
-    
-    private void formatSameSubject(Node subject, List<Triple> triples)
-    {
+
+    private void formatSameSubject(Node subject, List<Triple> triples) {
         if ( triples == null || triples.size() == 0 )
             return ;
         
@@ -555,14 +504,11 @@ public class FormatterElement extends FormatterBase
         int indent = subjectWidth + TRIPLES_COLUMN_GAP ;
         int s1_len = printSubject(t1.getSubject()) ;
 
-        if ( s1_len > TRIPLES_SUBJECT_LONG )
-        {
+        if ( s1_len > TRIPLES_SUBJECT_LONG ) {
             // Too long - start a new line.
             out.incIndent(indent) ;
             out.println() ;
-        }
-        else
-        {
+        } else {
             printGap() ;
             out.incIndent(indent) ;
         }
@@ -571,11 +517,10 @@ public class FormatterElement extends FormatterBase
         printProperty(t1.getPredicate()) ;
         printGap() ;
         printObject(t1.getObject()) ;
-        
+
         // Do the rest
-        
-        for (  ; iter.hasNext() ; )
-        {
+
+        for ( ; iter.hasNext() ; ) {
             Triple t = iter.next() ;
             out.println(" ;") ;
             printProperty(t.getPredicate()) ;
@@ -587,65 +532,57 @@ public class FormatterElement extends FormatterBase
 
         // Finish off the block.
         out.decIndent(indent) ;
-        //out.print(" .") ;
+        // out.print(" .") ;
     }
-    
-    private void setWidths(BasicPattern triples)
-    {
+
+    private void setWidths(BasicPattern triples) {
         subjectWidth = -1 ;
         predicateWidth = -1 ;
 
-        for ( Triple t : triples )
-        {
+        for ( Triple t : triples ) {
             String s = slotToString(t.getSubject()) ;
             if ( s.length() > subjectWidth )
                 subjectWidth = s.length() ;
-            
+
             String p = slotToString(t.getPredicate()) ;
             if ( p.length() > predicateWidth )
                 predicateWidth = p.length() ;
         }
     }
-    
-    private void printGap()
-    {
+
+    private void printGap() {
         out.print(' ', TRIPLES_COLUMN_GAP) ;
     }
-    
+
     // Indent must be set first.
-    private int printSubject(Node s)
-    {
+    private int printSubject(Node s) {
         String str = slotToString(s) ;
         out.print(str) ;
         out.pad(subjectWidth) ;
-        return str.length() ; 
+        return str.length() ;
     }
 
     // Assumes the indent is TRIPLES_SUBJECT_COLUMN+GAP
     private static String RDFTYPE = FmtUtils.stringForNode(RDF.Nodes.type, new SerializationContext()) ;
     
-    private int printProperty(Node p)
-    {
+    private int printProperty(Node p) {
         String str = slotToString(p) ;
         if ( p.equals(RDF.Nodes.type) && str.equals(RDFTYPE) )
             out.print("a") ;
         else
             out.print(str) ;
         out.pad(predicateWidth) ;
-        return str.length() ; 
+        return str.length() ;
     }
-    
-    private int printObject(Node obj)
-    {
+
+    private int printObject(Node obj) {
         return printNoCol(obj) ;
     }
-    
-    private int printNoCol(Node node)
-    {
-        String str = slotToString(node) ; 
+
+    private int printNoCol(Node node) {
+        String str = slotToString(node) ;
         out.print(str) ;
         return str.length() ;
-        
+
     }
-    
 }


[2/5] jena git commit: Cleaning.

Posted by an...@apache.org.
Cleaning.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/d306f539
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/d306f539
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/d306f539

Branch: refs/heads/master
Commit: d306f539dd981135e7474790475db74d644a13b1
Parents: 5104432
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Jul 13 21:47:54 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Jul 13 21:47:54 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/jena/sparql/algebra/OpAsQuery.java    | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/d306f539/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
index 85ca6d1..b23b39c 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
@@ -338,9 +338,11 @@ public class OpAsQuery {
         private static Expr rewrite(Expr expr, ExprTransform transform) {
             return ExprTransformer.transform(transform, expr) ;
         }
-
         
-        // processQueryPattern : query.setQueryPattern
+        /**
+         * Process for a single pattern below the modifiers.
+         * Cleans up the ElementGroup produced.
+         */
         
         private void processQueryPattern(QueryLevelDetails level) {
             Op op = level.pattern ;
@@ -379,14 +381,14 @@ public class OpAsQuery {
             return el2 ;
         }
         
-        Element asElement(Op op) {
+        private Element asElement(Op op) {
             ElementGroup g = asElementGroup(op) ;
             if ( g.size() == 1 )
                 return g.get(0) ;
             return g ;
         }
 
-        ElementGroup asElementGroup(Op op) {
+        private ElementGroup asElementGroup(Op op) {
             startSubGroup() ;
             op.visit(this) ;
             return endSubGroup() ;