use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class XSDFuncOp method roundXpath3.
public static NodeValue roundXpath3(NodeValue v, NodeValue precision, boolean isHalfEven) {
if (!precision.isInteger()) {
throw new ExprEvalTypeException("The precision for rounding should be an integer");
}
int precisionInt = precision.getInteger().intValue();
String fName = isHalfEven ? "round-half-to-even" : "round";
switch(classifyNumeric(fName, v)) {
case OP_INTEGER:
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));
case OP_FLOAT:
BigDecimal decFromFloat = roundDecimalValue(new BigDecimal(v.getFloat()), precisionInt, isHalfEven);
return NodeValue.makeFloat(decFromFloat.floatValue());
case OP_DOUBLE:
BigDecimal decFromDouble = roundDecimalValue(new BigDecimal(v.getDouble()), precisionInt, isHalfEven);
return NodeValue.makeDouble(decFromDouble.doubleValue());
default:
throw new ARQInternalErrorException("Unrecognized numeric operation : " + v);
}
}
use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class XSDFuncOp method fixupDateTime.
private static NodeValue fixupDateTime(NodeValue nv) {
DateTimeStruct dts = DateTimeStruct.parseDateTime(nv.asNode().getLiteralLexicalForm());
if (dts.timezone != null)
return null;
dts.timezone = defaultTimezone;
nv = NodeValue.makeDateTime(dts.toString());
if (!nv.isDateTime())
throw new ARQInternalErrorException("Failed to reform an xsd:dateTime");
return nv;
}
use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class XSDFuncOp method round.
public static NodeValue round(NodeValue v) {
switch(classifyNumeric("round", v)) {
case OP_INTEGER:
return v;
case OP_DECIMAL:
int sgn = v.getDecimal().signum();
BigDecimal dec;
if (sgn < 0)
dec = v.getDecimal().setScale(0, BigDecimal.ROUND_HALF_DOWN);
else
dec = v.getDecimal().setScale(0, BigDecimal.ROUND_HALF_UP);
return NodeValue.makeDecimal(dec);
case OP_FLOAT:
return NodeValue.makeFloat(Math.round(v.getFloat()));
case OP_DOUBLE:
return NodeValue.makeDouble(Math.round(v.getDouble()));
default:
throw new ARQInternalErrorException("Unrecognized numeric operation : " + v);
}
}
use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class AggregatorBase method getValue.
public Node getValue(Binding key) {
Accumulator acc = buckets.get(key);
if (acc == null)
throw new ARQInternalErrorException("Null for accumulator");
NodeValue nv = acc.getValue();
if (nv == null)
return null;
return nv.asNode();
}
Aggregations