use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger in project webtools.sourceediting by eclipse.
the class FnStringToCodepoints method string_to_codepoints.
/**
* Base-Uri operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:base-uri operation.
*/
public static ResultSequence string_to_codepoints(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty())
return ResultBuffer.EMPTY;
XSString xstr = (XSString) arg1.first();
CodePointIterator cpi = new StringCodePointIterator(xstr.value());
ResultBuffer rs = new ResultBuffer();
for (int codePoint = cpi.current(); codePoint != CodePointIterator.DONE; codePoint = cpi.next()) {
rs.add(new XSInteger(BigInteger.valueOf(codePoint)));
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger in project webtools.sourceediting by eclipse.
the class FnRemove method remove.
/**
* Remove operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:remove operation.
*/
public static ResultSequence remove(Collection args) throws DynamicError {
assert args.size() == 2;
ResultBuffer rs = new ResultBuffer();
// get args
Iterator citer = args.iterator();
ResultSequence target = (ResultSequence) citer.next();
ResultSequence arg2 = (ResultSequence) citer.next();
// sanity chex
if (arg2.size() != 1)
DynamicError.throw_type_error();
Item at = arg2.first();
if (!(at instanceof XSInteger))
DynamicError.throw_type_error();
int position = ((XSInteger) at).int_value().intValue();
if (position < 1)
return target;
if (position > target.size())
return target;
if (target.empty())
return rs.getSequence();
int curpos = 1;
for (Iterator i = target.iterator(); i.hasNext(); ) {
at = (AnyType) i.next();
if (curpos != position)
rs.add(at);
curpos++;
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger in project webtools.sourceediting by eclipse.
the class FnCount method count.
/**
* Count operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:count operation.
*/
public static ResultSequence count(Collection args) throws DynamicError {
assert args.size() == 1;
// get args
Iterator citer = args.iterator();
ResultSequence arg = (ResultSequence) citer.next();
return ResultSequenceFactory.create_new(new XSInteger(BigInteger.valueOf(arg.size())));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger in project webtools.sourceediting by eclipse.
the class FnDayFromDate method day_from_date.
/**
* Day-From-Date operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:day-from-date operation.
*/
public static ResultSequence day_from_date(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
XSDate dt = (XSDate) arg1.first();
int res = dt.day();
return new XSInteger(BigInteger.valueOf(res));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger in project webtools.sourceediting by eclipse.
the class FnAvg method avg.
/**
* Average value operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:avg operation.
*/
public static ResultSequence avg(Collection args) throws DynamicError {
ResultSequence arg = (ResultSequence) args.iterator().next();
if (arg.empty())
return ResultSequenceFactory.create_new();
int elems = 0;
MathPlus total = null;
TypePromoter tp = new ScalarTypePromoter();
tp.considerSequence(arg);
for (Iterator i = arg.iterator(); i.hasNext(); ) {
++elems;
AnyAtomicType conv = tp.promote((AnyType) i.next());
if (conv != null) {
if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
}
if (total == null) {
total = (MathPlus) conv;
} else {
total = (MathPlus) total.plus(ResultSequenceFactory.create_new(conv)).first();
}
}
}
if (!(total instanceof MathDiv))
DynamicError.throw_type_error();
return ((MathDiv) total).div(ResultSequenceFactory.create_new(new XSInteger(BigInteger.valueOf(elems))));
}
Aggregations