while(argItor.hasNext()) {
Item it = argItor.next();
if(it instanceof UntypedAtomicValue) {
it = ((UntypedAtomicValue) it).castAs(DoubleType.DOUBLE, dynEnv);
} else if(!(it instanceof XNumber)) {
throw new DynamicError("err:FORG0006", "fs:plus(" + min.getType() + ", "
+ it.getType() + ") is not defined.");
}
XNumber cmp = (XNumber) it;
if(cmp.isNaN()) {
return cmp;
}
if(cmp.compareTo(min) < 0) {
min = cmp;
}
}
return min;
} else if(firstItem instanceof DurationValue) {
// Duration values must either all be xdt:yearMonthDuration values
// or must all be xdt:dayTimeDuration values.
DurationValue min = (DurationValue) firstItem;
assert (firstType != null);
while(argItor.hasNext()) {
Item it = argItor.next();
if(it instanceof DurationValue) {
throw new DynamicError("err:FORG0006", "Duration values must all be `"
+ firstType + "`, but found `" + it.getType() + "`");
}
DurationValue cmp = (DurationValue) it;
if(cmp.compareTo(min) < 0) {
min = cmp;
}
}
return min;
} else if(TypeUtil.subtypeOf(firstType, StringType.STRING)) {
AtomicValue min = (AtomicValue) firstItem;
final int arglen = argv.size();
final Collator collator;
if(arglen == 2) {
Item sec = argv.getItem(1);
Type secType = sec.getType();
if(!TypeUtil.subtypeOf(secType, StringType.STRING)) {
throw new DynamicError("err:FORG0006", "second argument is expected to be xs:string, but was "
+ secType);
}
String uri = sec.stringValue();
collator = CollationUtils.resolve(uri, dynEnv.getStaticContext());
} else {
collator = Collator.getInstance(); // compare in default locale
}
while(argItor.hasNext()) {
Item it = argItor.next();
Type cmpType = it.getType();
if(!TypeUtil.subtypeOf(cmpType, StringType.STRING)) {
throw new DynamicError("err:FORG0006", "imcomparable xs:string and " + cmpType);
}
if(collator.compare(it, firstItem) < 0) {
min = (AtomicValue) it;
}
}
return min;
} else {
throw new DynamicError("err:FORG0006", "Invalid argument type: " + firstItem.getType());
}
}