Search in sources :

Example 31 with ARQInternalErrorException

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);
    }
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) BigDecimal(java.math.BigDecimal)

Example 32 with ARQInternalErrorException

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;
}
Also used : DateTimeStruct(org.apache.jena.sparql.util.DateTimeStruct) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 33 with ARQInternalErrorException

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);
    }
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) BigDecimal(java.math.BigDecimal)

Example 34 with ARQInternalErrorException

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();
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Aggregations

ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)34 Node (org.apache.jena.graph.Node)6 NodeValue (org.apache.jena.sparql.expr.NodeValue)6 ArrayList (java.util.ArrayList)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 Var (org.apache.jena.sparql.core.Var)4 BigDecimal (java.math.BigDecimal)3 BasicPattern (org.apache.jena.sparql.core.BasicPattern)3 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)3 BigInteger (java.math.BigInteger)2 CmdException (jena.cmd.CmdException)2 TerminationException (jena.cmd.TerminationException)2 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)2 Graph (org.apache.jena.graph.Graph)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 JenaException (org.apache.jena.shared.JenaException)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)2