use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class BindingComparator method compare.
// Compare bindings by iterating.
// Node comparsion is:
// Compare by
@Override
public int compare(Binding bind1, Binding bind2) {
for (SortCondition sc : conditions) {
if (sc.expression == null) {
throw new QueryExecException("Broken sort condition");
}
NodeValue nv1 = null;
NodeValue nv2 = null;
try {
nv1 = sc.expression.eval(bind1, env);
} catch (VariableNotBoundException ex) {
} catch (ExprEvalException ex) {
Log.warn(this, ex.getMessage());
}
try {
nv2 = sc.expression.eval(bind2, env);
} catch (VariableNotBoundException ex) {
} catch (ExprEvalException ex) {
Log.warn(this, ex.getMessage());
}
Node n1 = NodeValue.toNode(nv1);
Node n2 = NodeValue.toNode(nv2);
int x = compareNodes(nv1, nv2, sc.direction);
if (x != Expr.CMP_EQUAL) {
return x;
}
}
// Same by the SortConditions - now do any extra tests to make sure they are unique.
return compareBindingsSyntactic(bind1, bind2);
//return 0 ;
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class date method exec.
@Override
public NodeValue exec(NodeValue v) {
if (!v.isString()) {
Log.warn(this, "date: argument not a string: " + v);
throw new ExprEvalException("date: argument not a string: " + v);
}
String lexicalForm = v.getString();
// Quite picky about format
if (!lexicalForm.matches("\\d{4}-\\d{2}-\\d{2}")) {
Log.warn(this, "date: argument not in date format: " + v);
throw new ExprEvalException("date: argument not in date format: " + v);
}
lexicalForm = lexicalForm + "T00:00:00Z";
NodeValue nv = NodeValue.makeNode(lexicalForm, XSDDatatype.XSDdateTime);
return nv;
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class evenInteger method exec.
@Override
public NodeValue exec(NodeValue x) {
if (!x.isInteger())
throw new ExprEvalException("evenInteger: Not an intger: " + x);
int i = x.getInteger().getLowestSetBit();
boolean b = (i == -1) || (i != 0);
return NodeValue.makeNodeBoolean(b);
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class factorial method exec.
@Override
public NodeValue exec(NodeValue v) {
BigInteger i = v.getInteger();
switch(i.compareTo(BigInteger.ZERO)) {
case 0:
// 0! is 1
return NodeValue.makeInteger(BigInteger.ONE);
case -1:
// Negative factorial is error
throw new ExprEvalException("Cannot evaluate a negative factorial");
case 1:
BigInteger res = i.add(BigInteger.ZERO);
i = i.subtract(BigInteger.ONE);
while (i.compareTo(BigInteger.ZERO) != 0) {
res = res.multiply(i);
i = i.subtract(BigInteger.ONE);
}
return NodeValue.makeInteger(res);
default:
throw new ExprEvalException("Unexpecte comparison result");
}
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class sprintf method exec.
@Override
public NodeValue exec(List<NodeValue> args) {
if (args.size() < 2)
throw new ExprEvalException(Lib.className(this) + ": Wrong number of arguments: " + args.size() + " : [wanted at least 2]");
NodeValue v1 = args.get(0);
List<NodeValue> allArgs = new ArrayList<>();
for (int i = 1; i < args.size(); i++) allArgs.add(args.get(i));
return XSDFuncOp.javaSprintf(v1, allArgs);
}
Aggregations