@Test public void testEvaluateBigDecimal() { try { BigDecimal bd = new BigDecimal(1234567.567); Literal rounded = round.evaluate(f, f.createLiteral(bd.toPlainString(), XMLSchema.DECIMAL)); BigDecimal roundValue = rounded.decimalValue(); assertEquals(new BigDecimal(1234568.0), roundValue); } catch (ValueExprEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException("ROUND requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (datatype != null && XMLDatatypeUtil.isNumericDatatype(datatype)) { if (XMLDatatypeUtil.isIntegerDatatype(datatype)) { return literal; } else if (XMLDatatypeUtil.isDecimalDatatype(datatype)) { BigDecimal rounded = literal.decimalValue().setScale(0, RoundingMode.HALF_UP); return valueFactory.createLiteral(rounded.toPlainString(), datatype); } else if (XMLDatatypeUtil.isFloatingPointDatatype(datatype)) { double ceilingValue = Math.round(literal.doubleValue()); return valueFactory.createLiteral(Double.toString(ceilingValue), datatype); } else { throw new ValueExprEvaluationException("unexpected datatype for function operand: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } }
Round implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException("ROUND requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (datatype != null && XMLDatatypeUtil.isNumericDatatype(datatype)) { if (XMLDatatypeUtil.isIntegerDatatype(datatype)) { return literal; } else if (XMLDatatypeUtil.isDecimalDatatype(datatype)) { BigDecimal rounded = literal.decimalValue().setScale(0, RoundingMode.HALF_UP); return valueFactory.createLiteral(rounded.toPlainString(), datatype); } else if (XMLDatatypeUtil.isFloatingPointDatatype(datatype)) { double ceilingValue = Math.round(literal.doubleValue()); return valueFactory.createLiteral(Double.toString(ceilingValue), datatype); } else { throw new ValueExprEvaluationException("unexpected datatype for function operand: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } } }
Round implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException("ROUND requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (datatype != null && XMLDatatypeUtil.isNumericDatatype(datatype)) { if (XMLDatatypeUtil.isIntegerDatatype(datatype)) { return literal; } else if (XMLDatatypeUtil.isDecimalDatatype(datatype)) { BigDecimal rounded = literal.decimalValue().setScale(0, RoundingMode.HALF_UP); return valueFactory.createLiteral(rounded.toPlainString(), datatype); } else if (XMLDatatypeUtil.isFloatingPointDatatype(datatype)) { double ceilingValue = Math.round(literal.doubleValue()); return valueFactory.createLiteral(Double.toString(ceilingValue), datatype); } else { throw new ValueExprEvaluationException("unexpected datatype for function operand: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } }  }
Round implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException("ROUND requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (datatype != null && XMLDatatypeUtil.isNumericDatatype(datatype)) { if (XMLDatatypeUtil.isIntegerDatatype(datatype)) { return literal; } else if (XMLDatatypeUtil.isDecimalDatatype(datatype)) { BigDecimal rounded = literal.decimalValue().setScale(0, RoundingMode.HALF_UP); return valueFactory.createLiteral(rounded.toPlainString(), datatype); } else if (XMLDatatypeUtil.isFloatingPointDatatype(datatype)) { double ceilingValue = Math.round(literal.doubleValue()); return valueFactory.createLiteral(Double.toString(ceilingValue), datatype); } else { throw new ValueExprEvaluationException("unexpected datatype for function operand: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } }  @Override String getURI(); @Override Literal evaluate(ValueFactory valueFactory, Value... args); }
Round implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException("ROUND requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (datatype != null && XMLDatatypeUtil.isNumericDatatype(datatype)) { if (XMLDatatypeUtil.isIntegerDatatype(datatype)) { return literal; } else if (XMLDatatypeUtil.isDecimalDatatype(datatype)) { BigDecimal rounded = literal.decimalValue().setScale(0, RoundingMode.HALF_UP); return valueFactory.createLiteral(rounded.toPlainString(), datatype); } else if (XMLDatatypeUtil.isFloatingPointDatatype(datatype)) { double ceilingValue = Math.round(literal.doubleValue()); return valueFactory.createLiteral(Double.toString(ceilingValue), datatype); } else { throw new ValueExprEvaluationException("unexpected datatype for function operand: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } } else { throw new ValueExprEvaluationException("unexpected input value for function: " + args[0]); } }  @Override String getURI(); @Override Literal evaluate(ValueFactory valueFactory, Value... args);  }