@Test public void testCompute() throws Exception { Literal float1 = vf.createLiteral("12", XMLSchema.INTEGER); Literal float2 = vf.createLiteral("2", XMLSchema.INTEGER); Literal duration1 = vf.createLiteral("P1Y1M", XMLSchema.YEARMONTHDURATION); Literal duration2 = vf.createLiteral("P1Y", XMLSchema.YEARMONTHDURATION); Literal yearMonth1 = vf.createLiteral("2012-10", XMLSchema.GYEARMONTH); assertComputeEquals(vf.createLiteral("14", XMLSchema.INTEGER), float1, float2, MathOp.PLUS); assertComputeEquals(vf.createLiteral("10", XMLSchema.INTEGER), float1, float2, MathOp.MINUS); assertComputeEquals(vf.createLiteral("24", XMLSchema.INTEGER), float1, float2, MathOp.MULTIPLY); assertComputeEquals(vf.createLiteral("6", XMLSchema.DECIMAL), float1, float2, MathOp.DIVIDE); assertComputeEquals(vf.createLiteral("P2Y1M", XMLSchema.YEARMONTHDURATION), duration1, duration2, MathOp.PLUS); assertComputeEquals(vf.createLiteral("P0Y1M", XMLSchema.YEARMONTHDURATION), duration1, duration2, MathOp.MINUS); assertComputeEquals(vf.createLiteral("P12Y", XMLSchema.YEARMONTHDURATION), float1, duration2, MathOp.MULTIPLY); assertComputeEquals(vf.createLiteral("P12Y", XMLSchema.YEARMONTHDURATION), duration2, float1, MathOp.MULTIPLY); assertComputeEquals(vf.createLiteral("2013-11", XMLSchema.GYEARMONTH), yearMonth1, duration1, MathOp.PLUS); assertComputeEquals(vf.createLiteral("2011-09", XMLSchema.GYEARMONTH), yearMonth1, duration1, MathOp.MINUS); assertComputeEquals(vf.createLiteral("2013-11", XMLSchema.GYEARMONTH), duration1, yearMonth1, MathOp.PLUS); }
public static Literal compute(Literal leftLit, Literal rightLit, MathOp op) throws ValueExprEvaluationException { IRI leftDatatype = leftLit.getDatatype(); IRI rightDatatype = rightLit.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(leftDatatype) && XMLDatatypeUtil.isNumericDatatype(rightDatatype)) { return MathUtil.compute(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurations(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDecimalDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(rightLit, leftLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDecimalDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isCalendarDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenCalendarAndDuration(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isCalendarDatatype(rightDatatype)) { return operationsBetweenDurationAndCalendar(leftLit, rightLit, op); } else { throw new ValueExprEvaluationException("Mathematical operators are not supported on these operands"); } }
XMLDatatypeMathUtil { public static Literal compute(Literal leftLit, Literal rightLit, MathOp op) throws ValueExprEvaluationException { IRI leftDatatype = leftLit.getDatatype(); IRI rightDatatype = rightLit.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(leftDatatype) && XMLDatatypeUtil.isNumericDatatype(rightDatatype)) { return MathUtil.compute(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurations(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDecimalDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(rightLit, leftLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDecimalDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isCalendarDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenCalendarAndDuration(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isCalendarDatatype(rightDatatype)) { return operationsBetweenDurationAndCalendar(leftLit, rightLit, op); } else { throw new ValueExprEvaluationException("Mathematical operators are not supported on these operands"); } } }
XMLDatatypeMathUtil { public static Literal compute(Literal leftLit, Literal rightLit, MathOp op) throws ValueExprEvaluationException { IRI leftDatatype = leftLit.getDatatype(); IRI rightDatatype = rightLit.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(leftDatatype) && XMLDatatypeUtil.isNumericDatatype(rightDatatype)) { return MathUtil.compute(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurations(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDecimalDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(rightLit, leftLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDecimalDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isCalendarDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenCalendarAndDuration(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isCalendarDatatype(rightDatatype)) { return operationsBetweenDurationAndCalendar(leftLit, rightLit, op); } else { throw new ValueExprEvaluationException("Mathematical operators are not supported on these operands"); } }  }
XMLDatatypeMathUtil { public static Literal compute(Literal leftLit, Literal rightLit, MathOp op) throws ValueExprEvaluationException { IRI leftDatatype = leftLit.getDatatype(); IRI rightDatatype = rightLit.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(leftDatatype) && XMLDatatypeUtil.isNumericDatatype(rightDatatype)) { return MathUtil.compute(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurations(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDecimalDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(rightLit, leftLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDecimalDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isCalendarDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenCalendarAndDuration(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isCalendarDatatype(rightDatatype)) { return operationsBetweenDurationAndCalendar(leftLit, rightLit, op); } else { throw new ValueExprEvaluationException("Mathematical operators are not supported on these operands"); } }  static Literal compute(Literal leftLit, Literal rightLit, MathOp op); }
XMLDatatypeMathUtil { public static Literal compute(Literal leftLit, Literal rightLit, MathOp op) throws ValueExprEvaluationException { IRI leftDatatype = leftLit.getDatatype(); IRI rightDatatype = rightLit.getDatatype(); if (XMLDatatypeUtil.isNumericDatatype(leftDatatype) && XMLDatatypeUtil.isNumericDatatype(rightDatatype)) { return MathUtil.compute(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurations(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDecimalDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(rightLit, leftLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isDecimalDatatype(rightDatatype)) { return operationsBetweenDurationAndDecimal(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isCalendarDatatype(leftDatatype) && XMLDatatypeUtil.isDurationDatatype(rightDatatype)) { return operationsBetweenCalendarAndDuration(leftLit, rightLit, op); } else if (XMLDatatypeUtil.isDurationDatatype(leftDatatype) && XMLDatatypeUtil.isCalendarDatatype(rightDatatype)) { return operationsBetweenDurationAndCalendar(leftLit, rightLit, op); } else { throw new ValueExprEvaluationException("Mathematical operators are not supported on these operands"); } }  static Literal compute(Literal leftLit, Literal rightLit, MathOp op);  }