use of com.bigdata.rdf.error.SparqlTypeErrorException in project wikidata-query-rdf by wikimedia.
the class WikibaseDateExtension method doMathOp.
@SuppressWarnings({ "rawtypes", "checkstyle:cyclomaticcomplexity", "checkstyle:NPathComplexity" })
@SuppressFBWarnings(value = "LEST_LOST_EXCEPTION_STACK_TRACE", justification = "Cause is really not needed here.")
@Override
public IV doMathOp(final Literal l1, final IV iv1, final Literal l2, final IV iv2, final MathOp op, final BigdataValueFactory vf) {
URI dt1 = l1.getDatatype();
URI dt2 = l2.getDatatype();
boolean d1 = isWikibaseDateURI(dt1);
boolean d2 = isWikibaseDateURI(dt2);
if (!d1 && !d2) {
throw new SparqlTypeErrorException();
}
LiteralExtensionIV liv1 = d1 ? normalizeIV(l1, iv1) : null;
LiteralExtensionIV liv2 = d2 ? normalizeIV(l2, iv2) : null;
if (d1 && d2) {
return handleTwoDates(liv1, liv2, op);
}
try {
// Now we have one date and one duration
if (op == MathOp.PLUS) {
LiteralExtensionIV iv = d1 ? liv1 : liv2;
Literal lduration = d1 ? l2 : l1;
return datePlusDuration(iv, DATATYPE_FACTORY.newDuration(lduration.getLabel()), vf);
}
if (op == MathOp.MINUS) {
return datePlusDuration(liv1, DATATYPE_FACTORY.newDuration(l2.getLabel()).negate(), vf);
}
} catch (IllegalArgumentException e) {
// If we had trouble converting any arguments, make it SPARQL error
throw new SparqlTypeErrorException();
}
throw new SparqlTypeErrorException();
}
Aggregations