This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit c05656287afb9e1cc8d438459c112b7c91d0da46 Author: Andy Seaborne <[email protected]> AuthorDate: Mon Nov 11 15:23:16 2024 +0000 Internal tidy-up of RowSet --- .../org/apache/jena/sparql/exec/RowSetMem.java | 52 ++++++++-------------- .../org/apache/jena/sparql/exec/RowSetOps.java | 28 ++---------- 2 files changed, 22 insertions(+), 58 deletions(-) diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetMem.java b/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetMem.java index b30591e27c..81fdb73b2d 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetMem.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetMem.java @@ -49,26 +49,9 @@ public class RowSetMem implements RowSetRewindable * @param other The other RowSetMem object */ private RowSetMem(RowSetMem other) { - // Should be no need to isolate the rows list. - this(other, false); - } - - /** - * Create an in-memory result set from another one - * - * @param other - * The other ResultSetMem object - * @param takeCopy - * Should we copy the rows? - */ - - private RowSetMem(RowSetMem other, boolean takeCopy) { vars = other.vars; - if ( takeCopy ) - rows = new ArrayList<>(other.rows); - else - // Share results (not the iterator). - rows = other.rows; + // Share results (not the iterator). + rows = other.rows; reset(); } @@ -80,21 +63,26 @@ public class RowSetMem implements RowSetRewindable */ private RowSetMem(RowSet other) { - this.rows = new ArrayList<>(); - other.forEachRemaining(rows::add); + if ( other instanceof RowSetMem rsm ) { + // See also the RowSetMem(RowSetMem) constructor. + // This code is in case there wasn't compile time type information available. + rows = rsm.rows; + vars = rsm.getResultVars(); + return; + } + // Copy necessary. + List<Binding> arr = new ArrayList<>(); + other.forEachRemaining(arr::add); + this.rows = arr; this.vars = other.getResultVars(); reset(); } - /** - * Is there another possibility? - */ + /** Is there another row? */ @Override public boolean hasNext() { return iterator.hasNext() ; } - /** - * Moves onto the next result possibility. - */ + /** Moves onto the next result possibility. */ @Override public Binding next() { rowNumber++ ; return iterator.next() ; } @@ -109,19 +97,15 @@ public class RowSetMem implements RowSetRewindable rowNumber = 0; } - /** Return the "row" number for the current iterator item - */ + /** Return the "row" number for the current iterator item */ @Override public long getRowNumber() { return rowNumber ; } - /** - * Return the number of rows - */ + /** Return the number of rows (not the number remaining in an iterator) */ @Override public long size() { return rows.size() ; } - /** Get the variable names for the projection - */ + /** Get the variable names for the projection */ @Override public List<Var> getResultVars() { return vars ; } diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetOps.java b/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetOps.java index 0328b412a3..8a4dad0765 100644 --- a/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetOps.java +++ b/jena-arq/src/main/java/org/apache/jena/sparql/exec/RowSetOps.java @@ -19,11 +19,8 @@ package org.apache.jena.sparql.exec; import java.io.OutputStream; -import java.util.Iterator; -import org.apache.jena.query.QuerySolution; import org.apache.jena.query.ResultSet; -import org.apache.jena.rdf.model.RDFNode; import org.apache.jena.riot.ResultSetMgr; import org.apache.jena.riot.resultset.ResultSetLang; import org.apache.jena.riot.system.PrefixMap; @@ -33,9 +30,10 @@ import org.apache.jena.sparql.ARQConstants; import org.apache.jena.sparql.core.Prologue; import org.apache.jena.sparql.resultset.ResultsWriter; -/** RowSetFormatter - Convenience ways to call the various output formatters. - * in various formats. - * @see ResultSetMgr +/** + * RowSetOps - Convenience ways to call the various output formatters. + * + * @see ResultSetMgr */ public class RowSetOps { @@ -131,22 +129,4 @@ public class RowSetOps { public static void out(OutputStream out, boolean answer) { ResultsWriter.create().lang(ResultSetLang.RS_Text).write(out, answer); } - - /** Touch every var/value */ - private static void materialize(QuerySolution qs) { - for ( Iterator<String> iter = qs.varNames(); iter.hasNext(); ) { - String vn = iter.next(); - RDFNode n = qs.get(vn); - } - } - -// public static long count(RowSet rowSet) { -// return Iter.count(rowSet); -// } - - // ---- SSE - - - // ---- CSV - }
