Search in sources :

Example 16 with XSDecimal

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

the class FsPlus method convert_args.

/**
 * Convert and promote arguments for operation.
 *
 * @param args
 *            input arguments.
 * @param sc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of conversion.
 */
private static Collection convert_args(Collection args) throws DynamicError {
    Collection result = new ArrayList();
    // Keep track of numeric types for promotion
    boolean has_float = false;
    boolean has_double = false;
    // atomize arguments
    for (Iterator i = args.iterator(); i.hasNext(); ) {
        org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize((org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next());
        if (rs.empty())
            return new ArrayList();
        if (rs.size() > 1)
            throw new DynamicError(TypeError.invalid_type(null));
        AnyType arg = (AnyType) rs.item(0);
        if (arg instanceof XSUntypedAtomic) {
            arg = new XSDouble(arg.getStringValue());
        }
        if (arg instanceof XSDouble)
            has_double = true;
        if (arg instanceof XSFloat)
            has_float = true;
        result.add(ResultBuffer.wrap(arg));
    }
    if (has_double)
        has_float = false;
    if (has_double || has_float) {
        Collection result2 = new ArrayList();
        // promote arguments
        for (Iterator i = result.iterator(); i.hasNext(); ) {
            org.eclipse.wst.xml.xpath2.api.ResultSequence rs = (org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next();
            Item arg = rs.item(0);
            if (has_double && (arg instanceof XSFloat)) {
                arg = new XSDouble(((XSFloat) arg).float_value());
            } else if (has_double && (arg instanceof XSDecimal)) {
                arg = new XSDouble(((XSDecimal) arg).getValue().doubleValue());
            } else if (has_float && (arg instanceof XSDecimal)) {
                arg = new XSFloat(((XSDecimal) arg).getValue().floatValue());
            }
            result2.add(arg);
        }
        return result2;
    }
    return result;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ArrayList(java.util.ArrayList) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) Item(org.eclipse.wst.xml.xpath2.api.Item) XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) Iterator(java.util.Iterator) Collection(java.util.Collection) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 17 with XSDecimal

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

the class FnSecondsFromDateTime method seconds_from_date_time.

/**
 * Seconds-from-dateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:seconds-from-dateTime operation.
 */
public static ResultSequence seconds_from_date_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;
    }
    XSDateTime dt = (XSDateTime) arg1.first();
    double res = dt.second();
    return new XSDecimal(new BigDecimal(res));
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) BigDecimal(java.math.BigDecimal)

Example 18 with XSDecimal

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

the class XSInteger method div.

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 19 with XSDecimal

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

the class XSDecimal method gt.

/**
 * Comparison between this number and the supplied representation.
 *
 * @param arg
 *            Representation to be compared with (must currently be of type
 *            XSDecimal)
 * @return True if the supplied type represents a number smaller than this
 *         one stored. False otherwise
 */
public boolean gt(AnyType arg, DynamicContext context) throws DynamicError {
    Item carg = convertArg(arg);
    XSDecimal val = (XSDecimal) get_single_type(carg, XSDecimal.class);
    return (_value.compareTo(val.getValue()) == 1);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 20 with XSDecimal

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

the class XSDecimal method plus.

// math
/**
 * Mathematical addition 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 addition with
 * @return A XSDecimal consisting of the result of the mathematical
 *         addition.
 */
public ResultSequence plus(ResultSequence arg) throws DynamicError {
    // get arg
    ResultSequence carg = convertResultSequence(arg);
    Item at = get_single_arg(carg);
    if (!(at instanceof XSDecimal))
        DynamicError.throw_type_error();
    XSDecimal dt = (XSDecimal) at;
    // own it
    return ResultSequenceFactory.create_new(new XSDecimal(_value.add(dt.getValue())));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

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