use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class FnDeepEqual method deep_equal.
/**
* Deep-Equal boolean operation.
*
* @param one
* input1 xpath expression/variable.
* @param two
* input2 xpath expression/variable.
* @param context
* Current dynamic context
* @return Result of fn:deep-equal operation.
*/
public static boolean deep_equal(ResultSequence one, ResultSequence two, EvaluationContext context, String collationURI) {
if (one.empty() && two.empty())
return true;
if (one.size() != two.size())
return false;
Iterator onei = one.iterator();
Iterator twoi = two.iterator();
while (onei.hasNext()) {
AnyType a = (AnyType) onei.next();
AnyType b = (AnyType) twoi.next();
if (!deep_equal(a, b, context, collationURI))
return false;
}
return true;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class FnMin method min.
/**
* Min operation.
*
* @param args
* Result from the expressions evaluation.
* @param dynamic
* Dynamic context
* @throws DynamicError
* Dynamic error.
* @return Result of fn:min operation.
*/
public static ResultSequence min(Collection args, DynamicContext context) throws DynamicError {
ResultSequence arg = FnMax.get_arg(args, CmpLt.class);
if (arg.empty())
return ResultSequenceFactory.create_new();
CmpLt max = null;
TypePromoter tp = new ComparableTypePromoter();
tp.considerSequence(arg);
for (Iterator i = arg.iterator(); i.hasNext(); ) {
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 (max == null || ((CmpLt) conv).lt((AnyType) max, context)) {
max = (CmpLt) conv;
}
}
}
return ResultSequenceFactory.create_new((AnyType) max);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class FnIndexOf method index_of.
/**
* Index-Of operation.
*
* @param args
* Result from the expressions evaluation.
* @param dynamicContext
* @throws DynamicError
* Dynamic error.
* @return Result of fn:index-of operation.
*/
public static ResultSequence index_of(Collection args, DynamicContext dc) {
Function.convert_arguments(args, expected_args());
// get args
Iterator citer = args.iterator();
ResultSequence arg1 = (ResultSequence) citer.next();
ResultSequence arg2 = (ResultSequence) citer.next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
// sanity chex
if (arg2.size() != 1)
DynamicError.throw_type_error();
String collationUri = dc.getCollationProvider().getDefaultCollation();
if (citer.hasNext()) {
ResultSequence arg3 = (ResultSequence) citer.next();
if (!arg3.empty()) {
XSString collation = (XSString) arg3.first();
collationUri = collation.getStringValue();
}
}
ResultBuffer rb = new ResultBuffer();
AnyAtomicType at = (AnyAtomicType) arg2.first();
get_comparable(at);
int index = 1;
for (Iterator i = arg1.iterator(); i.hasNext(); ) {
AnyType cmptype = (AnyType) i.next();
get_comparable(cmptype);
if (!(at instanceof CmpEq))
continue;
if (isBoolean(cmptype, at)) {
XSBoolean boolat = (XSBoolean) cmptype;
if (boolat.eq(at, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (isNumeric(cmptype, at)) {
NumericType numericat = (NumericType) at;
if (numericat.eq(cmptype, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (isDuration(cmptype, at)) {
XSDuration durat = (XSDuration) at;
if (durat.eq(cmptype, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (at instanceof QName && cmptype instanceof QName) {
QName qname = (QName) at;
if (qname.eq(cmptype, dc)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
} else if (needsStringComparison(cmptype, at)) {
XSString xstr1 = new XSString(cmptype.getStringValue());
XSString itemStr = new XSString(at.getStringValue());
if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).equals(BigInteger.ZERO)) {
rb.add(new XSInteger(BigInteger.valueOf(index)));
}
}
index++;
}
return rb.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class FnTrace method trace.
/**
* Trace operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:trace operation.
*/
public static ResultSequence trace(Collection args) throws DynamicError {
// sanity check args
if (args.size() != 2)
DynamicError.throw_type_error();
Iterator argsi = args.iterator();
ResultSequence arg1 = (ResultSequence) argsi.next();
ResultSequence arg2 = (ResultSequence) argsi.next();
if (arg2.size() != 1)
DynamicError.throw_type_error();
Item at = arg2.first();
if (!(at instanceof XSString))
DynamicError.throw_type_error();
XSString label = (XSString) at;
int index = 1;
for (Iterator i = arg1.iterator(); i.hasNext(); index++) {
at = (AnyType) i.next();
System.out.println(label.value() + " [" + index + "] " + ((AnyType) at).string_type() + ":" + at.getStringValue());
}
return arg1;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType 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();
}
Aggregations