Search in sources :

Example 16 with XSInteger

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

the class XSDecimal method idiv.

/**
 * Mathematical integer division operator between this XSDecimal and the
 * supplied ResultSequence. Due to no numeric type promotion or conversion,
 * the ResultSequence must be of type XSDecimal.
 *
 * @param arg
 *            The ResultSequence to perform an integer division with
 * @return A XSInteger consisting of the result of the mathematical integer
 *         division.
 */
public ResultSequence idiv(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    XSDecimal val = (XSDecimal) get_single_type(carg, XSDecimal.class);
    if (val.zero())
        throw DynamicError.div_zero(null);
    BigInteger _ivalue = _value.toBigInteger();
    BigInteger ival = val.getValue().toBigInteger();
    BigInteger result = _ivalue.divide(ival);
    return ResultSequenceFactory.create_new(new XSInteger(result));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigInteger(java.math.BigInteger)

Example 17 with XSInteger

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

the class FnStringLength method string_length.

/**
 * Obtain the string length of the arguments.
 *
 * @param args
 *            are used to obtain the string length.
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of obtaining the string length from the arguments.
 */
public static ResultSequence string_length(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = null;
    if (cargs.isEmpty()) {
        // support for arity = 0
        return getResultSetForArityZero(ec);
    } else {
        arg1 = (ResultSequence) cargs.iterator().next();
    }
    String str = "";
    if (!arg1.empty()) {
        str = ((XSString) arg1.first()).value();
    }
    return new XSInteger(BigInteger.valueOf(UTF16.countCodePoint(str)));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 18 with XSInteger

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

the class XSDouble method idiv.

/**
 * Mathematical integer division operator between this XSDouble and the
 * supplied ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform an integer division with
 * @return A XSInteger consisting of the result of the mathematical integer
 *         division.
 */
public ResultSequence idiv(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
    if (this.nan() || val.nan())
        throw DynamicError.numeric_overflow("Dividend or divisor is NaN");
    if (this.infinite())
        throw DynamicError.numeric_overflow("Dividend is infinite");
    if (val.zero())
        throw DynamicError.div_zero(null);
    BigDecimal result = new BigDecimal((double_value() / val.double_value()));
    return ResultSequenceFactory.create_new(new XSInteger(result.toBigInteger()));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigDecimal(java.math.BigDecimal)

Example 19 with XSInteger

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

the class XSInteger method minus.

/**
 * Mathematical subtraction operator between this XSInteger and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform a subtraction with
 * @return A XSInteger consisting of the result of the mathematical
 *         subtraction.
 */
public ResultSequence minus(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    XSInteger val = (XSInteger) get_single_type(carg, XSInteger.class);
    return ResultSequenceFactory.create_new(new XSInteger(int_value().subtract(val.int_value())));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 20 with XSInteger

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

the class XSInteger method plus.

/**
 * Mathematical addition operator between this XSInteger and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform an addition with
 * @return A XSInteger consisting of the result of the mathematical
 *         addition.
 */
public ResultSequence plus(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    Item at = get_single_arg(carg);
    if (!(at instanceof XSInteger))
        DynamicError.throw_type_error();
    XSInteger val = (XSInteger) at;
    return ResultSequenceFactory.create_new(new XSInteger(int_value().add(val.int_value())));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Aggregations

XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)34 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)32 Collection (java.util.Collection)20 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)12 Iterator (java.util.Iterator)8 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8 XSDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration)6 URL (java.net.URL)5 XSModel (org.apache.xerces.xs.XSModel)5 Item (org.eclipse.wst.xml.xpath2.api.Item)5 XSDateTime (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime)5 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)4 BigInteger (java.math.BigInteger)3 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)3 XSDate (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)2 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)2 XSTime (org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)2