Search in sources :

Example 1 with XSDecimal

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

the class FnSecondsFromTime method seconds_from_time.

/**
 * Base-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:base-uri operation.
 */
public static ResultSequence seconds_from_time(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSTime dt = (XSTime) arg1.first();
    double res = dt.second();
    return new XSDecimal(new BigDecimal(res));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) BigDecimal(java.math.BigDecimal)

Example 2 with XSDecimal

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

the class XSDecimal method mod.

/**
 * Mathematical modulus 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 a modulus with
 * @return A XSDecimal consisting of the result of the mathematical modulus.
 */
public ResultSequence mod(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    XSDecimal val = (XSDecimal) get_single_type(carg, XSDecimal.class);
    // BigDecimal result = _value.remainder(val.getValue());
    BigDecimal result = remainder(_value, val.getValue());
    return ResultSequenceFactory.create_new(new XSDecimal(result));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigDecimal(java.math.BigDecimal)

Example 3 with XSDecimal

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

the class XSDecimal method div.

/**
 * Mathematical division operator between this XSDecimal and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform a division with
 * @return A XSDecimal consisting of the result of the mathematical
 *         division.
 */
public ResultSequence div(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);
    }
    BigDecimal result = getValue().divide(val.getValue(), 18, BigDecimal.ROUND_HALF_EVEN);
    return ResultSequenceFactory.create_new(new XSDecimal(result));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigDecimal(java.math.BigDecimal)

Example 4 with XSDecimal

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

the class XSDecimal method times.

/**
 * Mathematical multiplication operator between this XSDecimal and the
 * supplied ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform a multiplication with
 * @return A XSDecimal consisting of the result of the mathematical
 *         multiplication.
 */
public ResultSequence times(ResultSequence arg) {
    ResultSequence carg = convertResultSequence(arg);
    XSDecimal val = (XSDecimal) get_single_type(carg, XSDecimal.class);
    BigDecimal result = _value.multiply(val.getValue());
    return ResultSequenceFactory.create_new(new XSDecimal(result));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigDecimal(java.math.BigDecimal)

Example 5 with XSDecimal

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal 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)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)14 Item (org.eclipse.wst.xml.xpath2.api.Item)10 BigDecimal (java.math.BigDecimal)9 XSDecimal (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal)8 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)7 URL (java.net.URL)6 XSModel (org.apache.xerces.xs.XSModel)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 Collection (java.util.Collection)4 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 DefaultDynamicContext (org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)1 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)1 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)1 JFlexCupParser (org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)1 StaticChecker (org.eclipse.wst.xml.xpath2.processor.StaticChecker)1 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)1 StaticNameResolver (org.eclipse.wst.xml.xpath2.processor.StaticNameResolver)1