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 2024/12/31 10:27:41 UTC
(jena) branch main updated (66fefd47bf -> bc4f44045c)
This is an automated email from the ASF dual-hosted git repository.
andy pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
from 66fefd47bf GH-2908: Adjust for T24:00:00 in xsd:dateTime
new 42ae21228f Don't include the default/only charset
new b00841e72b Rename Responses.doResponseBoolean; code tidy
new 9e0015085e Close iterator
new 0a07f63e6b JenaSystem.init with optional tracing
new bc4f44045c Tidy NodeValue subclasses
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../jena/sparql/expr/nodevalue/NodeFunctions.java | 244 +++---
.../sparql/expr/nodevalue/NodeValueBoolean.java | 24 +-
.../sparql/expr/nodevalue/NodeValueDateTime.java | 45 +-
.../sparql/expr/nodevalue/NodeValueDuration.java | 26 +-
.../sparql/expr/nodevalue/NodeValueInteger.java | 52 +-
.../jena/sparql/expr/nodevalue/NodeValueLang.java | 38 +-
.../jena/sparql/expr/nodevalue/NodeValueNode.java | 10 +-
.../sparql/expr/nodevalue/NodeValueSortKey.java | 4 +-
.../sparql/expr/nodevalue/NodeValueString.java | 44 +-
.../sparql/expr/nodevalue/NodeValueVisitor.java | 36 +-
.../jena/sparql/expr/nodevalue/XSDDuration.java | 2 +-
.../jena/sparql/expr/nodevalue/XSDFuncOp.java | 957 ++++++++++-----------
.../jena/sparql/modify/UpdateEngineWorker.java | 27 +-
.../main/java/org/apache/jena/sys/JenaSystem.java | 44 +-
.../jena/fuseki/servlets/ResponseResultSet.java | 2 +-
.../org/apache/jena/fuseki/servlets/Responses.java | 48 +-
.../jena/fuseki/servlets/SPARQLQueryProcessor.java | 2 +-
.../org/apache/jena/fuseki/main/sys/JettyLib.java | 4 +-
18 files changed, 815 insertions(+), 794 deletions(-)
(jena) 03/05: Close iterator
Posted by an...@apache.org.
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 9e0015085e84c6fc2eb6bec3bfb9f62809ab2b98
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Wed Nov 27 17:56:47 2024 +0000
Close iterator
---
.../jena/sparql/modify/UpdateEngineWorker.java | 27 +++++++++++-----------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java
index 40a443bba7..c8c8930638 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/modify/UpdateEngineWorker.java
@@ -405,20 +405,21 @@ public class UpdateEngineWorker implements UpdateVisitor
try {
Iterator<Binding> bindings = evalBindings(query, dsg, inputBinding, context);
- if ( false ) {
- List<Binding> x = Iter.toList(bindings);
- System.out.printf("====>> Bindings (%d)\n", x.size());
- //Iter.print(System.out, x.iterator());
- // More readable.
- List<Var> vars = Var.varList(query.getResultVars());
- RowSet rs = RowSetStream.create(vars, x.iterator());
- PrefixMap pmap = datasetGraph.prefixes();
- RowSetOps.out(System.out, rs, datasetGraph.prefixes());
- System.out.println("====<<");
- bindings = Iter.iter(x);
+ try {
+ if ( false ) {
+ List<Binding> x = Iter.toList(bindings);
+ System.out.printf("====>> Bindings (%d)\n", x.size());
+ List<Var> vars = Var.varList(query.getResultVars());
+ RowSet rs = RowSetStream.create(vars, x.iterator());
+ PrefixMap pmap = datasetGraph.prefixes();
+ RowSetOps.out(System.out, rs, datasetGraph.prefixes());
+ System.out.println("====<<");
+ bindings = Iter.iter(x);
+ }
+ db.addAll(bindings);
+ } finally {
+ Iter.close(bindings);
}
- db.addAll(bindings);
- Iter.close(bindings);
Iterator<Binding> it = db.iterator();
execDelete(datasetGraph, update.getDeleteQuads(), withGraph, it);
(jena) 02/05: Rename Responses.doResponseBoolean; code tidy
Posted by an...@apache.org.
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 b00841e72b50061172d653dbe9ee37e7337376c4
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Wed Nov 27 16:49:37 2024 +0000
Rename Responses.doResponseBoolean; code tidy
---
.../jena/fuseki/servlets/ResponseResultSet.java | 2 +-
.../org/apache/jena/fuseki/servlets/Responses.java | 48 ++++++++++++----------
.../jena/fuseki/servlets/SPARQLQueryProcessor.java | 2 +-
3 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java
index 51a51c4dfa..054dde3252 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java
@@ -31,7 +31,7 @@ import org.apache.jena.sparql.exec.RowSet;
public class ResponseResultSet
{
public static void doResponseResultSet(HttpAction action, Boolean booleanResult) {
- Responses.doResponseResultSet(action, booleanResult);
+ Responses.doResponseBoolean(action, booleanResult);
}
public static void doResponseResultSet(HttpAction action, ResultSet resultSet, Prologue qPrologue) {
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/Responses.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/Responses.java
index a0943fdb6f..018a6290a0 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/Responses.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/Responses.java
@@ -149,7 +149,7 @@ public class Responses
// Jetty closes the stream if it is a gzip stream.
}
- public static void doResponseResultSet(HttpAction action, Boolean booleanResult) {
+ public static void doResponseBoolean(HttpAction action, Boolean booleanResult) {
ResponseResults.doResponseResultSet$(action, null, booleanResult, null, DEF.rsOfferBoolean);
}
@@ -231,23 +231,28 @@ public class Responses
String charset = charsetUTF8;
String jsonCallback = null;
- if ( Objects.equals(serializationType, contentTypeResultsXML) ) {
- charset = null;
- if ( stylesheetURL != null )
- cxt.set(RowSetWriterXML.xmlStylesheet, stylesheetURL);
- }
- if ( Objects.equals(serializationType, contentTypeResultsJSON) ) {
- jsonCallback = paramCallback(action.getRequest());
- }
- if (Objects.equals(serializationType, WebContent.contentTypeResultsThrift) ) {
- if ( booleanResult != null )
- ServletOps.errorBadRequest("Can't write a boolean result in thrift");
- charset = null;
- }
- if (Objects.equals(serializationType, WebContent.contentTypeResultsProtobuf) ) {
- if ( booleanResult != null )
- ServletOps.errorBadRequest("Can't write a boolean result in protobuf");
- charset = null;
+ switch(serializationType) {
+ case contentTypeResultsXML-> {
+ // XML controls the character set
+ charset = null;
+ if ( stylesheetURL != null )
+ cxt.set(RowSetWriterXML.xmlStylesheet, stylesheetURL);
+ }
+ case contentTypeResultsJSON -> {
+ // JSON is always UTF-8.
+ // charset = null;
+ jsonCallback = paramCallback(action.getRequest());
+ }
+ case contentTypeResultsThrift -> {
+ if ( booleanResult != null )
+ ServletOps.errorBadRequest("Can't write a boolean result in thrift");
+ charset = null;
+ }
+ case contentTypeResultsProtobuf -> {
+ if ( booleanResult != null )
+ ServletOps.errorBadRequest("Can't write a boolean result in protobuf");
+ charset = null;
+ }
}
// Finally, the general case
@@ -509,12 +514,13 @@ public class Responses
// Stop caching (not that ?queryString URLs are cached anyway)
if ( true )
ServletOps.setNoCache(action);
- // See: http://www.w3.org/International/O-HTTP-charset.html
if ( contentType != null ) {
- if ( charset != null && !isXML(contentType) )
+ if ( charset != null && !isXML(contentType) ) {
+ // Doing it ourselves means it is logged for "verbose"
contentType = contentType + "; charset=" + charset;
- action.log.trace("Content-Type for response: " + contentType);
+ }
action.setResponseContentType(contentType);
+ action.log.trace("Content-Type for response: " + contentType);
}
}
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java
index b9600b03ad..6d527f18ee 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/SPARQLQueryProcessor.java
@@ -440,7 +440,7 @@ public abstract class SPARQLQueryProcessor extends ActionService
// DESCRIBE results are graphs
Responses.doResponseGraph(action, result.graph());
else if ( result.isBoolean() )
- Responses.doResponseResultSet(action, result.booleanResult());
+ Responses.doResponseBoolean(action, result.booleanResult());
else if ( result.isJson() )
Responses.doResponseJson(action, result.jsonItems());
else
(jena) 01/05: Don't include the default/only charset
Posted by an...@apache.org.
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 42ae21228f3954366be5e71d68635e86e4f2402a
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Wed Nov 27 16:48:55 2024 +0000
Don't include the default/only charset
---
.../src/main/java/org/apache/jena/fuseki/main/sys/JettyLib.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/sys/JettyLib.java b/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/sys/JettyLib.java
index 0ffc137899..7c5db7a016 100644
--- a/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/sys/JettyLib.java
+++ b/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/sys/JettyLib.java
@@ -62,8 +62,8 @@ public class JettyLib {
// RDF syntax
mimeTypes.addMimeMapping("nt", WebContent.contentTypeNTriples);
mimeTypes.addMimeMapping("nq", WebContent.contentTypeNQuads);
- mimeTypes.addMimeMapping("ttl", WebContent.contentTypeTurtle+";charset=utf-8");
- mimeTypes.addMimeMapping("trig", WebContent.contentTypeTriG+";charset=utf-8");
+ mimeTypes.addMimeMapping("ttl", WebContent.contentTypeTurtle);
+ mimeTypes.addMimeMapping("trig", WebContent.contentTypeTriG);
mimeTypes.addMimeMapping("rdf", WebContent.contentTypeRDFXML);
mimeTypes.addMimeMapping("jsonld", WebContent.contentTypeJSONLD);
mimeTypes.addMimeMapping("rj", WebContent.contentTypeRDFJSON);
(jena) 05/05: Tidy NodeValue subclasses
Posted by an...@apache.org.
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 bc4f44045c9c6b18cd8a8f3c829488f4491accfa
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Sun Dec 29 10:34:14 2024 +0000
Tidy NodeValue subclasses
---
.../jena/sparql/expr/nodevalue/NodeFunctions.java | 244 +++---
.../sparql/expr/nodevalue/NodeValueBoolean.java | 24 +-
.../sparql/expr/nodevalue/NodeValueDateTime.java | 45 +-
.../sparql/expr/nodevalue/NodeValueDuration.java | 26 +-
.../sparql/expr/nodevalue/NodeValueInteger.java | 52 +-
.../jena/sparql/expr/nodevalue/NodeValueLang.java | 38 +-
.../jena/sparql/expr/nodevalue/NodeValueNode.java | 10 +-
.../sparql/expr/nodevalue/NodeValueSortKey.java | 4 +-
.../sparql/expr/nodevalue/NodeValueString.java | 44 +-
.../sparql/expr/nodevalue/NodeValueVisitor.java | 36 +-
.../jena/sparql/expr/nodevalue/XSDDuration.java | 2 +-
.../jena/sparql/expr/nodevalue/XSDFuncOp.java | 957 ++++++++++-----------
12 files changed, 739 insertions(+), 743 deletions(-)
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java
index 4f015eb903..190938d698 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java
@@ -16,22 +16,22 @@
* limitations under the License.
*/
-package org.apache.jena.sparql.expr.nodevalue ;
+package org.apache.jena.sparql.expr.nodevalue;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.UUID ;
+import java.util.UUID;
import java.util.function.Function;
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeConstants.Field;
import javax.xml.datatype.Duration;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
import org.apache.jena.graph.Triple;
import org.apache.jena.irix.IRIException;
import org.apache.jena.irix.IRIs;
@@ -40,13 +40,13 @@ import org.apache.jena.query.ARQ;
import org.apache.jena.rdf.model.impl.Util;
import org.apache.jena.riot.out.NodeFmtLib;
import org.apache.jena.riot.system.RiotLib;
-import org.apache.jena.sparql.expr.ExprEvalException ;
-import org.apache.jena.sparql.expr.ExprTypeException ;
-import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.graph.NodeConst ;
-import org.apache.jena.sparql.util.FmtUtils ;
-import org.apache.jena.sparql.util.NodeUtils ;
-import org.apache.jena.vocabulary.XSD ;
+import org.apache.jena.sparql.expr.ExprEvalException;
+import org.apache.jena.sparql.expr.ExprTypeException;
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.graph.NodeConst;
+import org.apache.jena.sparql.util.FmtUtils;
+import org.apache.jena.sparql.util.NodeUtils;
+import org.apache.jena.vocabulary.XSD;
/**
* Implementation of node-centric functions.
@@ -58,21 +58,21 @@ public class NodeFunctions {
* tag or an XSD string).
*/
public static Node checkAndGetStringLiteral(String label, NodeValue nv) {
- Node n = nv.asNode() ;
+ Node n = nv.asNode();
if ( !n.isLiteral() )
- throw new ExprEvalException(label + ": Not a literal: " + nv) ;
- String lang = n.getLiteralLanguage() ;
+ throw new ExprEvalException(label + ": Not a literal: " + nv);
+ String lang = n.getLiteralLanguage();
if ( NodeUtils.isLangString(n) )
// Language tag. Legal.
- return n ;
+ return n;
// No language tag : either no datatype or a datatype of xsd:string
// Includes the case of rdf:langString and no language ==> Illegal as a compatible string.
if ( nv.isString() )
- return n ;
- throw new ExprEvalException(label + ": Not a string literal: " + nv) ;
+ return n;
+ throw new ExprEvalException(label + ": Not a string literal: " + nv);
}
/**
@@ -93,43 +93,43 @@ public class NodeFunctions {
* The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
*/
- Node n1 = checkAndGetStringLiteral(label, arg1) ;
- Node n2 = checkAndGetStringLiteral(label, arg2) ;
- String lang1 = n1.getLiteralLanguage() ;
- String lang2 = n2.getLiteralLanguage() ;
+ Node n1 = checkAndGetStringLiteral(label, arg1);
+ Node n2 = checkAndGetStringLiteral(label, arg2);
+ String lang1 = n1.getLiteralLanguage();
+ String lang2 = n2.getLiteralLanguage();
if ( lang1 == null )
- lang1 = "" ;
+ lang1 = "";
if ( lang2 == null )
- lang2 = "" ;
+ lang2 = "";
// Case 1
if ( lang1.equals("") ) {
if ( lang2.equals("") )
- return ;
- throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2) ;
+ return;
+ throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2);
}
// Case 2
if ( lang1.equalsIgnoreCase(lang2) )
- return ;
+ return;
// Case 3
if ( lang2.equals("") )
- return ;
+ return;
- throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2) ;
+ throw new ExprEvalException(label + ": Incompatible: " + arg1 + " and " + arg2);
}
// -------- sameTerm
public static NodeValue sameTerm(NodeValue nv1, NodeValue nv2) {
- return NodeValue.booleanReturn(sameTerm(nv1.asNode(), nv2.asNode())) ;
+ return NodeValue.booleanReturn(sameTerm(nv1.asNode(), nv2.asNode()));
}
/** sameTerm(x,y) */
public static boolean sameTerm(Node node1, Node node2) {
if ( node1.equals(node2) )
- return true ;
+ return true;
if ( Util.isLangString(node1) && Util.isLangString(node2) ) {
String lex1 = node1.getLiteralLexicalForm();
String lex2 = node2.getLiteralLexicalForm();
@@ -140,7 +140,7 @@ public class NodeFunctions {
if ( node1.isNodeTriple() && node2.isNodeTriple() ) {
return sameTriples(node1.getTriple(), node2.getTriple());
}
- return false ;
+ return false;
}
private static boolean sameTriples(Triple t1, Triple t2) {
@@ -156,18 +156,18 @@ public class NodeFunctions {
// Exception for two literals that might be equal but we don't know because of language tags.
public static boolean rdfTermEquals(Node n1, Node n2) {
if ( n1.equals(n2) )
- return true ;
+ return true;
if ( n1.isLiteral() && n2.isLiteral() ) {
// Two literals, may be sameTerm by language tag case insensitivity.
- String lang1 = n1.getLiteralLanguage() ;
- String lang2 = n2.getLiteralLanguage() ;
+ String lang1 = n1.getLiteralLanguage();
+ String lang2 = n2.getLiteralLanguage();
if ( isNotEmpty(lang1) && isNotEmpty(lang2) ) {
// Two language tags, both not "", equal by case insensitivity => lexical test.
if ( lang1.equalsIgnoreCase(lang2) ) {
- boolean b = n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm()) ;
+ boolean b = n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm());
if ( b )
- return true ;
+ return true;
}
}
@@ -176,7 +176,7 @@ public class NodeFunctions {
// case 1: At least one language tag., not same lexical form -> unknown.
// case 2: No language tags, not .equals -> unknown.
// Raise error (rather than return false).
- NodeValue.raise(new ExprEvalException("Mismatch in RDFterm-equals: " + n1 + ", " + n2)) ;
+ NodeValue.raise(new ExprEvalException("Mismatch in RDFterm-equals: " + n1 + ", " + n2));
}
if ( n1.isNodeTriple() && n2.isNodeTriple() ) {
@@ -188,19 +188,19 @@ public class NodeFunctions {
}
// Not both literal nor both triple terms - .equals would have worked.
- return false ;
+ return false;
}
// -------- str
public static NodeValue str(NodeValue nv) {
- return NodeValue.makeString(str(nv.asNode())) ;
+ return NodeValue.makeString(str(nv.asNode()));
}
public static String str(Node node) {
if ( node.isLiteral() )
- return node.getLiteral().getLexicalForm() ;
+ return node.getLiteral().getLexicalForm();
if ( node.isURI() )
- return node.getURI() ;
+ return node.getURI();
if ( node.isBlank() && ! ARQ.isTrue(ARQ.strictSPARQL) )
return RiotLib.blankNodeToIriString(node);
if ( node.isNodeTriple() && ! ARQ.isTrue(ARQ.strictSPARQL) ) {
@@ -210,61 +210,61 @@ public class NodeFunctions {
return "<< " + f.apply(t.getSubject()) + " " + f.apply(t.getPredicate()) + " " + f.apply(t.getObject()) + " >>";
}
if ( node.isBlank() )
- NodeValue.raise(new ExprEvalException("Blank node: " + node)) ;
+ NodeValue.raise(new ExprEvalException("Blank node: " + node));
if ( node.isNodeTriple())
- NodeValue.raise(new ExprEvalException("Quoted triple: " + node)) ;
- NodeValue.raise(new ExprEvalException("Not valid for STR(): " + node)) ;
- return "[undef]" ;
+ NodeValue.raise(new ExprEvalException("Quoted triple: " + node));
+ NodeValue.raise(new ExprEvalException("Not valid for STR(): " + node));
+ return "[undef]";
}
// -------- sort key (collation)
public static NodeValue sortKey(NodeValue nv, String collation) {
- return NodeValue.makeSortKey(str(nv.asNode()), collation) ;
+ return NodeValue.makeSortKey(str(nv.asNode()), collation);
}
// -------- datatype
public static NodeValue datatype(NodeValue nv) {
- return NodeValue.makeNode(datatype(nv.asNode())) ;
+ return NodeValue.makeNode(datatype(nv.asNode()));
}
public static Node datatype(Node node) {
if ( !node.isLiteral() ) {
- NodeValue.raise(new ExprTypeException("datatype: Not a literal: " + node)) ;
- return null ;
+ NodeValue.raise(new ExprTypeException("datatype: Not a literal: " + node));
+ return null;
}
- String s = node.getLiteralDatatypeURI() ;
- boolean plainLiteral = (s == null || s.equals("")) ;
+ String s = node.getLiteralDatatypeURI();
+ boolean plainLiteral = (s == null || s.equals(""));
if ( plainLiteral ) {
- boolean simpleLiteral = (node.getLiteralLanguage() == null || node.getLiteralLanguage().equals("")) ;
+ boolean simpleLiteral = (node.getLiteralLanguage() == null || node.getLiteralLanguage().equals(""));
if ( !simpleLiteral )
- return NodeConst.rdfLangString ;
- return XSD.xstring.asNode() ;
+ return NodeConst.rdfLangString;
+ return XSD.xstring.asNode();
}
- return NodeFactory.createURI(s) ;
+ return NodeFactory.createURI(s);
}
// -------- lang
public static NodeValue lang(NodeValue nv) {
if ( nv.isLangString() )
- return NodeValue.makeString(nv.getLang()) ;
+ return NodeValue.makeString(nv.getLang());
if ( nv.isLiteral() )
- return NodeValue.nvEmptyString ;
- NodeValue.raise(new ExprTypeException("lang: Not a literal: " + nv.asQuotedString())) ;
- return null ;
+ return NodeValue.nvEmptyString;
+ NodeValue.raise(new ExprTypeException("lang: Not a literal: " + nv.asQuotedString()));
+ return null;
}
public static String lang(Node node) {
if ( !node.isLiteral() )
- NodeValue.raise(new ExprTypeException("lang: Not a literal: " + FmtUtils.stringForNode(node))) ;
+ NodeValue.raise(new ExprTypeException("lang: Not a literal: " + FmtUtils.stringForNode(node)));
- String s = node.getLiteralLanguage() ;
+ String s = node.getLiteralLanguage();
if ( s == null )
- s = "" ;
- return s ;
+ s = "";
+ return s;
}
// -------- langMatches
@@ -275,7 +275,7 @@ public class NodeFunctions {
* @return Boolean nodeValue
*/
public static NodeValue langMatches(NodeValue nv, NodeValue nvPattern) {
- return langMatches(nv, nvPattern.getString()) ;
+ return langMatches(nv, nvPattern.getString());
}
/** LANGMATCHES
@@ -285,13 +285,13 @@ public class NodeFunctions {
* @return Boolean nodeValue
*/
public static NodeValue langMatches(NodeValue nv, String langPattern) {
- Node node = nv.asNode() ;
+ Node node = nv.asNode();
if ( !node.isLiteral() ) {
- NodeValue.raise(new ExprTypeException("langMatches: not a literal: " + node)) ;
- return null ;
+ NodeValue.raise(new ExprTypeException("langMatches: not a literal: " + node));
+ return null;
}
- String langStr = node.getLiteralLexicalForm() ;
+ String langStr = node.getLiteralLexicalForm();
return NodeValue.booleanReturn(langMatches(langStr, langPattern));
}
@@ -318,8 +318,8 @@ public class NodeFunctions {
if ( langPattern.equals("*") ) {
// Not a legal lang string.
if ( langStr == null || langStr.equals("") )
- return false ;
- return true ;
+ return false;
+ return true;
}
// Basic Language Range
@@ -330,8 +330,8 @@ public class NodeFunctions {
// extended-language-range = (1*8ALPHA / "*")
// *("-" (1*8alphanum / "*"))
- String[] langElts = langStr.split("-") ;
- String[] langRangeElts = langPattern.split("-") ;
+ String[] langElts = langStr.split("-");
+ String[] langRangeElts = langPattern.split("-");
/*
* Here is the logic to compare language code. There is a match if the
@@ -349,88 +349,88 @@ public class NodeFunctions {
*/
if ( langRangeElts.length > langElts.length )
// Lang tag longer than pattern tag => can't match
- return false ;
- for ( int i = 0 ; i < langRangeElts.length ; i++ ) {
- String range = langRangeElts[i] ;
+ return false;
+ for ( int i = 0; i < langRangeElts.length; i++ ) {
+ String range = langRangeElts[i];
if ( range == null )
- break ;
+ break;
// Language longer than range
if ( i >= langElts.length )
- break ;
- String lang = langElts[i] ;
+ break;
+ String lang = langElts[i];
if ( range.equals("*") )
- continue ;
+ continue;
if ( !range.equalsIgnoreCase(lang) )
return false;
}
- return true ;
+ return true;
}
// -------- isURI/isIRI
public static NodeValue isIRI(NodeValue nv) {
- return NodeValue.booleanReturn(isIRI(nv.asNode())) ;
+ return NodeValue.booleanReturn(isIRI(nv.asNode()));
}
public static boolean isIRI(Node node) {
if ( node.isURI() )
- return true ;
- return false ;
+ return true;
+ return false;
}
public static NodeValue isURI(NodeValue nv) {
- return NodeValue.booleanReturn(isIRI(nv.asNode())) ;
+ return NodeValue.booleanReturn(isIRI(nv.asNode()));
}
public static boolean isURI(Node node) {
- return isIRI(node) ;
+ return isIRI(node);
}
// -------- isBlank
public static NodeValue isBlank(NodeValue nv) {
- return NodeValue.booleanReturn(isBlank(nv.asNode())) ;
+ return NodeValue.booleanReturn(isBlank(nv.asNode()));
}
public static boolean isBlank(Node node) {
- return node.isBlank() ;
+ return node.isBlank();
}
// -------- isLiteral
public static NodeValue isLiteral(NodeValue nv) {
- return NodeValue.booleanReturn(isLiteral(nv.asNode())) ;
+ return NodeValue.booleanReturn(isLiteral(nv.asNode()));
}
public static boolean isLiteral(Node node) {
- return node.isLiteral() ;
+ return node.isLiteral();
}
/** NodeValue to NodeValue, skolemizing, and converting strings to URIs. */
public static NodeValue iri(NodeValue nv, String baseIRI) {
if ( isIRI(nv.asNode()) )
- return nv ;
- Node n2 = iri(nv.asNode(), baseIRI) ;
- return NodeValue.makeNode(n2) ;
+ return nv;
+ Node n2 = iri(nv.asNode(), baseIRI);
+ return NodeValue.makeNode(n2);
}
/** Node to Node, skolemizing, and converting strings to URIs. */
public static Node iri(Node n, String baseIRI) {
Node node = RiotLib.blankNodeToIri(n);
if ( node.isURI() )
- return node ;
+ return node;
// Literals.
// Simple literal or xsd:string
- String str = simpleLiteralOrXSDString(node) ;
+ String str = simpleLiteralOrXSDString(node);
if ( str == null )
- throw new ExprEvalException("Can't make an IRI from " + node) ;
+ throw new ExprEvalException("Can't make an IRI from " + node);
- String iriStr = node.getLiteralLexicalForm() ;
+ String iriStr = node.getLiteralLexicalForm();
if ( RiotLib.isBNodeIRI(iriStr) ) {
// Jena's "Blank node URI" <_:...>
// Pass through as an IRI.
- return NodeFactory.createURI(iriStr) ;
+ return NodeFactory.createURI(iriStr);
}
String iri = resolveCheckIRI(baseIRI, iriStr);
- return NodeFactory.createURI(iri) ;
+ return NodeFactory.createURI(iri);
}
private static String resolveCheckIRI(String baseIRI, String iriStr) {
@@ -440,67 +440,67 @@ public class NodeFunctions {
return iriStr;
IRIx base = ( baseIRI != null ) ? IRIx.create(baseIRI) : IRIs.getSystemBase();
if ( base.isRelative() /*&& iri.isRelative()*/ )
- throw new ExprEvalException("Relative IRI for base: " + iriStr) ;
+ throw new ExprEvalException("Relative IRI for base: " + iriStr);
IRIx result = base.resolve(iri);
if ( ! result.isReference() )
throw new IRIException("Not suitable: "+result.str());
return result.str();
} catch (IRIException ex) {
- throw new ExprEvalException("Bad IRI: " + iriStr) ;
+ throw new ExprEvalException("Bad IRI: " + iriStr);
}
}
public static NodeValue struuid() {
- return NodeValue.makeString(uuidString()) ;
+ return NodeValue.makeString(uuidString());
}
public static NodeValue uuid() {
- String str = "urn:uuid:" + uuidString() ;
- Node n = NodeFactory.createURI(str) ;
- return NodeValue.makeNode(n) ;
+ String str = "urn:uuid:" + uuidString();
+ Node n = NodeFactory.createURI(str);
+ return NodeValue.makeNode(n);
}
private static String uuidString() {
- return UUID.randomUUID().toString() ;
+ return UUID.randomUUID().toString();
}
private static String simpleLiteralOrXSDString(Node n) {
if ( !n.isLiteral() )
- return null ;
+ return null;
if ( n.getLiteralDatatype() == null ) {
if ( n.getLiteralLanguage().equals("") )
- return n.getLiteralLexicalForm() ;
+ return n.getLiteralLexicalForm();
} else if ( n.getLiteralDatatype().equals(XSDDatatype.XSDstring) )
- return n.getLiteralLexicalForm() ;
- return null ;
+ return n.getLiteralLexicalForm();
+ return null;
}
public static NodeValue strDatatype(NodeValue v1, NodeValue v2) {
if ( !v1.isString() )
- throw new ExprEvalException("Not a string (arg 1): " + v1) ;
+ throw new ExprEvalException("Not a string (arg 1): " + v1);
if ( !v2.isIRI() )
- throw new ExprEvalException("Not an IRI (arg 2): " + v2) ;
+ throw new ExprEvalException("Not an IRI (arg 2): " + v2);
- String lex = v1.asString() ;
- Node dt = v2.asNode() ;
+ String lex = v1.asString();
+ Node dt = v2.asNode();
// Check?
- Node n = NodeFactory.createLiteralDT(lex, NodeFactory.getType(dt.getURI())) ;
- return NodeValue.makeNode(n) ;
+ Node n = NodeFactory.createLiteralDT(lex, NodeFactory.getType(dt.getURI()));
+ return NodeValue.makeNode(n);
}
public static NodeValue strLang(NodeValue v1, NodeValue v2) {
if ( !v1.isString() )
- throw new ExprEvalException("Not a string (arg 1): " + v1) ;
+ throw new ExprEvalException("Not a string (arg 1): " + v1);
if ( !v2.isString() )
- throw new ExprEvalException("Not a string (arg 2): " + v2) ;
+ throw new ExprEvalException("Not a string (arg 2): " + v2);
- String lex = v1.asString() ;
- String lang = v2.asString() ;
+ String lex = v1.asString();
+ String lang = v2.asString();
if ( lang.isEmpty() )
- throw new ExprEvalException("Empty lang tag") ;
- return NodeValue.makeLangString(lex, lang) ;
+ throw new ExprEvalException("Empty lang tag");
+ return NodeValue.makeLangString(lex, lang);
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueBoolean.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueBoolean.java
index c5be4dcca4..85d2b41c0d 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueBoolean.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueBoolean.java
@@ -18,35 +18,35 @@
package org.apache.jena.sparql.expr.nodevalue;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.graph.NodeConst ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.graph.NodeConst;
public class NodeValueBoolean extends NodeValue
{
- boolean bool = false ;
+ boolean bool = false;
- public NodeValueBoolean(boolean b) { super() ; bool = b ; }
- public NodeValueBoolean(boolean b, Node n) { super(n) ; bool = b ; }
+ public NodeValueBoolean(boolean b) { super(); bool = b; }
+ public NodeValueBoolean(boolean b, Node n) { super(n); bool = b; }
@Override
- public boolean isBoolean() { return true ; }
+ public boolean isBoolean() { return true; }
@Override
- public boolean getBoolean() { return bool ; }
+ public boolean getBoolean() { return bool; }
@Override
protected Node makeNode()
- { return bool ? NodeConst.nodeTrue : NodeConst.nodeFalse ; }
+ { return bool ? NodeConst.nodeTrue : NodeConst.nodeFalse; }
@Override
- public String asString() { return toString() ; }
+ public String asString() { return toString(); }
@Override
public String toString()
- { return bool ? "true" : "false" ; }
+ { return bool ? "true" : "false"; }
@Override
- public void visit(NodeValueVisitor visitor) { visitor.visit(this) ; }
+ public void visit(NodeValueVisitor visitor) { visitor.visit(this); }
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDateTime.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDateTime.java
index 923c57fda2..42de6c7172 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDateTime.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDateTime.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -20,31 +20,28 @@ package org.apache.jena.sparql.expr.nodevalue;
import static org.apache.jena.datatypes.xsd.XSDDatatype.*;
-import javax.xml.datatype.XMLGregorianCalendar ;
+import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.jena.datatypes.RDFDatatype;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.sparql.expr.NodeValue;
public class NodeValueDateTime extends NodeValue
{
- final private XMLGregorianCalendar datetime ;
+ final private XMLGregorianCalendar datetime;
/** Lex - caller removes leading and trailing whitespace. */
public static NodeValueDateTime create(String lex, Node n) {
- XMLGregorianCalendar datetime;
- // Java bug : Java6, Java8: gMonth with a timezone of Z causes IllegalArgumentException
- if ( XSDgMonth.equals(n.getLiteralDatatype()) )
- {
- if ( lex.endsWith("Z") )
- {
- lex = lex.substring(0, lex.length()-1) ;
- datetime = NodeValue.xmlDatatypeFactory.newXMLGregorianCalendar(lex) ;
- datetime.setTimezone(0) ;
+ // Java bug : gMonth with a timezone of Z causes IllegalArgumentException
+ if ( XSDgMonth.equals(n.getLiteralDatatype()) ) {
+ if ( lex.endsWith("Z") ) {
+ lex = lex.substring(0, lex.length() - 1);
+ XMLGregorianCalendar datetime = NodeValue.xmlDatatypeFactory.newXMLGregorianCalendar(lex);
+ datetime.setTimezone(0);
return new NodeValueDateTime(datetime, n);
}
}
- datetime = NodeValue.xmlDatatypeFactory.newXMLGregorianCalendar(lex) ;
+ XMLGregorianCalendar datetime = NodeValue.xmlDatatypeFactory.newXMLGregorianCalendar(lex);
return new NodeValueDateTime(datetime, n);
}
@@ -63,19 +60,19 @@ public class NodeValueDateTime extends NodeValue
}
@Override
- public boolean isDate() { return XSDdate.equals(getNode().getLiteralDatatype()) ; }
+ public boolean isDate() { return XSDdate.equals(getNode().getLiteralDatatype()); }
@Override
- public boolean isTime() { return XSDtime.equals(getNode().getLiteralDatatype()) ; }
+ public boolean isTime() { return XSDtime.equals(getNode().getLiteralDatatype()); }
@Override
- public boolean isGYear() { return XSDgYear.equals(getNode().getLiteralDatatype()) ; }
+ public boolean isGYear() { return XSDgYear.equals(getNode().getLiteralDatatype()); }
@Override
- public boolean isGYearMonth() { return XSDgYearMonth.equals(getNode().getLiteralDatatype()) ; }
+ public boolean isGYearMonth() { return XSDgYearMonth.equals(getNode().getLiteralDatatype()); }
@Override
- public boolean isGMonth() { return XSDgMonth.equals(getNode().getLiteralDatatype()) ; }
+ public boolean isGMonth() { return XSDgMonth.equals(getNode().getLiteralDatatype()); }
@Override
- public boolean isGMonthDay() { return XSDgMonthDay.equals(getNode().getLiteralDatatype()) ; }
+ public boolean isGMonthDay() { return XSDgMonthDay.equals(getNode().getLiteralDatatype()); }
@Override
- public boolean isGDay() { return XSDgDay.equals(getNode().getLiteralDatatype()) ; }
+ public boolean isGDay() { return XSDgDay.equals(getNode().getLiteralDatatype()); }
@Override
public XMLGregorianCalendar getDateTime() {
@@ -86,11 +83,11 @@ public class NodeValueDateTime extends NodeValue
@Override
protected Node makeNode()
{
- return null ;
+ return null;
}
@Override
public void visit(NodeValueVisitor visitor)
- { visitor.visit(this) ; }
+ { visitor.visit(this); }
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDuration.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDuration.java
index 9b10917b0c..e64efddaf5 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDuration.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueDuration.java
@@ -18,38 +18,38 @@
package org.apache.jena.sparql.expr.nodevalue;
-import javax.xml.datatype.Duration ;
+import javax.xml.datatype.Duration;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.expr.NodeValue;
/** XSD Duration */
public class NodeValueDuration extends NodeValue
{
- Duration duration ;
+ Duration duration;
public NodeValueDuration(Duration dt)
{
- duration = dt ;
+ duration = dt;
}
- public NodeValueDuration(Duration dt, Node n) { super(n) ; duration = dt ; }
+ public NodeValueDuration(Duration dt, Node n) { super(n); duration = dt; }
@Override
- public boolean isDuration() { return true ; }
+ public boolean isDuration() { return true; }
@Override
- public Duration getDuration() { return duration ; }
+ public Duration getDuration() { return duration; }
@Override
protected Node makeNode()
{
- String lex = duration.toString() ;
- return NodeFactory.createLiteralDT(lex, XSDDatatype.XSDduration) ;
+ String lex = duration.toString();
+ return NodeFactory.createLiteralDT(lex, XSDDatatype.XSDduration);
}
@Override
- public void visit(NodeValueVisitor visitor) { visitor.visit(this) ; }
+ public void visit(NodeValueVisitor visitor) { visitor.visit(this); }
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueInteger.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueInteger.java
index 59ab9d1738..201720c58d 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueInteger.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueInteger.java
@@ -18,62 +18,62 @@
package org.apache.jena.sparql.expr.nodevalue;
-import java.math.BigDecimal ;
-import java.math.BigInteger ;
+import java.math.BigDecimal;
+import java.math.BigInteger;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.expr.NodeValue;
public class NodeValueInteger extends NodeValue
{
- //long integer = Integer.MIN_VALUE ;
+ //long integer = Integer.MIN_VALUE;
// The performance impact of this seems to be very low
// After all, much of the work is pattern matching.
- BigInteger integer ;
+ BigInteger integer;
- public NodeValueInteger(BigInteger i) { super() ; integer = i ; }
- public NodeValueInteger(BigInteger i, Node n) { super(n) ; integer = i ; }
-// public NodeValueInteger(long i, Node n) { super(n) ; integer = new BigInteger(Long.toString(i)) ; }
- public NodeValueInteger(long i) { super() ; integer = new BigInteger(Long.toString(i)) ; }
+ public NodeValueInteger(BigInteger i) { super(); integer = i; }
+ public NodeValueInteger(BigInteger i, Node n) { super(n); integer = i; }
+// public NodeValueInteger(long i, Node n) { super(n); integer = new BigInteger(Long.toString(i)); }
+ public NodeValueInteger(long i) { super(); integer = new BigInteger(Long.toString(i)); }
@Override
- public boolean isNumber() { return true ; }
+ public boolean isNumber() { return true; }
@Override
- public boolean isInteger() { return true ; }
+ public boolean isInteger() { return true; }
@Override
- public boolean isDecimal() { return true ; }
+ public boolean isDecimal() { return true; }
@Override
- public boolean isFloat() { return true ; }
+ public boolean isFloat() { return true; }
@Override
- public boolean isDouble() { return true ; }
+ public boolean isDouble() { return true; }
@Override
- public BigInteger getInteger() { return integer ; }
+ public BigInteger getInteger() { return integer; }
@Override
- public double getDouble() { return integer.doubleValue() ; }
+ public double getDouble() { return integer.doubleValue(); }
@Override
- public float getFloat() { return integer.floatValue() ; }
+ public float getFloat() { return integer.floatValue(); }
@Override
- public BigDecimal getDecimal() { return new BigDecimal(integer) ; }
+ public BigDecimal getDecimal() { return new BigDecimal(integer); }
@Override
protected Node makeNode()
- { return NodeFactory.createLiteralDT(integer.toString(), XSDDatatype.XSDinteger) ; }
+ { return NodeFactory.createLiteralDT(integer.toString(), XSDDatatype.XSDinteger); }
@Override
- public String asString() { return toString() ; }
+ public String asString() { return toString(); }
@Override
public String toString()
{
// Preserve lexical form
- if ( getNode() != null ) return super.asString() ; // str()
- return integer.toString() ;
+ if ( getNode() != null ) return super.asString(); // str()
+ return integer.toString();
}
@Override
- public void visit(NodeValueVisitor visitor) { visitor.visit(this) ; }
+ public void visit(NodeValueVisitor visitor) { visitor.visit(this); }
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueLang.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueLang.java
index ffae70c9f2..306b462b9f 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueLang.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueLang.java
@@ -18,12 +18,12 @@
package org.apache.jena.sparql.expr.nodevalue;
-import java.util.Objects ;
+import java.util.Objects;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.util.FmtUtils ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.util.FmtUtils;
/** A NodeValue that is a lang tagged literal (rdf:langString).
* A string + language tag which is not ""
@@ -33,20 +33,20 @@ public class NodeValueLang extends NodeValue {
// but it get confusing as then it is a NodeValueString
// but isString is false.
- private final String string ;
+ private final String string;
private final String lang;
public NodeValueLang(String lex, String lang) {
- this.string = Objects.requireNonNull(lex) ;
- this.lang = Objects.requireNonNull(lang) ;
+ this.string = Objects.requireNonNull(lex);
+ this.lang = Objects.requireNonNull(lang);
if ( lang.isEmpty() )
- throw new IllegalArgumentException("lang is the empty string") ;
+ throw new IllegalArgumentException("lang is the empty string");
}
public NodeValueLang(Node n) {
- super(Objects.requireNonNull(n)) ;
- this.string = n.getLiteralLexicalForm() ;
- this.lang = n.getLiteralLanguage() ;
+ super(Objects.requireNonNull(n));
+ this.string = n.getLiteralLexicalForm();
+ this.lang = n.getLiteralLanguage();
}
@Override
@@ -55,25 +55,25 @@ public class NodeValueLang extends NodeValue {
}
@Override
- public String getString() { return string ; }
+ public String getString() { return string; }
@Override
- public String getLang() { return lang ; }
+ public String getLang() { return lang; }
@Override
- public String asString() { return string ; }
+ public String asString() { return string; }
@Override
protected Node makeNode()
- { return NodeFactory.createLiteralLang(string, lang) ; }
+ { return NodeFactory.createLiteralLang(string, lang); }
@Override
public String toString() {
if ( getNode() != null )
- return FmtUtils.stringForNode(getNode()) ;
- return "'"+getString()+"'@"+lang ;
+ return FmtUtils.stringForNode(getNode());
+ return "'"+getString()+"'@"+lang ;
}
@Override
- public void visit(NodeValueVisitor visitor) { visitor.visit(this) ; }
+ public void visit(NodeValueVisitor visitor) { visitor.visit(this); }
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueNode.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueNode.java
index 51c105526d..d67c44fbeb 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueNode.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueNode.java
@@ -18,8 +18,8 @@
package org.apache.jena.sparql.expr.nodevalue;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.sparql.expr.NodeValue;
/** A NodeValue that isn't anything else - unrecognized literals, URIs and blank nodes.
@@ -29,12 +29,12 @@ public class NodeValueNode extends NodeValue
{
// ??? subclasses for NodeValueUnknownLiteralType, NodeValueLiteralBadLexicalForm
- public NodeValueNode(Node n) { super(n) ; }
+ public NodeValueNode(Node n) { super(n); }
@Override
protected Node makeNode()
- { return asNode() ; }
+ { return asNode(); }
@Override
- public void visit(NodeValueVisitor visitor) { visitor.visit(this) ; }
+ public void visit(NodeValueVisitor visitor) { visitor.visit(this); }
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueSortKey.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueSortKey.java
index 5e797e2d5f..f0481a7f6b 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueSortKey.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueSortKey.java
@@ -98,7 +98,7 @@ public final class NodeValueSortKey extends NodeValue implements Comparable<Node
public String toString()
{
if (getNode() != null) {
- return FmtUtils.stringForNode(getNode()) ;
+ return FmtUtils.stringForNode(getNode());
}
return "'"+getString()+"'";
}
@@ -111,7 +111,7 @@ public final class NodeValueSortKey extends NodeValue implements Comparable<Node
String c1 = this.getCollation();
String c2 = other.getCollation();
if (c1 == null || c2 == null || ! c1.equals(c2))
- return XSDFuncOp.compareString(this, other) ;
+ return XSDFuncOp.compareString(this, other);
// locales are parsed. Here we could think about caching if necessary
Locale desiredLocale = Locale.forLanguageTag(c1);
// collators are already stored in a concurrent map by the JVM, with <locale, softref<collator>>
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueString.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueString.java
index 2d64c6243d..aa876a73ba 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueString.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueString.java
@@ -18,45 +18,45 @@
package org.apache.jena.sparql.expr.nodevalue;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.sparql.expr.NodeValue ;
-import org.apache.jena.sparql.util.FmtUtils ;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.util.FmtUtils;
public class NodeValueString extends NodeValue
{
// A plain string, with no language tag, or an xsd:string.
-
- private String string ;
-
- public NodeValueString(String str) { string = str ; }
- public NodeValueString(String str, Node n) { super(n) ; string = str ; }
-
+
+ private String string;
+
+ public NodeValueString(String str) { string = str; }
+ public NodeValueString(String str, Node n) { super(n); string = str; }
+
@Override
- public boolean isString() { return true ; }
-
+ public boolean isString() { return true; }
+
@Override
- public String getString() { return string ; }
+ public String getString() { return string; }
@Override
- public String asString() { return string ; }
-
+ public String asString() { return string; }
+
@Override
public String toString()
- {
+ {
if ( getNode() != null )
{
// Can be a plain string or an xsd:string.
- return FmtUtils.stringForNode(getNode()) ;
+ return FmtUtils.stringForNode(getNode());
}
- return '"'+string+'"' ;
+ return '"'+string+'"';
}
-
+
@Override
protected Node makeNode()
- { return NodeFactory.createLiteralString(string) ; }
-
+ { return NodeFactory.createLiteralString(string); }
+
@Override
- public void visit(NodeValueVisitor visitor) { visitor.visit(this) ; }
+ public void visit(NodeValueVisitor visitor) { visitor.visit(this); }
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueVisitor.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueVisitor.java
index c830ffb6ac..d9688b3d41 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueVisitor.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeValueVisitor.java
@@ -20,24 +20,24 @@ package org.apache.jena.sparql.expr.nodevalue;
public interface NodeValueVisitor
{
- public void visit(NodeValueBoolean nv) ;
-// public void visit(NodeValueDate nv) ;
-// public void visit(NodeValueDateTime nv) ;
- public void visit(NodeValueDecimal nv) ;
- public void visit(NodeValueDouble nv) ;
- public void visit(NodeValueFloat nv) ;
- public void visit(NodeValueInteger nv) ;
- public void visit(NodeValueNode nv) ;
- public void visit(NodeValueLang nv) ;
- public void visit(NodeValueString nv) ;
- public void visit(NodeValueSortKey nv) ;
- public void visit(NodeValueDateTime nv) ;
-// public void visit(NodeValueTime nv) ;
+ public void visit(NodeValueBoolean nv);
+// public void visit(NodeValueDate nv);
+// public void visit(NodeValueDateTime nv);
+ public void visit(NodeValueDecimal nv);
+ public void visit(NodeValueDouble nv);
+ public void visit(NodeValueFloat nv);
+ public void visit(NodeValueInteger nv);
+ public void visit(NodeValueNode nv);
+ public void visit(NodeValueLang nv);
+ public void visit(NodeValueString nv);
+ public void visit(NodeValueSortKey nv);
+ public void visit(NodeValueDateTime nv);
+// public void visit(NodeValueTime nv);
public void visit(NodeValueDuration nodeValueDuration);
-// public void visit(NodeValueGYear nv) ;
-// public void visit(NodeValueGYearMonth nv) ;
-// public void visit(NodeValueGMonth nv) ;
-// public void visit(NodeValueGMonthDay nv) ;
-// public void visit(NodeValueGDay nv) ;
+// public void visit(NodeValueGYear nv);
+// public void visit(NodeValueGYearMonth nv);
+// public void visit(NodeValueGMonth nv);
+// public void visit(NodeValueGMonthDay nv);
+// public void visit(NodeValueGDay nv);
}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDDuration.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDDuration.java
index 9b58264ea0..ba59b84e3c 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDDuration.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDDuration.java
@@ -95,7 +95,7 @@ public class XSDDuration {
/** Check whether a duration field is unset or is zero */
private static boolean zeroField(Duration duration, Field field) {
- return ! duration.isSet(field) || duration.getField(field).intValue() == 0 ;
+ return ! duration.isSet(field) || duration.getField(field).intValue() == 0;
}
/**
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java
index 66c1f24c8f..fa049da431 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java
@@ -19,41 +19,41 @@
package org.apache.jena.sparql.expr.nodevalue;
import static javax.xml.datatype.DatatypeConstants.*;
-import static org.apache.jena.sparql.expr.nodevalue.NodeFunctions.checkAndGetStringLiteral ;
-import static org.apache.jena.sparql.expr.nodevalue.NodeFunctions.checkTwoArgumentStringLiterals ;
-import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_DECIMAL ;
-import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_DOUBLE ;
-import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_FLOAT ;
-import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_INTEGER ;
-
-import java.math.BigDecimal ;
-import java.math.BigInteger ;
+import static org.apache.jena.sparql.expr.nodevalue.NodeFunctions.checkAndGetStringLiteral;
+import static org.apache.jena.sparql.expr.nodevalue.NodeFunctions.checkTwoArgumentStringLiterals;
+import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_DECIMAL;
+import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_DOUBLE;
+import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_FLOAT;
+import static org.apache.jena.sparql.expr.nodevalue.NumericType.OP_INTEGER;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
-import java.text.DecimalFormat ;
-import java.text.DecimalFormatSymbols ;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.text.Normalizer;
-import java.text.NumberFormat ;
+import java.text.NumberFormat;
import java.time.ZonedDateTime;
import java.util.*;
-import java.util.regex.Matcher ;
-import java.util.regex.Pattern ;
-
-import javax.xml.datatype.DatatypeConstants ;
-import javax.xml.datatype.Duration ;
-import javax.xml.datatype.XMLGregorianCalendar ;
-
-import org.apache.jena.atlas.lib.IRILib ;
-import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.rdf.model.impl.Util ;
-import org.apache.jena.sparql.ARQInternalErrorException ;
-import org.apache.jena.sparql.SystemARQ ;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.jena.atlas.lib.IRILib;
+import org.apache.jena.atlas.lib.StrUtils;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.rdf.model.impl.Util;
+import org.apache.jena.sparql.ARQInternalErrorException;
+import org.apache.jena.sparql.SystemARQ;
import org.apache.jena.sparql.expr.*;
-import org.apache.jena.sparql.util.DateTimeStruct ;
+import org.apache.jena.sparql.util.DateTimeStruct;
import org.apache.jena.sparql.util.XSDNumUtils;
/**
* Implementation of XQuery/XPath functions and operators.
@@ -66,7 +66,7 @@ public class XSDFuncOp
// The choice of "24" is arbitrary but more than 18 (XSD 1.0) or 16 XSD 1.1) as required by F&O
// F&O 3.1: section 4.2 (end intro)
// https://www.w3.org/TR/xpath-functions/#op.numeric section 4.2
- private static final int DIVIDE_PRECISION = 24 ;
+ private static final int DIVIDE_PRECISION = 24;
// --------------------------------
// Numeric operations
// http://www.w3.org/TR/xpath-functions/#op.numeric
@@ -75,45 +75,45 @@ public class XSDFuncOp
public static NodeValue numAdd(NodeValue nv1, NodeValue nv2) {
switch (classifyNumeric("add", nv1, nv2)) {
case OP_INTEGER :
- return NodeValue.makeInteger(nv1.getInteger().add(nv2.getInteger())) ;
+ return NodeValue.makeInteger(nv1.getInteger().add(nv2.getInteger()));
case OP_DECIMAL :
- return NodeValue.makeDecimal(nv1.getDecimal().add(nv2.getDecimal())) ;
+ return NodeValue.makeDecimal(nv1.getDecimal().add(nv2.getDecimal()));
case OP_FLOAT :
- return NodeValue.makeFloat(nv1.getFloat() + nv2.getFloat()) ;
+ return NodeValue.makeFloat(nv1.getFloat() + nv2.getFloat());
case OP_DOUBLE :
- return NodeValue.makeDouble(nv1.getDouble() + nv2.getDouble()) ;
+ return NodeValue.makeDouble(nv1.getDouble() + nv2.getDouble());
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")") ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")");
}
}
public static NodeValue numSubtract(NodeValue nv1, NodeValue nv2) {
switch (classifyNumeric("subtract", nv1, nv2)) {
case OP_INTEGER :
- return NodeValue.makeInteger(nv1.getInteger().subtract(nv2.getInteger())) ;
+ return NodeValue.makeInteger(nv1.getInteger().subtract(nv2.getInteger()));
case OP_DECIMAL :
- return NodeValue.makeDecimal(nv1.getDecimal().subtract(nv2.getDecimal())) ;
+ return NodeValue.makeDecimal(nv1.getDecimal().subtract(nv2.getDecimal()));
case OP_FLOAT :
- return NodeValue.makeFloat(nv1.getFloat() - nv2.getFloat()) ;
+ return NodeValue.makeFloat(nv1.getFloat() - nv2.getFloat());
case OP_DOUBLE :
- return NodeValue.makeDouble(nv1.getDouble() - nv2.getDouble()) ;
+ return NodeValue.makeDouble(nv1.getDouble() - nv2.getDouble());
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")") ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")");
}
}
public static NodeValue numMultiply(NodeValue nv1, NodeValue nv2) {
switch (classifyNumeric("multiply", nv1, nv2)) {
case OP_INTEGER :
- return NodeValue.makeInteger(nv1.getInteger().multiply(nv2.getInteger())) ;
+ return NodeValue.makeInteger(nv1.getInteger().multiply(nv2.getInteger()));
case OP_DECIMAL :
- return NodeValue.makeDecimal(nv1.getDecimal().multiply(nv2.getDecimal())) ;
+ return NodeValue.makeDecimal(nv1.getDecimal().multiply(nv2.getDecimal()));
case OP_FLOAT :
- return NodeValue.makeFloat(nv1.getFloat() * nv2.getFloat()) ;
+ return NodeValue.makeFloat(nv1.getFloat() * nv2.getFloat());
case OP_DOUBLE :
- return NodeValue.makeDouble(nv1.getDouble() * nv2.getDouble()) ;
+ return NodeValue.makeDouble(nv1.getDouble() * nv2.getDouble());
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")") ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")");
}
}
@@ -129,29 +129,29 @@ public class XSDFuncOp
switch (classifyNumeric("divide", nv1, nv2)) {
case OP_INTEGER : {
// Note: result is a decimal
- BigDecimal d1 = new BigDecimal(nv1.getInteger()) ;
- BigDecimal d2 = new BigDecimal(nv2.getInteger()) ;
- return decimalDivide(d1, d2) ;
+ BigDecimal d1 = new BigDecimal(nv1.getInteger());
+ BigDecimal d2 = new BigDecimal(nv2.getInteger());
+ return decimalDivide(d1, d2);
}
case OP_DECIMAL : {
- BigDecimal d1 = nv1.getDecimal() ;
- BigDecimal d2 = nv2.getDecimal() ;
- return decimalDivide(d1, d2) ;
+ BigDecimal d1 = nv1.getDecimal();
+ BigDecimal d2 = nv2.getDecimal();
+ return decimalDivide(d1, d2);
}
case OP_FLOAT :
// No need to check for divide by zero
- return NodeValue.makeFloat(nv1.getFloat() / nv2.getFloat()) ;
+ return NodeValue.makeFloat(nv1.getFloat() / nv2.getFloat());
case OP_DOUBLE :
// No need to check for divide by zero
- return NodeValue.makeDouble(nv1.getDouble() / nv2.getDouble()) ;
+ return NodeValue.makeDouble(nv1.getDouble() / nv2.getDouble());
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")") ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")");
}
}
private static NodeValue decimalDivide(BigDecimal d1, BigDecimal d2) {
if ( d2.equals(BigDecimal.ZERO) )
- throw new ExprEvalException("Divide by zero in decimal divide") ;
+ throw new ExprEvalException("Divide by zero in decimal divide");
BigDecimal d3;
try {
// Jena 3.16.0 used d1.divide(d2, DIVIDE_PRECISION, BigDecimal.ROUND_FLOOR)
@@ -165,7 +165,7 @@ public class XSDFuncOp
} catch (ArithmeticException ex) {
d3 = d1.divide(d2, DIVIDE_PRECISION, RoundingMode.HALF_EVEN);
}
- return NodeValue.makeDecimal(d3) ;
+ return NodeValue.makeDecimal(d3);
}
/** Integer divide */
@@ -175,25 +175,25 @@ public class XSDFuncOp
BigInteger bi1 = nv1.getInteger();
BigInteger bi2 = nv2.getInteger();
if ( BigInteger.ZERO.equals(bi2) )
- throw new ExprEvalException("Divide by zero in IDIV") ;
+ throw new ExprEvalException("Divide by zero in IDIV");
BigInteger bi3 = bi1.divide(bi2);
return NodeValue.makeInteger(bi3);
case OP_DECIMAL :
BigDecimal bd_a = nv1.getDecimal();
BigDecimal bd_b = nv2.getDecimal();
if ( BigDecimal.ZERO.compareTo(bd_b) == 0 )
- throw new ExprEvalException("Divide by zero in IDIV") ;
+ throw new ExprEvalException("Divide by zero in IDIV");
BigInteger bi = bd_a.divideToIntegralValue(bd_b).toBigIntegerExact();
return NodeValue.makeInteger(bi);
case OP_FLOAT : {
float arg1 = nv1.getFloat();
float arg2 = nv2.getFloat();
if ( arg2 == 0.0 )
- throw new ExprEvalException("Divide by zero in IDIV") ;
+ throw new ExprEvalException("Divide by zero in IDIV");
if ( Float.isNaN(arg1) || Float.isNaN(arg2) )
- throw new ExprEvalException("Divide by NaN in IDIV") ;
+ throw new ExprEvalException("Divide by NaN in IDIV");
if ( Float.isInfinite(arg1) )
- throw new ExprEvalException("+/-INF in IDIV") ;
+ throw new ExprEvalException("+/-INF in IDIV");
float f = arg1 / arg2;
return NodeValue.makeInteger((long)f);
}
@@ -201,16 +201,16 @@ public class XSDFuncOp
double arg1 = nv1.getDouble();
double arg2 = nv2.getDouble();
if ( arg2 == 0.0 )
- throw new ExprEvalException("Divide by zero in IDIV") ;
+ throw new ExprEvalException("Divide by zero in IDIV");
if ( Double.isNaN(arg1) || Double.isNaN(arg2) )
- throw new ExprEvalException("Divide by NaN in IDIV") ;
+ throw new ExprEvalException("Divide by NaN in IDIV");
if ( Double.isInfinite(arg1) )
- throw new ExprEvalException("+/-INF in IDIV") ;
+ throw new ExprEvalException("+/-INF in IDIV");
double d = arg1 / arg2;
return NodeValue.makeInteger((long)d);
}
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")") ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")");
}
}
@@ -226,14 +226,14 @@ public class XSDFuncOp
BigInteger bi1 = nv1.getInteger();
BigInteger bi2 = nv2.getInteger();
if ( BigInteger.ZERO.equals(bi2) )
- throw new ExprEvalException("Divide by zero in MOD") ;
+ throw new ExprEvalException("Divide by zero in MOD");
BigInteger bi3 = bi1.remainder(bi2);
return NodeValue.makeInteger(bi3);
case OP_DECIMAL :
BigDecimal bd_a = nv1.getDecimal();
BigDecimal bd_b = nv2.getDecimal();
if ( BigDecimal.ZERO.compareTo(bd_b) == 0 )
- throw new ExprEvalException("Divide by zero in MOD") ;
+ throw new ExprEvalException("Divide by zero in MOD");
// This is the MOD for X&O
BigDecimal bd_mod = bd_a.remainder(bd_b);
return NodeValue.makeDecimal(bd_mod);
@@ -241,16 +241,16 @@ public class XSDFuncOp
float f1 = nv1.getFloat();
float f2 = nv2.getFloat();
if ( f2 == 0 )
- throw new ExprEvalException("Divide by zero in MOD") ;
- return NodeValue.makeFloat( f1 % f2) ;
+ throw new ExprEvalException("Divide by zero in MOD");
+ return NodeValue.makeFloat( f1 % f2);
case OP_DOUBLE :
double d1 = nv1.getDouble();
double d2 = nv2.getDouble();
if ( d2 == 0 )
- throw new ExprEvalException("Divide by zero in MOD") ;
- return NodeValue.makeDouble(d1 % d2) ;
+ throw new ExprEvalException("Divide by zero in MOD");
+ return NodeValue.makeDouble(d1 % d2);
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")") ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")");
}
}
@@ -282,30 +282,30 @@ public class XSDFuncOp
}
public static NodeValue max(NodeValue nv1, NodeValue nv2) {
- int x = compareNumeric(nv1, nv2) ;
+ int x = compareNumeric(nv1, nv2);
if ( x == Expr.CMP_LESS )
- return nv2 ;
- return nv1 ;
+ return nv2;
+ return nv1;
}
public static NodeValue min(NodeValue nv1, NodeValue nv2) {
- int x = compareNumeric(nv1, nv2) ;
+ int x = compareNumeric(nv1, nv2);
if ( x == Expr.CMP_GREATER )
- return nv2 ;
- return nv1 ;
+ return nv2;
+ return nv1;
}
/** {@literal F&O} fn:not */
public static NodeValue not(NodeValue nv) {
- boolean b = XSDFuncOp.booleanEffectiveValue(nv) ;
- return NodeValue.booleanReturn(!b) ;
+ boolean b = XSDFuncOp.booleanEffectiveValue(nv);
+ return NodeValue.booleanReturn(!b);
}
/** {@literal F&O} fn:boolean */
public static NodeValue booleanEffectiveValueAsNodeValue(NodeValue nv) {
if ( nv.isBoolean() ) // "Optimization" (saves on object churn)
- return nv ;
- return NodeValue.booleanReturn(booleanEffectiveValue(nv)) ;
+ return nv;
+ return NodeValue.booleanReturn(booleanEffectiveValue(nv));
}
/** {@literal F&O} fn:boolean */
@@ -317,14 +317,14 @@ public class XSDFuncOp
// http://www.w3.org/TR/xquery/#dt-ebv
if ( nv.isBoolean() )
- return nv.getBoolean() ;
+ return nv.getBoolean();
if ( nv.isString() || nv.isLangString() )
// Plain literals.
- return ! nv.getString().isEmpty() ;
+ return ! nv.getString().isEmpty();
if ( nv.isInteger() )
- return !nv.getInteger().equals(BigInteger.ZERO) ;
+ return !nv.getInteger().equals(BigInteger.ZERO);
if ( nv.isDecimal() )
- return !nv.getDecimal().equals(BigDecimal.ZERO) ;
+ return !nv.getDecimal().equals(BigDecimal.ZERO);
if ( nv.isDouble() ) {
double v = nv.getDouble();
return v != 0.0d && ! Double.isNaN(v);
@@ -333,76 +333,76 @@ public class XSDFuncOp
float v = nv.getFloat();
return v != 0.0f && ! Float.isNaN(v);
}
- NodeValue.raise(new ExprEvalException("Not a boolean effective value (wrong type): " + nv)) ;
+ NodeValue.raise(new ExprEvalException("Not a boolean effective value (wrong type): " + nv));
// Does not return
- return false ;
+ return false;
}
public static NodeValue unaryMinus(NodeValue nv) {
switch (classifyNumeric("unaryMinus", nv)) {
case OP_INTEGER :
- return NodeValue.makeInteger(nv.getInteger().negate()) ;
+ return NodeValue.makeInteger(nv.getInteger().negate());
case OP_DECIMAL :
- return NodeValue.makeDecimal(nv.getDecimal().negate()) ;
+ return NodeValue.makeDecimal(nv.getDecimal().negate());
case OP_FLOAT :
- return NodeValue.makeFloat(-nv.getFloat()) ;
+ return NodeValue.makeFloat(-nv.getFloat());
case OP_DOUBLE :
- return NodeValue.makeDouble(-nv.getDouble()) ;
+ return NodeValue.makeDouble(-nv.getDouble());
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : " + nv) ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : " + nv);
}
}
public static NodeValue unaryPlus(NodeValue nv) {
// Not quite a no-op - tests for a number
- NumericType opType = classifyNumeric("unaryPlus", nv) ;
- return nv ;
+ NumericType opType = classifyNumeric("unaryPlus", nv);
+ return nv;
}
public static NodeValue abs(NodeValue nv) {
switch (classifyNumeric("abs", nv)) {
case OP_INTEGER :
- return NodeValue.makeInteger(nv.getInteger().abs()) ;
+ return NodeValue.makeInteger(nv.getInteger().abs());
case OP_DECIMAL :
- return NodeValue.makeDecimal(nv.getDecimal().abs()) ;
+ return NodeValue.makeDecimal(nv.getDecimal().abs());
case OP_FLOAT :
- return NodeValue.makeFloat(Math.abs(nv.getFloat())) ;
+ return NodeValue.makeFloat(Math.abs(nv.getFloat()));
case OP_DOUBLE :
- return NodeValue.makeDouble(Math.abs(nv.getDouble())) ;
+ return NodeValue.makeDouble(Math.abs(nv.getDouble()));
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : " + nv) ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : " + nv);
}
}
public static NodeValue ceiling(NodeValue v) {
switch (classifyNumeric("ceiling", v)) {
case OP_INTEGER :
- return v ;
+ return v;
case OP_DECIMAL :
- BigDecimal dec = v.getDecimal().setScale(0, RoundingMode.CEILING) ;
- return NodeValue.makeDecimal(dec) ;
+ BigDecimal dec = v.getDecimal().setScale(0, RoundingMode.CEILING);
+ return NodeValue.makeDecimal(dec);
case OP_FLOAT :
- return NodeValue.makeFloat((float)Math.ceil(v.getFloat())) ;
+ return NodeValue.makeFloat((float)Math.ceil(v.getFloat()));
case OP_DOUBLE :
- return NodeValue.makeDouble(Math.ceil(v.getDouble())) ;
+ return NodeValue.makeDouble(Math.ceil(v.getDouble()));
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : " + v) ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : " + v);
}
}
public static NodeValue floor(NodeValue v) {
switch (classifyNumeric("floor", v)) {
case OP_INTEGER :
- return v ;
+ return v;
case OP_DECIMAL :
- BigDecimal dec = v.getDecimal().setScale(0, RoundingMode.FLOOR) ;
- return NodeValue.makeDecimal(dec) ;
+ BigDecimal dec = v.getDecimal().setScale(0, RoundingMode.FLOOR);
+ return NodeValue.makeDecimal(dec);
case OP_FLOAT :
- return NodeValue.makeFloat((float)Math.floor(v.getFloat())) ;
+ return NodeValue.makeFloat((float)Math.floor(v.getFloat()));
case OP_DOUBLE :
- return NodeValue.makeDouble(Math.floor(v.getDouble())) ;
+ return NodeValue.makeDouble(Math.floor(v.getDouble()));
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : " + v) ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : " + v);
}
}
@@ -455,47 +455,47 @@ public class XSDFuncOp
BigDecimal decFromInt = roundDecimalValue(new BigDecimal(v.getInteger()),precisionInt,isHalfEven);
return NodeValue.makeInteger(decFromInt.toBigIntegerExact());
case OP_DECIMAL :
- return NodeValue.makeDecimal(roundDecimalValue(v.getDecimal(),precisionInt,isHalfEven)) ;
+ return NodeValue.makeDecimal(roundDecimalValue(v.getDecimal(),precisionInt,isHalfEven));
case OP_FLOAT :
BigDecimal decFromFloat = roundDecimalValue(new BigDecimal(v.getFloat()),precisionInt,isHalfEven);
- return NodeValue.makeFloat(decFromFloat.floatValue()) ;
+ return NodeValue.makeFloat(decFromFloat.floatValue());
case OP_DOUBLE :
BigDecimal decFromDouble = roundDecimalValue(new BigDecimal(v.getDouble()),precisionInt,isHalfEven);
- return NodeValue.makeDouble(decFromDouble.doubleValue()) ;
+ return NodeValue.makeDouble(decFromDouble.doubleValue());
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : " + v) ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : " + v);
}
}
public static NodeValue sqrt(NodeValue v) {
- return NodeValue.makeDouble(Math.sqrt(v.getDouble())) ;
+ return NodeValue.makeDouble(Math.sqrt(v.getDouble()));
}
// NB Java string start from zero and uses start/end
// F&O strings start from one and uses start/length
public static NodeValue javaSubstring(NodeValue v1, NodeValue v2) {
- return javaSubstring(v1, v2, null) ;
+ return javaSubstring(v1, v2, null);
}
public static NodeValue javaSubstring(NodeValue nvString, NodeValue nvStart, NodeValue nvFinish) {
try {
- String string = nvString.getString() ;
- int start = nvStart.getInteger().intValue() ;
+ String string = nvString.getString();
+ int start = nvStart.getInteger().intValue();
if ( nvFinish == null )
- return NodeValue.makeString(string.substring(start)) ;
+ return NodeValue.makeString(string.substring(start));
- int finish = nvFinish.getInteger().intValue() ;
- return NodeValue.makeString(string.substring(start, string.offsetByCodePoints(start, finish - start))) ;
+ int finish = nvFinish.getInteger().intValue();
+ return NodeValue.makeString(string.substring(start, string.offsetByCodePoints(start, finish - start)));
} catch (IndexOutOfBoundsException ex) {
- throw new ExprEvalException("IndexOutOfBounds", ex) ;
+ throw new ExprEvalException("IndexOutOfBounds", ex);
}
}
// expecting nvString = format | nvStart = value (int,float, string,....)
public static NodeValue javaSprintf(NodeValue nvFormat, List<NodeValue> valuesToPrint) {
try {
- String formatForOutput = nvFormat.getString() ;
+ String formatForOutput = nvFormat.getString();
List<Object> objVals = new ArrayList<>();
for(NodeValue nvValue:valuesToPrint) {
ValueSpace vlSpClass = nvValue.getValueSpace();
@@ -551,15 +551,15 @@ public class XSDFuncOp
return NodeValue.makeString(String.format(formatForOutput,objVals.toArray()));
} catch (IndexOutOfBoundsException ex) {
- throw new ExprEvalException("IndexOutOfBounds", ex) ;
+ throw new ExprEvalException("IndexOutOfBounds", ex);
}
}
public static NodeValue strlen(NodeValue nvString) {
- Node n = checkAndGetStringLiteral("strlen", nvString) ;
+ Node n = checkAndGetStringLiteral("strlen", nvString);
String str = n.getLiteralLexicalForm();
- int len = str.codePointCount(0, str.length()) ;
- return NodeValue.makeInteger(len) ;
+ int len = str.codePointCount(0, str.length());
+ return NodeValue.makeInteger(len);
}
public static NodeValue strReplace(NodeValue nvStr, NodeValue nvPattern, NodeValue nvReplacement, NodeValue nvFlags) {
@@ -571,16 +571,16 @@ public class XSDFuncOp
}
public static NodeValue strReplace(NodeValue nvStr, Pattern pattern, NodeValue nvReplacement) {
- String n = checkAndGetStringLiteral("replace", nvStr).getLiteralLexicalForm() ;
- String rep = checkAndGetStringLiteral("replace", nvReplacement).getLiteralLexicalForm() ;
- String x = replaceAll(pattern.matcher(n), rep) ;
+ String n = checkAndGetStringLiteral("replace", nvStr).getLiteralLexicalForm();
+ String rep = checkAndGetStringLiteral("replace", nvReplacement).getLiteralLexicalForm();
+ String x = replaceAll(pattern.matcher(n), rep);
if ( x == null )
// No replacement.
- return nvStr ;
+ return nvStr;
if ( x.equals(n) )
// No change - return original.
return nvStr;
- return calcReturn(x, nvStr.asNode()) ;
+ return calcReturn(x, nvStr.asNode());
}
// Jena's replaceAll and xsd:func-replace differ in the handling of matching
@@ -592,50 +592,50 @@ public class XSDFuncOp
private static String replaceAll(Matcher matcher, String rep) {
try {
- StringBuilder sb = null ; // Delay until needed
+ StringBuilder sb = null; // Delay until needed
while(matcher.find()) {
if ( sb == null )
- sb = new StringBuilder() ;
+ sb = new StringBuilder();
else {
// Do one match of zerolength string otherwise filter out.
if (matcher.start() == matcher.end() )
- continue ;
+ continue;
}
matcher.appendReplacement(sb, rep);
}
if ( sb == null )
- return null ;
+ return null;
matcher.appendTail(sb);
return sb.toString();
} catch (IndexOutOfBoundsException ex) {
- throw new ExprEvalException("IndexOutOfBounds", ex) ;
+ throw new ExprEvalException("IndexOutOfBounds", ex);
}
}
public static NodeValue strReplace(NodeValue nvStr, NodeValue nvPattern, NodeValue nvReplacement) {
- return strReplace(nvStr, nvPattern, nvReplacement, null) ;
+ return strReplace(nvStr, nvPattern, nvReplacement, null);
}
public static NodeValue substring(NodeValue v1, NodeValue v2) {
- return substring(v1, v2, null) ;
+ return substring(v1, v2, null);
}
public static NodeValue substring(NodeValue nvString, NodeValue nvStart, NodeValue nvLength) {
- Node n = checkAndGetStringLiteral("substring", nvString) ;
- RDFDatatype dt = n.getLiteralDatatype() ;
+ Node n = checkAndGetStringLiteral("substring", nvString);
+ RDFDatatype dt = n.getLiteralDatatype();
// XSD F&O:
try {
- String string = n.getLiteralLexicalForm() ;
+ String string = n.getLiteralLexicalForm();
// Length in code points.
int cpLength = string.codePointCount(0, string.length());
// Arguments.
- int start = intValueStr(nvStart, cpLength + 1) ;
- int length ;
+ int start = intValueStr(nvStart, cpLength + 1);
+ int length;
if ( nvLength != null )
- length = intValueStr(nvLength, 0) ;
+ length = intValueStr(nvLength, 0);
else
length = cpLength;
@@ -647,21 +647,21 @@ public class XSDFuncOp
// Working in codepoints indexes at this point
// Includes negative start.
- int finish = start + length ;
+ int finish = start + length;
- // F&O strings are one-based ; convert to java, 0 based.
+ // F&O strings are one-based; convert to java, 0 based.
// Adjust to zero-offset, and ensure in-bounds - still in codepoint indexes.
// java needs indexes in-bounds.
- start-- ;
- finish-- ;
+ start--;
+ finish--;
if ( start < 0 )
- start = 0 ;
+ start = 0;
if ( finish > cpLength )
- finish = cpLength ; // Java index must be within bounds.
+ finish = cpLength; // Java index must be within bounds.
if ( finish < start )
- finish = start ;
+ finish = start;
if ( finish < 0 )
- finish = 0 ;
+ finish = 0;
// Convert to UTF-16 code units to index values for the string.substring
int xs = codePointToStringIndex(string, start, cpLength);
@@ -669,9 +669,9 @@ public class XSDFuncOp
String lex2 = string.substring(xs, xf);
- return calcReturn(lex2, n) ;
+ return calcReturn(lex2, n);
} catch (IndexOutOfBoundsException ex) {
- throw new ExprEvalException("IndexOutOfBounds", ex) ;
+ throw new ExprEvalException("IndexOutOfBounds", ex);
}
}
@@ -688,186 +688,186 @@ public class XSDFuncOp
// NaN, float and double.
private static int intValueStr(NodeValue nv, int valueNan) {
if ( nv.isInteger() )
- return nv.getInteger().intValue() ;
+ return nv.getInteger().intValue();
if ( nv.isDecimal() )
- return (int)Math.round(nv.getDecimal().doubleValue()) ;
+ return (int)Math.round(nv.getDecimal().doubleValue());
if ( nv.isFloat() ) {
- float f = nv.getFloat() ;
+ float f = nv.getFloat();
if ( Float.isNaN(f) )
- return valueNan ;
- return Math.round(f) ;
+ return valueNan;
+ return Math.round(f);
}
if ( nv.isDouble() ) {
- double d = nv.getDouble() ;
+ double d = nv.getDouble();
if ( Double.isNaN(d) )
- return valueNan ;
- return (int)Math.round(d) ;
+ return valueNan;
+ return (int)Math.round(d);
}
- throw new ExprEvalException("Not a number:" + nv) ;
+ throw new ExprEvalException("Not a number:" + nv);
}
public static NodeValue strContains(NodeValue string, NodeValue match) {
- checkTwoArgumentStringLiterals("contains", string, match) ;
- String lex1 = string.asNode().getLiteralLexicalForm() ;
- String lex2 = match.asNode().getLiteralLexicalForm() ;
- boolean x = StrUtils.contains(lex1, lex2) ;
- return NodeValue.booleanReturn(x) ;
+ checkTwoArgumentStringLiterals("contains", string, match);
+ String lex1 = string.asNode().getLiteralLexicalForm();
+ String lex2 = match.asNode().getLiteralLexicalForm();
+ boolean x = StrUtils.contains(lex1, lex2);
+ return NodeValue.booleanReturn(x);
}
public static NodeValue strStartsWith(NodeValue string, NodeValue match) {
- checkTwoArgumentStringLiterals("strStarts", string, match) ;
- String lex1 = string.asNode().getLiteralLexicalForm() ;
- String lex2 = match.asNode().getLiteralLexicalForm() ;
- return NodeValue.booleanReturn(lex1.startsWith(lex2)) ;
+ checkTwoArgumentStringLiterals("strStarts", string, match);
+ String lex1 = string.asNode().getLiteralLexicalForm();
+ String lex2 = match.asNode().getLiteralLexicalForm();
+ return NodeValue.booleanReturn(lex1.startsWith(lex2));
}
public static NodeValue strEndsWith(NodeValue string, NodeValue match) {
- checkTwoArgumentStringLiterals("strEnds", string, match) ;
- String lex1 = string.asNode().getLiteralLexicalForm() ;
- String lex2 = match.asNode().getLiteralLexicalForm() ;
- return NodeValue.booleanReturn(lex1.endsWith(lex2)) ;
+ checkTwoArgumentStringLiterals("strEnds", string, match);
+ String lex1 = string.asNode().getLiteralLexicalForm();
+ String lex2 = match.asNode().getLiteralLexicalForm();
+ return NodeValue.booleanReturn(lex1.endsWith(lex2));
}
/** Build a NodeValue with lexical form, and same language and datatype as the Node argument */
private static NodeValue calcReturn(String result, Node arg) {
- Node n2 = NodeFactory.createLiteral(result, arg.getLiteralLanguage(), arg.getLiteralDatatype()) ;
- return NodeValue.makeNode(n2) ;
+ Node n2 = NodeFactory.createLiteral(result, arg.getLiteralLanguage(), arg.getLiteralDatatype());
+ return NodeValue.makeNode(n2);
}
public static NodeValue strBefore(NodeValue string, NodeValue match) {
- checkTwoArgumentStringLiterals("strBefore", string, match) ;
- String lex1 = string.asNode().getLiteralLexicalForm() ;
- String lex2 = match.asNode().getLiteralLexicalForm() ;
- Node mainArg = string.asNode() ;
+ checkTwoArgumentStringLiterals("strBefore", string, match);
+ String lex1 = string.asNode().getLiteralLexicalForm();
+ String lex2 = match.asNode().getLiteralLexicalForm();
+ Node mainArg = string.asNode();
if ( lex2.length() == 0 )
- return calcReturn("", mainArg) ;
+ return calcReturn("", mainArg);
- int i = lex1.indexOf(lex2) ;
+ int i = lex1.indexOf(lex2);
if ( i < 0 )
- return NodeValue.nvEmptyString ;
+ return NodeValue.nvEmptyString;
- String s = lex1.substring(0, i) ;
- return calcReturn(s, string.asNode()) ;
+ String s = lex1.substring(0, i);
+ return calcReturn(s, string.asNode());
}
public static NodeValue strAfter(NodeValue string, NodeValue match) {
- checkTwoArgumentStringLiterals("strAfter", string, match) ;
- String lex1 = string.asNode().getLiteralLexicalForm() ;
- String lex2 = match.asNode().getLiteralLexicalForm() ;
- Node mainArg = string.asNode() ;
+ checkTwoArgumentStringLiterals("strAfter", string, match);
+ String lex1 = string.asNode().getLiteralLexicalForm();
+ String lex2 = match.asNode().getLiteralLexicalForm();
+ Node mainArg = string.asNode();
if ( lex2.length() == 0 )
- return calcReturn(lex1, mainArg) ;
+ return calcReturn(lex1, mainArg);
- int i = lex1.indexOf(lex2) ;
+ int i = lex1.indexOf(lex2);
if ( i < 0 )
- return NodeValue.nvEmptyString ;
- i += lex2.length() ;
- String s = lex1.substring(i) ;
- return calcReturn(s, string.asNode()) ;
+ return NodeValue.nvEmptyString;
+ i += lex2.length();
+ String s = lex1.substring(i);
+ return calcReturn(s, string.asNode());
}
public static NodeValue strLowerCase(NodeValue string) {
- Node n = checkAndGetStringLiteral("lcase", string) ;
- String lex = n.getLiteralLexicalForm() ;
- String lex2 = lex.toLowerCase() ;
- return calcReturn(lex2, string.asNode()) ;
+ Node n = checkAndGetStringLiteral("lcase", string);
+ String lex = n.getLiteralLexicalForm();
+ String lex2 = lex.toLowerCase();
+ return calcReturn(lex2, string.asNode());
}
public static NodeValue strUpperCase(NodeValue string) {
- Node n = checkAndGetStringLiteral("ucase", string) ;
- String lex = n.getLiteralLexicalForm() ;
- String lex2 = lex.toUpperCase() ;
- return calcReturn(lex2, string.asNode()) ;
+ Node n = checkAndGetStringLiteral("ucase", string);
+ String lex = n.getLiteralLexicalForm();
+ String lex2 = lex.toUpperCase();
+ return calcReturn(lex2, string.asNode());
}
public static NodeValue strEncodeForURI(NodeValue v) {
- Node n = v.asNode() ;
+ Node n = v.asNode();
if ( !n.isLiteral() )
- throw new ExprEvalException("Not a literal") ;
+ throw new ExprEvalException("Not a literal");
if ( ! Util.isSimpleString(n) && ! Util.isLangString(n) )
- throw new ExprEvalException("Not a string literal") ;
+ throw new ExprEvalException("Not a string literal");
- String str = n.getLiteralLexicalForm() ;
- String encStr = IRILib.encodeUriComponent(str) ;
- encStr = IRILib.encodeNonASCII(encStr) ;
+ String str = n.getLiteralLexicalForm();
+ String encStr = IRILib.encodeUriComponent(str);
+ encStr = IRILib.encodeNonASCII(encStr);
- return NodeValue.makeString(encStr) ;
+ return NodeValue.makeString(encStr);
}
/** {@literal F&O} fn:concat (implicit cast to strings). */
public static NodeValue fnConcat(List<NodeValue> args) {
- StringBuilder sb = new StringBuilder() ;
+ StringBuilder sb = new StringBuilder();
for (NodeValue arg : args) {
- String x = arg.asString() ;
- sb.append(x) ;
+ String x = arg.asString();
+ sb.append(x);
}
- return NodeValue.makeString(sb.toString()) ;
+ return NodeValue.makeString(sb.toString());
}
/** SPARQL CONCAT (no implicit casts to strings) */
public static NodeValue strConcat(List<NodeValue> args) {
// Step 1 : Choose type.
// One lang tag -> that lang tag
- String lang = null ;
- boolean mixedLang = false ;
- boolean xsdString = false ;
- boolean simpleLiteral = false ;
+ String lang = null;
+ boolean mixedLang = false;
+ boolean xsdString = false;
+ boolean simpleLiteral = false;
- StringBuilder sb = new StringBuilder() ;
+ StringBuilder sb = new StringBuilder();
for (NodeValue nv : args) {
- Node n = checkAndGetStringLiteral("CONCAT", nv) ;
- String lang1 = n.getLiteralLanguage() ;
+ Node n = checkAndGetStringLiteral("CONCAT", nv);
+ String lang1 = n.getLiteralLanguage();
if ( !lang1.equals("") ) {
if ( lang != null && !lang1.equals(lang) )
// throw new
- // ExprEvalException("CONCAT: Mixed language tags: "+args) ;
- mixedLang = true ;
- lang = lang1 ;
+ // ExprEvalException("CONCAT: Mixed language tags: "+args);
+ mixedLang = true;
+ lang = lang1;
} else if ( n.getLiteralDatatype() != null )
- xsdString = true ;
+ xsdString = true;
else
- simpleLiteral = true ;
+ simpleLiteral = true;
- sb.append(n.getLiteralLexicalForm()) ;
+ sb.append(n.getLiteralLexicalForm());
}
if ( mixedLang )
- return NodeValue.makeString(sb.toString()) ;
+ return NodeValue.makeString(sb.toString());
// Must be all one lang.
if ( lang != null ) {
if ( !xsdString && !simpleLiteral )
- return NodeValue.makeNode(sb.toString(), lang, (String)null) ;
+ return NodeValue.makeNode(sb.toString(), lang, (String)null);
else
// Lang and one or more of xsd:string or simpleLiteral.
- return NodeValue.makeString(sb.toString()) ;
+ return NodeValue.makeString(sb.toString());
}
if ( simpleLiteral && xsdString )
- return NodeValue.makeString(sb.toString()) ;
+ return NodeValue.makeString(sb.toString());
// All xsdString
if ( xsdString )
- return NodeValue.makeNode(sb.toString(), XSDDatatype.XSDstring) ;
+ return NodeValue.makeNode(sb.toString(), XSDDatatype.XSDstring);
if ( simpleLiteral )
- return NodeValue.makeString(sb.toString()) ;
+ return NodeValue.makeString(sb.toString());
// No types - i.e. no arguments
- return NodeValue.makeString(sb.toString()) ;
+ return NodeValue.makeString(sb.toString());
}
/** fn:normalizeSpace */
public static NodeValue strNormalizeSpace(NodeValue v){
- String str = v.asString() ;
+ String str = v.asString();
if(str == "" )
return NodeValue.nvEmptyString;
// is it possible that str is null?
str = str.trim().replaceAll("\\s+"," ");
- return NodeValue.makeString(str) ;
+ return NodeValue.makeString(str);
}
public static NodeValue strNormalizeUnicode(NodeValue v1, NodeValue v2) {
@@ -907,89 +907,89 @@ public class XSDFuncOp
public static NumericType classifyNumeric(String fName, NodeValue nv1, NodeValue nv2) {
if ( !nv1.isNumber() )
- throw new ExprEvalTypeException("Not a number (first arg to " + fName + "): " + nv1) ;
+ throw new ExprEvalTypeException("Not a number (first arg to " + fName + "): " + nv1);
if ( !nv2.isNumber() )
- throw new ExprEvalTypeException("Not a number (second arg to " + fName + "): " + nv2) ;
+ throw new ExprEvalTypeException("Not a number (second arg to " + fName + "): " + nv2);
if ( nv1.isInteger() ) {
if ( nv2.isInteger() )
- return OP_INTEGER ;
+ return OP_INTEGER;
if ( nv2.isDecimal() )
- return OP_DECIMAL ;
+ return OP_DECIMAL;
if ( nv2.isFloat() )
- return OP_FLOAT ;
+ return OP_FLOAT;
if ( nv2.isDouble() )
- return OP_DOUBLE ;
- throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2) ;
+ return OP_DOUBLE;
+ throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2);
}
if ( nv1.isDecimal() ) {
if ( nv2.isDecimal() )
- return OP_DECIMAL ;
+ return OP_DECIMAL;
if ( nv2.isFloat() )
- return OP_FLOAT ;
+ return OP_FLOAT;
if ( nv2.isDouble() )
- return OP_DOUBLE ;
- throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2) ;
+ return OP_DOUBLE;
+ throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2);
}
if ( nv1.isFloat() ) {
if ( nv2.isFloat() )
- return OP_FLOAT ;
+ return OP_FLOAT;
if ( nv2.isDouble() )
- return OP_DOUBLE ;
- throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2) ;
+ return OP_DOUBLE;
+ throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2);
}
if ( nv1.isDouble() ) {
if ( nv2.isDouble() )
- return OP_DOUBLE ;
- throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2) ;
+ return OP_DOUBLE;
+ throw new ARQInternalErrorException("Numeric op unrecognized (second arg to " + fName + "): " + nv2);
}
- throw new ARQInternalErrorException("Numeric op unrecognized (first arg to " + fName + "): " + nv1) ;
+ throw new ARQInternalErrorException("Numeric op unrecognized (first arg to " + fName + "): " + nv1);
}
public static NumericType classifyNumeric(String fName, NodeValue nv) {
if ( !nv.isNumber() )
- throw new ExprEvalTypeException("Not a number: (" + fName + ") " + nv) ;
+ throw new ExprEvalTypeException("Not a number: (" + fName + ") " + nv);
if ( nv.isInteger() )
- return OP_INTEGER ;
+ return OP_INTEGER;
if ( nv.isDecimal() )
- return OP_DECIMAL ;
+ return OP_DECIMAL;
if ( nv.isFloat() )
- return OP_FLOAT ;
+ return OP_FLOAT;
if ( nv.isDouble() )
- return OP_DOUBLE ;
- throw new ARQInternalErrorException("Numeric op unrecognized (" + fName + "): " + nv) ;
+ return OP_DOUBLE;
+ throw new ARQInternalErrorException("Numeric op unrecognized (" + fName + "): " + nv);
}
- private static Set<XSDDatatype> integerSubTypes = new HashSet<>() ;
+ private static Set<XSDDatatype> integerSubTypes = new HashSet<>();
static {
-// decimalSubTypes.add(XSDDatatype.XSDfloat) ;
-// decimalSubTypes.add(XSDDatatype.XSDdouble) ;
- integerSubTypes.add(XSDDatatype.XSDint) ;
- integerSubTypes.add(XSDDatatype.XSDlong) ;
- integerSubTypes.add(XSDDatatype.XSDshort) ;
- integerSubTypes.add(XSDDatatype.XSDbyte) ;
- integerSubTypes.add(XSDDatatype.XSDunsignedByte) ;
- integerSubTypes.add(XSDDatatype.XSDunsignedShort) ;
- integerSubTypes.add(XSDDatatype.XSDunsignedInt) ;
- integerSubTypes.add(XSDDatatype.XSDunsignedLong) ;
-// integerSubTypes.add(XSDDatatype.XSDdecimal) ;
- integerSubTypes.add(XSDDatatype.XSDinteger) ;
- integerSubTypes.add(XSDDatatype.XSDnonPositiveInteger) ;
- integerSubTypes.add(XSDDatatype.XSDnonNegativeInteger) ;
- integerSubTypes.add(XSDDatatype.XSDpositiveInteger) ;
- integerSubTypes.add(XSDDatatype.XSDnegativeInteger) ;
+// decimalSubTypes.add(XSDDatatype.XSDfloat);
+// decimalSubTypes.add(XSDDatatype.XSDdouble);
+ integerSubTypes.add(XSDDatatype.XSDint);
+ integerSubTypes.add(XSDDatatype.XSDlong);
+ integerSubTypes.add(XSDDatatype.XSDshort);
+ integerSubTypes.add(XSDDatatype.XSDbyte);
+ integerSubTypes.add(XSDDatatype.XSDunsignedByte);
+ integerSubTypes.add(XSDDatatype.XSDunsignedShort);
+ integerSubTypes.add(XSDDatatype.XSDunsignedInt);
+ integerSubTypes.add(XSDDatatype.XSDunsignedLong);
+// integerSubTypes.add(XSDDatatype.XSDdecimal);
+ integerSubTypes.add(XSDDatatype.XSDinteger);
+ integerSubTypes.add(XSDDatatype.XSDnonPositiveInteger);
+ integerSubTypes.add(XSDDatatype.XSDnonNegativeInteger);
+ integerSubTypes.add(XSDDatatype.XSDpositiveInteger);
+ integerSubTypes.add(XSDDatatype.XSDnegativeInteger);
}
public static boolean isNumericDatatype(XSDDatatype xsdDatatype) {
if ( XSDDatatype.XSDfloat.equals(xsdDatatype) )
- return true ;
+ return true;
if ( XSDDatatype.XSDdouble.equals(xsdDatatype) )
- return true ;
- return isDecimalDatatype(xsdDatatype) ;
+ return true;
+ return isDecimalDatatype(xsdDatatype);
}
public static boolean isNumeric(Node node) {
@@ -1003,12 +1003,12 @@ public class XSDFuncOp
public static boolean isDecimalDatatype(XSDDatatype xsdDatatype) {
if ( XSDDatatype.XSDdecimal.equals(xsdDatatype) )
- return true ;
- return isIntegerDatatype(xsdDatatype) ;
+ return true;
+ return isIntegerDatatype(xsdDatatype);
}
public static boolean isIntegerDatatype(XSDDatatype xsdDatatype) {
- return integerSubTypes.contains(xsdDatatype) ;
+ return integerSubTypes.contains(xsdDatatype);
}
public static boolean isTemporalDatatype(XSDDatatype datatype) {
@@ -1041,26 +1041,26 @@ public class XSDFuncOp
private static int calcReturn(int x) {
if ( x < 0 )
- return Expr.CMP_LESS ;
+ return Expr.CMP_LESS;
if ( x > 0 )
- return Expr.CMP_GREATER ;
- return Expr.CMP_EQUAL ;
+ return Expr.CMP_GREATER;
+ return Expr.CMP_EQUAL;
}
public static int compareNumeric(NodeValue nv1, NodeValue nv2) {
- NumericType opType = classifyNumeric("compareNumeric", nv1, nv2) ;
+ NumericType opType = classifyNumeric("compareNumeric", nv1, nv2);
switch (opType) {
case OP_INTEGER :
- return calcReturn(nv1.getInteger().compareTo(nv2.getInteger())) ;
+ return calcReturn(nv1.getInteger().compareTo(nv2.getInteger()));
case OP_DECIMAL :
- return calcReturn(nv1.getDecimal().compareTo(nv2.getDecimal())) ;
+ return calcReturn(nv1.getDecimal().compareTo(nv2.getDecimal()));
case OP_FLOAT :
- return calcReturn(Float.compare(nv1.getFloat(), nv2.getFloat())) ;
+ return calcReturn(Float.compare(nv1.getFloat(), nv2.getFloat()));
case OP_DOUBLE :
- return calcReturn(Double.compare(nv1.getDouble(), nv2.getDouble())) ;
+ return calcReturn(Double.compare(nv1.getDouble(), nv2.getDouble()));
default :
- throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")") ;
+ throw new ARQInternalErrorException("Unrecognized numeric operation : (" + nv1 + " ," + nv2 + ")");
}
}
@@ -1077,7 +1077,7 @@ public class XSDFuncOp
// langMatch
public static int compareString(NodeValue nv1, NodeValue nv2) {
- return calcReturn(nv1.getString().compareTo(nv2.getString())) ;
+ return calcReturn(nv1.getString().compareTo(nv2.getString()));
}
// --------------------------------
@@ -1097,7 +1097,7 @@ public class XSDFuncOp
// starting instants. These xs:dateTime values are calculated as described
// below."
if ( SystemARQ.StrictDateTimeFO )
- return compareDateTimeFO(nv1, nv2) ;
+ return compareDateTimeFO(nv1, nv2);
return compareDateTimeXSD(nv1, nv2);
}
@@ -1105,8 +1105,8 @@ public class XSDFuncOp
public static int compareDateTimeXSD(NodeValue nv1, NodeValue nv2) {
XMLGregorianCalendar dt1 = getXMLGregorianCalendarXSD(nv1);
XMLGregorianCalendar dt2 = getXMLGregorianCalendarXSD(nv2);
- int x = compareDateTime(dt1, dt2) ;
- return x ;
+ int x = compareDateTime(dt1, dt2);
+ return x;
}
/**
@@ -1118,8 +1118,8 @@ public class XSDFuncOp
public static int compareDateTimeFO(NodeValue nv1, NodeValue nv2) {
XMLGregorianCalendar dt1 = getXMLGregorianCalendarFO(nv1);
XMLGregorianCalendar dt2 = getXMLGregorianCalendarFO(nv2);
- int x = compareDateTime(dt1, dt2) ;
- return x ;
+ int x = compareDateTime(dt1, dt2);
+ return x;
}
/** Return a normalized XMLGregorianCalendar appropriate for F&O comparison using the XSD algorithm. */
@@ -1164,8 +1164,8 @@ public class XSDFuncOp
// F&O has an "implicit timezone" - this code implements the XMLSchema
// compare algorithm.
- int x = dt1.compare(dt2) ;
- return convertComparison(x) ;
+ int x = dt1.compare(dt2);
+ return convertComparison(x);
}
@@ -1197,20 +1197,20 @@ public class XSDFuncOp
// F&O has an "implicit timezone" - this code implements the XMLSchema
// compare algorithm.
- int x = dt1.compare(dt2) ;
- return convertComparison(x) ;
+ int x = dt1.compare(dt2);
+ return convertComparison(x);
}
private static int convertComparison(int x) {
if ( x == DatatypeConstants.EQUAL )
- return Expr.CMP_EQUAL ;
+ return Expr.CMP_EQUAL;
if ( x == DatatypeConstants.LESSER )
- return Expr.CMP_LESS ;
+ return Expr.CMP_LESS;
if ( x == DatatypeConstants.GREATER )
- return Expr.CMP_GREATER ;
+ return Expr.CMP_GREATER;
if ( x == DatatypeConstants.INDETERMINATE )
- return Expr.CMP_INDETERMINATE ;
- throw new ARQInternalErrorException("Unexpected return from XSDDuration.compare: " + x) ;
+ return Expr.CMP_INDETERMINATE;
+ throw new ARQInternalErrorException("Unexpected return from XSDDuration.compare: " + x);
}
// --------------------------------
@@ -1237,16 +1237,16 @@ public class XSDFuncOp
// public static NodeValue logicalAnd(NodeValue x, NodeValue y)
public static int compareBoolean(NodeValue nv1, NodeValue nv2) {
- boolean b1 = nv1.getBoolean() ;
- boolean b2 = nv2.getBoolean() ;
+ boolean b1 = nv1.getBoolean();
+ boolean b2 = nv2.getBoolean();
if ( b1 == b2 )
- return Expr.CMP_EQUAL ;
+ return Expr.CMP_EQUAL;
if ( !b1 && b2 )
- return Expr.CMP_LESS ;
+ return Expr.CMP_LESS;
if ( b1 && !b2 )
- return Expr.CMP_GREATER ;
- throw new ARQInternalErrorException("Weird boolean comparison: " + nv1 + ", " + nv2) ;
+ return Expr.CMP_GREATER;
+ throw new ARQInternalErrorException("Weird boolean comparison: " + nv1 + ", " + nv2);
}
/**
@@ -1254,13 +1254,13 @@ public class XSDFuncOp
* Assumes the NodeValue is of suitable datatype.
*/
private static String tzStrFromNV(NodeValue nv) {
- DateTimeStruct dts = parseAnyDT(nv) ;
+ DateTimeStruct dts = parseAnyDT(nv);
if ( dts == null )
- return "" ;
- String tzStr = dts.timezone ;
+ return "";
+ String tzStr = dts.timezone;
if ( tzStr == null )
- tzStr = "" ;
- return tzStr ;
+ tzStr = "";
+ return tzStr;
}
/**
@@ -1272,150 +1272,150 @@ public class XSDFuncOp
*/
public static NodeValue dateTimeCast(NodeValue nv, XSDDatatype xsd) {
if ( nv.isString() ) {
- String s = nv.getString() ;
+ String s = nv.getString();
if ( ! xsd.isValid(s) )
- throw new ExprEvalTypeException("Invalid lexical form: '"+s+"' for "+xsd.getURI()) ;
- return NodeValue.makeNode(s, xsd) ;
+ throw new ExprEvalTypeException("Invalid lexical form: '"+s+"' for "+xsd.getURI());
+ return NodeValue.makeNode(s, xsd);
}
if ( !nv.hasDateTime() )
- throw new ExprEvalTypeException("Not a date/time type: " + nv) ;
+ throw new ExprEvalTypeException("Not a date/time type: " + nv);
- XMLGregorianCalendar xsdDT = nv.getDateTime() ;
+ XMLGregorianCalendar xsdDT = nv.getDateTime();
if ( XSDDatatype.XSDdateTime.equals(xsd) ) {
// ==> DateTime
if ( nv.isDateTime() )
- return nv ;
+ return nv;
if ( !nv.isDate() )
- throw new ExprEvalTypeException("Can't cast to XSD:dateTime: " + nv) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:dateTime: " + nv);
// DateTime with time 00:00:00 ... and timezone, if any
- String tzStr = tzStrFromNV(nv) ;
+ String tzStr = tzStrFromNV(nv);
String x = String.format("%04d-%02d-%02dT00:00:00%s", xsdDT.getYear(), xsdDT.getMonth(), xsdDT.getDay(),
- tzStr) ;
- return NodeValue.makeNode(x, xsd) ;
+ tzStr);
+ return NodeValue.makeNode(x, xsd);
}
if ( XSDDatatype.XSDdate.equals(xsd) ) {
// ==> Date
if ( nv.isDate() )
- return nv ;
+ return nv;
if ( !nv.isDateTime() )
- throw new ExprEvalTypeException("Can't cast to XSD:date: " + nv) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:date: " + nv);
// Timezone
- String tzStr = tzStrFromNV(nv) ;
- String x = String.format("%04d-%02d-%02d%s", xsdDT.getYear(), xsdDT.getMonth(), xsdDT.getDay(), tzStr) ;
- return NodeValue.makeNode(x, xsd) ;
+ String tzStr = tzStrFromNV(nv);
+ String x = String.format("%04d-%02d-%02d%s", xsdDT.getYear(), xsdDT.getMonth(), xsdDT.getDay(), tzStr);
+ return NodeValue.makeNode(x, xsd);
}
if ( XSDDatatype.XSDtime.equals(xsd) ) {
// ==> time
if ( nv.isTime() )
- return nv ;
+ return nv;
if ( !nv.isDateTime() )
- throw new ExprEvalTypeException("Can't cast to XSD:time: " + nv) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:time: " + nv);
// Careful formatting
- DateTimeStruct dts = parseAnyDT(nv) ;
+ DateTimeStruct dts = parseAnyDT(nv);
if ( dts.timezone == null )
- dts.timezone = "" ;
- String x = String.format("%s:%s:%s%s", dts.hour, dts.minute, dts.second, dts.timezone) ;
- return NodeValue.makeNode(x, xsd) ;
+ dts.timezone = "";
+ String x = String.format("%s:%s:%s%s", dts.hour, dts.minute, dts.second, dts.timezone);
+ return NodeValue.makeNode(x, xsd);
}
if ( XSDDatatype.XSDgYear.equals(xsd) ) {
// ==> Year
if ( nv.isGYear() )
- return nv ;
+ return nv;
if ( !nv.isDateTime() && !nv.isDate() )
- throw new ExprEvalTypeException("Can't cast to XSD:gYear: " + nv) ;
- String x = String.format("%04d", xsdDT.getYear()) ;
- return NodeValue.makeNode(x, xsd) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:gYear: " + nv);
+ String x = String.format("%04d", xsdDT.getYear());
+ return NodeValue.makeNode(x, xsd);
}
if ( XSDDatatype.XSDgYearMonth.equals(xsd) ) {
// ==> YearMonth
if ( nv.isGYearMonth() )
- return nv ;
+ return nv;
if ( !nv.isDateTime() && !nv.isDate() )
- throw new ExprEvalTypeException("Can't cast to XSD:gYearMonth: " + nv) ;
- String x = String.format("%04d-%02d", xsdDT.getYear(), xsdDT.getMonth()) ;
- return NodeValue.makeNode(x, xsd) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:gYearMonth: " + nv);
+ String x = String.format("%04d-%02d", xsdDT.getYear(), xsdDT.getMonth());
+ return NodeValue.makeNode(x, xsd);
}
if ( XSDDatatype.XSDgMonth.equals(xsd) ) {
// ==> Month
if ( nv.isGMonth() )
- return nv ;
+ return nv;
if ( !nv.isDateTime() && !nv.isDate() )
- throw new ExprEvalTypeException("Can't cast to XSD:gMonth: " + nv) ;
- String x = String.format("--%02d", xsdDT.getMonth()) ;
- return NodeValue.makeNode(x, xsd) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:gMonth: " + nv);
+ String x = String.format("--%02d", xsdDT.getMonth());
+ return NodeValue.makeNode(x, xsd);
}
if ( XSDDatatype.XSDgMonthDay.equals(xsd) ) {
// ==> MonthDay
if ( nv.isGMonthDay() )
- return nv ;
+ return nv;
if ( !nv.isDateTime() && !nv.isDate() )
- throw new ExprEvalTypeException("Can't cast to XSD:gMonthDay: " + nv) ;
- String x = String.format("--%02d-%02d", xsdDT.getMonth(), xsdDT.getDay()) ;
- return NodeValue.makeNode(x, xsd) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:gMonthDay: " + nv);
+ String x = String.format("--%02d-%02d", xsdDT.getMonth(), xsdDT.getDay());
+ return NodeValue.makeNode(x, xsd);
}
if ( XSDDatatype.XSDgDay.equals(xsd) ) {
// Day
if ( nv.isGDay() )
- return nv ;
+ return nv;
if ( !nv.isDateTime() && !nv.isDate() )
- throw new ExprEvalTypeException("Can't cast to XSD:gDay: " + nv) ;
- String x = String.format("---%02d", xsdDT.getDay()) ;
- return NodeValue.makeNode(x, xsd) ;
+ throw new ExprEvalTypeException("Can't cast to XSD:gDay: " + nv);
+ String x = String.format("---%02d", xsdDT.getDay());
+ return NodeValue.makeNode(x, xsd);
}
- throw new ExprEvalTypeException("Can't case to <" + xsd.getURI() + ">: " + nv) ;
+ throw new ExprEvalTypeException("Can't case to <" + xsd.getURI() + ">: " + nv);
}
// Get years/months/days/hours/minutes/seconds from any type we understands.
public static NodeValue getYear(NodeValue nv) {
- if ( nv.isDuration() ) return durGetYears(nv) ;
- return dtGetYear(nv) ;
+ if ( nv.isDuration() ) return durGetYears(nv);
+ return dtGetYear(nv);
}
public static NodeValue getMonth(NodeValue nv) {
- if ( nv.isDuration() ) return durGetMonths(nv) ;
- return dtGetMonth(nv) ;
+ if ( nv.isDuration() ) return durGetMonths(nv);
+ return dtGetMonth(nv);
}
public static NodeValue getDay(NodeValue nv) {
- if ( nv.isDuration() ) return XSDFuncOp.durGetDays(nv) ;
- return dtGetDay(nv) ;
+ if ( nv.isDuration() ) return XSDFuncOp.durGetDays(nv);
+ return dtGetDay(nv);
}
public static NodeValue getHours(NodeValue nv) {
- if ( nv.isDuration() ) return XSDFuncOp.durGetHours(nv) ;
- return dtGetHours(nv) ;
+ if ( nv.isDuration() ) return XSDFuncOp.durGetHours(nv);
+ return dtGetHours(nv);
}
public static NodeValue getMinutes(NodeValue nv) {
- if ( nv.isDuration() ) return XSDFuncOp.durGetMinutes(nv) ;
- return dtGetMinutes(nv) ;
+ if ( nv.isDuration() ) return XSDFuncOp.durGetMinutes(nv);
+ return dtGetMinutes(nv);
}
public static NodeValue getSeconds(NodeValue nv) {
- if ( nv.isDuration() ) return XSDFuncOp.durGetSeconds(nv) ;
- return dtGetSeconds(nv) ;
+ if ( nv.isDuration() ) return XSDFuncOp.durGetSeconds(nv);
+ return dtGetSeconds(nv);
}
/** Create an xsd:dateTime from an xsd:date and an xsd:time. */
public static NodeValue dtDateTime(NodeValue nv1, NodeValue nv2) {
if ( ! nv1.isDate() )
- throw new ExprEvalException("fn:dateTime: arg1: Not an xsd:date: "+nv1) ;
+ throw new ExprEvalException("fn:dateTime: arg1: Not an xsd:date: "+nv1);
if ( ! nv2.isTime() )
- throw new ExprEvalException("fn:dateTime: arg2: Not an xsd:time: "+nv2) ;
- String lex1 = nv1.asNode().getLiteralLexicalForm() ;
- String lex2 = nv2.asNode().getLiteralLexicalForm() ;
+ throw new ExprEvalException("fn:dateTime: arg2: Not an xsd:time: "+nv2);
+ String lex1 = nv1.asNode().getLiteralLexicalForm();
+ String lex2 = nv2.asNode().getLiteralLexicalForm();
DateTimeStruct dts1 = DateTimeStruct.parseDate(lex1);
DateTimeStruct dts2 = DateTimeStruct.parseTime(lex2);
@@ -1437,201 +1437,200 @@ public class XSDFuncOp
// Accessors: datetime, date, Gregorian.
public static NodeValue dtGetYear(NodeValue nv) {
if ( nv.isDateTime() || nv.isDate() || nv.isGYear() || nv.isGYearMonth() ) {
- DateTimeStruct dts = parseAnyDT(nv) ;
+ DateTimeStruct dts = parseAnyDT(nv);
if ( dts.neg != null )
- return NodeValue.makeNode("-"+dts.year, XSDDatatype.XSDinteger) ;
- return NodeValue.makeNode(dts.year, XSDDatatype.XSDinteger) ;
+ return NodeValue.makeNode("-"+dts.year, XSDDatatype.XSDinteger);
+ return NodeValue.makeNode(dts.year, XSDDatatype.XSDinteger);
}
- throw new ExprEvalException("Not a year datatype") ;
+ throw new ExprEvalException("Not a year datatype");
}
public static NodeValue dtGetMonth(NodeValue nv) {
if ( nv.isDateTime() || nv.isDate() || nv.isGYearMonth() || nv.isGMonth() || nv.isGMonthDay() ) {
- DateTimeStruct dts = parseAnyDT(nv) ;
- return NodeValue.makeNode(dts.month, XSDDatatype.XSDinteger) ;
+ DateTimeStruct dts = parseAnyDT(nv);
+ return NodeValue.makeNode(dts.month, XSDDatatype.XSDinteger);
}
- throw new ExprEvalException("Not a month datatype") ;
+ throw new ExprEvalException("Not a month datatype");
}
public static NodeValue dtGetDay(NodeValue nv) {
if ( nv.isDateTime() || nv.isDate() || nv.isGMonthDay() || nv.isGDay() ) {
- DateTimeStruct dts = parseAnyDT(nv) ;
- return NodeValue.makeNode(dts.day, XSDDatatype.XSDinteger) ;
+ DateTimeStruct dts = parseAnyDT(nv);
+ return NodeValue.makeNode(dts.day, XSDDatatype.XSDinteger);
}
- throw new ExprEvalException("Not a day datatype") ;
+ throw new ExprEvalException("Not a day datatype");
}
private static DateTimeStruct parseAnyDT(NodeValue nv) {
- String lex = nv.asNode().getLiteralLexicalForm() ;
+ String lex = nv.asNode().getLiteralLexicalForm();
if ( nv.isDateTime() )
- return DateTimeStruct.parseDateTime(lex) ;
+ return DateTimeStruct.parseDateTime(lex);
if ( nv.isDate() )
- return DateTimeStruct.parseDate(lex) ;
+ return DateTimeStruct.parseDate(lex);
if ( nv.isGYear() )
- return DateTimeStruct.parseGYear(lex) ;
+ return DateTimeStruct.parseGYear(lex);
if ( nv.isGYearMonth() )
- return DateTimeStruct.parseGYearMonth(lex) ;
+ return DateTimeStruct.parseGYearMonth(lex);
if ( nv.isGMonth() )
- return DateTimeStruct.parseGMonth(lex) ;
+ return DateTimeStruct.parseGMonth(lex);
if ( nv.isGMonthDay() )
- return DateTimeStruct.parseGMonthDay(lex) ;
+ return DateTimeStruct.parseGMonthDay(lex);
if ( nv.isGDay() )
- return DateTimeStruct.parseGDay(lex) ;
+ return DateTimeStruct.parseGDay(lex);
if ( nv.isTime() )
- return DateTimeStruct.parseTime(lex) ;
- return null ;
+ return DateTimeStruct.parseTime(lex);
+ return null;
}
private static DateTimeStruct parseTime(NodeValue nv) {
- String lex = nv.asNode().getLiteralLexicalForm() ;
+ String lex = nv.asNode().getLiteralLexicalForm();
if ( nv.isDateTime() )
- return DateTimeStruct.parseDateTime(lex) ;
+ return DateTimeStruct.parseDateTime(lex);
else if ( nv.isTime() )
- return DateTimeStruct.parseTime(lex) ;
+ return DateTimeStruct.parseTime(lex);
else
- throw new ExprEvalException("Not a datatype for time") ;
+ throw new ExprEvalException("Not a datatype for time");
}
public static NodeValue dtGetHours(NodeValue nv) {
- DateTimeStruct dts = parseTime(nv) ;
- return NodeValue.makeNode(dts.hour, XSDDatatype.XSDinteger) ;
+ DateTimeStruct dts = parseTime(nv);
+ return NodeValue.makeNode(dts.hour, XSDDatatype.XSDinteger);
}
public static NodeValue dtGetMinutes(NodeValue nv) {
- DateTimeStruct dts = parseTime(nv) ;
- return NodeValue.makeNode(dts.minute, XSDDatatype.XSDinteger) ;
+ DateTimeStruct dts = parseTime(nv);
+ return NodeValue.makeNode(dts.minute, XSDDatatype.XSDinteger);
}
public static NodeValue dtGetSeconds(NodeValue nv) {
- DateTimeStruct dts = parseTime(nv) ;
- return NodeValue.makeNode(dts.second, XSDDatatype.XSDdecimal) ;
+ DateTimeStruct dts = parseTime(nv);
+ return NodeValue.makeNode(dts.second, XSDDatatype.XSDdecimal);
}
public static NodeValue dtGetTZ(NodeValue nv) {
- DateTimeStruct dts = parseAnyDT(nv) ;
+ DateTimeStruct dts = parseAnyDT(nv);
if ( dts == null )
- throw new ExprEvalException("Not a data/time value: " + nv) ;
+ throw new ExprEvalException("Not a data/time value: " + nv);
if ( dts.timezone == null )
- return NodeValue.nvEmptyString ;
- return NodeValue.makeString(dts.timezone) ;
+ return NodeValue.nvEmptyString;
+ return NodeValue.makeString(dts.timezone);
}
public static NodeValue dtGetTimezone(NodeValue nv) {
- DateTimeStruct dts = parseAnyDT(nv) ;
+ DateTimeStruct dts = parseAnyDT(nv);
if ( dts == null || dts.timezone == null )
- throw new ExprEvalException("Not a datatype with a timezone: " + nv) ;
+ throw new ExprEvalException("Not a datatype with a timezone: " + nv);
if ( "".equals(dts.timezone) )
- return null ;
+ return null;
if ( "Z".equals(dts.timezone) ) {
- Node n = NodeFactory.createLiteralDT("PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration")) ;
- return NodeValue.makeNode(n) ;
+ Node n = NodeFactory.createLiteralDT("PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration"));
+ return NodeValue.makeNode(n);
}
if ( "+00:00".equals(dts.timezone) ) {
- Node n = NodeFactory.createLiteralDT("PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration")) ;
- return NodeValue.makeNode(n) ;
+ Node n = NodeFactory.createLiteralDT("PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration"));
+ return NodeValue.makeNode(n);
}
if ( "-00:00".equals(dts.timezone) ) {
- Node n = NodeFactory.createLiteralDT("-PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration")) ;
- return NodeValue.makeNode(n) ;
+ Node n = NodeFactory.createLiteralDT("-PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration"));
+ return NodeValue.makeNode(n);
}
- String s = dts.timezone ;
- int idx = 0 ;
- StringBuilder sb = new StringBuilder() ;
+ String s = dts.timezone;
+ int idx = 0;
+ StringBuilder sb = new StringBuilder();
if ( s.charAt(0) == '-' )
- sb.append('-') ;
- idx++ ; // Skip '-' or '+'
- sb.append("PT") ;
- digitsTwo(s, idx, sb, 'H') ;
- idx += 2 ;
- idx++ ; // The ":"
- digitsTwo(s, idx, sb, 'M') ;
- idx += 2 ;
- return NodeValue.makeNode(sb.toString(), null, XSDDatatype.XSD + "#dayTimeDuration") ;
+ sb.append('-');
+ idx++; // Skip '-' or '+'
+ sb.append("PT");
+ digitsTwo(s, idx, sb, 'H');
+ idx += 2;
+ idx++; // The ":"
+ digitsTwo(s, idx, sb, 'M');
+ idx += 2;
+ return NodeValue.makeNode(sb.toString(), null, XSDDatatype.XSD + "#dayTimeDuration");
}
private static void digitsTwo(String s, int idx, StringBuilder sb, char indicator) {
if ( s.charAt(idx) == '0' ) {
- idx++ ;
+ idx++;
if ( s.charAt(idx) != '0' ) {
- sb.append(s.charAt(idx)) ;
- sb.append(indicator) ;
+ sb.append(s.charAt(idx));
+ sb.append(indicator);
}
- idx++ ;
+ idx++;
} else {
- sb.append(s.charAt(idx)) ;
- idx++ ;
- sb.append(s.charAt(idx)) ;
- idx++ ;
- sb.append(indicator) ;
+ sb.append(s.charAt(idx));
+ idx++;
+ sb.append(s.charAt(idx));
+ idx++;
+ sb.append(indicator);
}
}
public static boolean isYearMonth(Duration dur) {
// Not dur.getXMLSchemaType()
return (dur.isSet(YEARS) || dur.isSet(MONTHS)) && !dur.isSet(DAYS) && !dur.isSet(HOURS) && !dur.isSet(MINUTES)
- && !dur.isSet(SECONDS) ;
+ && !dur.isSet(SECONDS);
}
public static boolean isDayTime(Duration dur) {
return !dur.isSet(YEARS) && !dur.isSet(MONTHS)
- && (dur.isSet(DAYS) || dur.isSet(HOURS) || dur.isSet(MINUTES) || dur.isSet(SECONDS)) ;
+ && (dur.isSet(DAYS) || dur.isSet(HOURS) || dur.isSet(MINUTES) || dur.isSet(SECONDS));
}
// ---- Durations
public static NodeValue durGetYears(NodeValue nv) {
- return accessDuration(nv, DatatypeConstants.YEARS) ;
+ return accessDuration(nv, DatatypeConstants.YEARS);
}
public static NodeValue durGetMonths(NodeValue nv) {
- return accessDuration(nv, DatatypeConstants.MONTHS) ;
+ return accessDuration(nv, DatatypeConstants.MONTHS);
}
public static NodeValue durGetDays(NodeValue nv) {
- return accessDuration(nv, DatatypeConstants.DAYS) ;
+ return accessDuration(nv, DatatypeConstants.DAYS);
}
public static NodeValue durGetHours(NodeValue nv) {
- return accessDuration(nv, DatatypeConstants.HOURS) ;
+ return accessDuration(nv, DatatypeConstants.HOURS);
}
public static NodeValue durGetMinutes(NodeValue nv) {
- return accessDuration(nv, DatatypeConstants.MINUTES) ;
+ return accessDuration(nv, DatatypeConstants.MINUTES);
}
public static NodeValue durGetSeconds(NodeValue nv) {
- return accessDuration(nv, DatatypeConstants.SECONDS) ;
+ return accessDuration(nv, DatatypeConstants.SECONDS);
}
public static NodeValue durGetSign(NodeValue nv) {
- int x = nv.getDuration().getSign() ;
- return NodeValue.makeInteger(x) ;
+ int x = nv.getDuration().getSign();
+ return NodeValue.makeInteger(x);
}
private static NodeValue accessDuration(NodeValue nv, Field field) {
Duration dur = nv.getDuration();
// if ( ! nv.isDuration() )
- // throw new ExprEvalException("Not a duration: "+nv) ;
- Number x = dur.getField(field) ;
+ // throw new ExprEvalException("Not a duration: "+nv);
+ Number x = dur.getField(field);
if ( x == null ) {
x = field.equals(DatatypeConstants.SECONDS)
? BigDecimal.ZERO
- : BigInteger.ZERO ;
+ : BigInteger.ZERO;
}
if ( field.equals(DatatypeConstants.SECONDS) )
- return NodeValue.makeDecimal((BigDecimal)x) ;
+ return NodeValue.makeDecimal((BigDecimal)x);
- return NodeValue.makeInteger((BigInteger)x) ;
+ return NodeValue.makeInteger((BigInteger)x);
}
- private static Duration duration1day = NodeValue.xmlDatatypeFactory.newDuration(true,
- BigInteger.ZERO, BigInteger.ZERO, BigInteger.ONE,
- BigInteger.ZERO, BigInteger.ZERO, BigDecimal.ZERO) ;
+ /** One day */
+ private static Duration duration1day = NodeValue.xmlDatatypeFactory.newDuration(true, null, null, BigInteger.ONE, null, null, null);
public static int compareDuration(NodeValue nv1, NodeValue nv2) {
- return compareDuration(nv1.getDuration(), nv2.getDuration()) ;
+ return compareDuration(nv1.getDuration(), nv2.getDuration());
}
private static int compareDuration(Duration duration1, Duration duration2) {
@@ -1640,7 +1639,7 @@ public class XSDFuncOp
return XSDDuration.durationCompare(duration1, duration2);
}
- public static final String implicitTimezoneStr = "Z" ;
+ public static final String implicitTimezoneStr = "Z";
private static final NodeValue implicitTimezone_ = NodeValue.makeNode("PT0S", XSDDatatype.XSDdayTimeDuration);
// minutes are used for the timezone in XMLGregorianCalendar
@@ -1739,36 +1738,36 @@ public class XSDFuncOp
*/
public static NodeValue formatNumber(NodeValue nv, NodeValue picture, NodeValue nvLocale) {
if ( !nv.isNumber() )
- NodeValue.raise(new ExprEvalException("Not a number: " + nv)) ;
+ NodeValue.raise(new ExprEvalException("Not a number: " + nv));
if ( !picture.isString() )
- NodeValue.raise(new ExprEvalException("Not a string: " + picture)) ;
+ NodeValue.raise(new ExprEvalException("Not a string: " + picture));
if ( nvLocale != null && !nvLocale.isString() )
- NodeValue.raise(new ExprEvalException("Not a string: " + nvLocale)) ;
+ NodeValue.raise(new ExprEvalException("Not a string: " + nvLocale));
- Locale locale = Locale.ROOT ;
+ Locale locale = Locale.ROOT;
if ( nvLocale != null )
- locale = Locale.forLanguageTag(nvLocale.asString()) ;
- DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale) ;
+ locale = Locale.forLanguageTag(nvLocale.asString());
+ DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale);
NumberFormat formatter =
(dfs == null )
? new DecimalFormat(picture.getString())
- : new DecimalFormat(picture.getString(), dfs) ;
+ : new DecimalFormat(picture.getString(), dfs);
- NumericType nt = XSDFuncOp.classifyNumeric("fn:formatNumber", nv) ;
- String s = null ;
+ NumericType nt = XSDFuncOp.classifyNumeric("fn:formatNumber", nv);
+ String s = null;
switch(nt) {
case OP_DECIMAL :
case OP_DOUBLE :
case OP_FLOAT :
- s = formatter.format(nv.getDouble()) ;
- break ;
+ s = formatter.format(nv.getDouble());
+ break;
case OP_INTEGER :
- s = formatter.format(nv.getInteger().longValue()) ;
- break ;
+ s = formatter.format(nv.getInteger().longValue());
+ break;
default :
- break ;
+ break;
}
- return NodeValue.makeString(s) ;
+ return NodeValue.makeString(s);
}
}
(jena) 04/05: JenaSystem.init with optional tracing
Posted by an...@apache.org.
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 0a07f63e6bf91e6add5df3ea5e95af08c36322c2
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Thu Nov 28 11:51:43 2024 +0000
JenaSystem.init with optional tracing
---
.../main/java/org/apache/jena/sys/JenaSystem.java | 44 +++++++++++++++-------
1 file changed, 31 insertions(+), 13 deletions(-)
diff --git a/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java b/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
index 5602bcbf56..417d4c3c33 100644
--- a/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
+++ b/jena-core/src/main/java/org/apache/jena/sys/JenaSystem.java
@@ -46,18 +46,6 @@ public class JenaSystem {
private static Subsystem<JenaSubsystemLifecycle> singleton = null;
- // Don't rely on class initialization.
- private static void setup() {
- // Called inside synchronized
- if ( singleton == null ) {
- singleton = new Subsystem<>(JenaSubsystemLifecycle.class);
- SubsystemRegistry<JenaSubsystemLifecycle> reg =
- new SubsystemRegistryServiceLoader<>(JenaSubsystemLifecycle.class);
- singleton.setSubsystemRegistry(reg);
- reg.add(new JenaInitLevel0());
- }
- }
-
public JenaSystem() { }
/**
@@ -76,13 +64,34 @@ public class JenaSystem {
System.err.println() ;
}
+ /**
+ * Initialize Jena. This call can be made several times. Only the first causes
+ * the one-time initialization.
+ */
public static void init() {
+ init(false);
+ }
+
+ /**
+ * Initialize Jena. This call can be made several times. Only the first causes
+ * the one-time initialization.
+ * <p>
+ * Optionally, output initialization steps (prints to stderr).
+ */
+ public static void init(boolean withTracing) {
if ( initialized )
return ;
+ if ( withTracing )
+ DEBUG_INIT = true;
+
// Access the initialized flag to trigger class loading
var unused = LazyInitializer.IS_INITIALIZED;
}
+ public static void shutdown() {
+ singleton.shutdown();
+ }
+
private static class LazyInitializer {
static final boolean IS_INITIALIZED = jenaSystemInitialization();
@@ -97,7 +106,16 @@ public class JenaSystem {
}
}
- public static void shutdown() { singleton.shutdown(); }
+ private static void setup() {
+ // Called inside synchronized
+ if ( singleton == null ) {
+ singleton = new Subsystem<>(JenaSubsystemLifecycle.class);
+ SubsystemRegistry<JenaSubsystemLifecycle> reg =
+ new SubsystemRegistryServiceLoader<>(JenaSubsystemLifecycle.class);
+ singleton.setSubsystemRegistry(reg);
+ reg.add(new JenaInitLevel0());
+ }
+ }
/** The level 0 subsystem - inserted without using the Registry load function.
* There should be only one such level 0 handler.