protected abstract XNumber promote(XNumber value);
public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv) throws XQueryException {
assert (argv != null && argv.size() == 1);
Item arg = argv.getItem(0);
Iterator<? extends Item> argItor = arg.iterator();
if (!argItor.hasNext()) {
return ValueSequence.EMPTY_SEQUENCE;
}
Item firstItem = argItor.next();
assert (!argItor.hasNext());
if (firstItem instanceof UntypedAtomicValue) {
firstItem = ((UntypedAtomicValue) firstItem).castAs(DoubleType.DOUBLE, dynEnv);
}
if (firstItem instanceof XNumber) {
XNumber num = (XNumber) firstItem;
XNumber promoted = promote(num);
return promoted;
} else {
throw new DynamicError("err:FORG0006", "Invalid argument type: " + firstItem.getType());
}
}