static boolean compare(AtomicValue v0, int op, AtomicValue v1, AtomicComparer collator, boolean checkTypes)
throws XPathException {
if (checkTypes &&
!Type.isComparable(v0.getPrimitiveType(), v1.getPrimitiveType(), Token.isOrderedOperator(op))) {
XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) +
" to " + Type.displayTypeName(v1));
e2.setErrorCode("XPTY0004");
e2.setIsTypeError(true);
throw e2;
}
if (v0.isNaN() || v1.isNaN()) {
return (op == Token.FNE);
}
try {
switch (op) {
case Token.FEQ:
return collator.comparesEqual(v0, v1);
case Token.FNE:
return !collator.comparesEqual(v0, v1);
case Token.FGT:
return collator.compareAtomicValues(v0, v1) > 0;
case Token.FLT:
return collator.compareAtomicValues(v0, v1) < 0;
case Token.FGE:
return collator.compareAtomicValues(v0, v1) >= 0;
case Token.FLE:
return collator.compareAtomicValues(v0, v1) <= 0;
default:
throw new UnsupportedOperationException("Unknown operator " + op);
}
} catch (ClassCastException err) {
XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) +
" to " + Type.displayTypeName(v1));
e2.setErrorCode("XPTY0004");
e2.setIsTypeError(true);
throw e2;
}
}