Search in sources :

Example 1 with RangeResultSequence

use of org.eclipse.wst.xml.xpath2.processor.internal.RangeResultSequence in project webtools.sourceediting by eclipse.

the class OpTo method op_to.

/**
 * Op-To operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of operation.
 */
public static ResultSequence op_to(Collection args) throws DynamicError {
    // convert arguments
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arguments
    Iterator iter = cargs.iterator();
    ResultSequence r = (ResultSequence) iter.next();
    int one = ((XSInteger) r.first()).int_value().intValue();
    r = (ResultSequence) iter.next();
    if (r.first() == null) {
        return ResultBuffer.EMPTY;
    }
    int two = ((XSInteger) r.first()).int_value().intValue();
    if (one > two)
        return ResultBuffer.EMPTY;
    // inclusive first and last
    if (one == two) {
        return new XSInteger(BigInteger.valueOf(one));
    }
    /*
		 * for(one++; one <= two; one++) { rs.add(new XSInteger(one)); }
		 * 
		 * return rs;
		 */
    return new RangeResultSequence(one, two);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) RangeResultSequence(org.eclipse.wst.xml.xpath2.processor.internal.RangeResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) Collection(java.util.Collection) RangeResultSequence(org.eclipse.wst.xml.xpath2.processor.internal.RangeResultSequence)

Aggregations

Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)1 RangeResultSequence (org.eclipse.wst.xml.xpath2.processor.internal.RangeResultSequence)1 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)1