Search in sources :

Example 16 with XSDouble

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

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

the class FnSubstring method expected_args.

/**
 * Calculate the expected arguments.
 *
 * @return The expected arguments.
 */
public static Collection expected_args(Collection actualArgs) {
    Collection _expected_args = new ArrayList();
    _expected_args.add(new SeqType(new XSString(), SeqType.OCC_QMARK));
    _expected_args.add(new SeqType(new XSDouble(), SeqType.OCC_NONE));
    // for arity 3
    if (actualArgs.size() == 3) {
        _expected_args.add(new SeqType(new XSDouble(), SeqType.OCC_NONE));
    }
    return _expected_args;
}
Also used : XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 18 with XSDouble

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

the class FsConvertOperand method convert_operand.

/**
 * Convert-Operand operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fs: operation.
 */
public static ResultSequence convert_operand(Collection args) throws DynamicError {
    assert args.size() == 2;
    Iterator iter = args.iterator();
    ResultSequence actual = (ResultSequence) iter.next();
    ResultSequence expected = (ResultSequence) iter.next();
    if (expected.size() != 1)
        DynamicError.throw_type_error();
    Item at = expected.first();
    if (!(at instanceof AnyAtomicType))
        DynamicError.throw_type_error();
    AnyAtomicType exp_aat = (AnyAtomicType) at;
    ResultBuffer result = new ResultBuffer();
    // 1
    if (actual.empty())
        return result.getSequence();
    // convert sequence
    for (Iterator i = actual.iterator(); i.hasNext(); ) {
        AnyType item = (AnyType) i.next();
        // 2
        if (item instanceof XSUntypedAtomic) {
            // a
            if (exp_aat instanceof XSUntypedAtomic)
                result.add(new XSString(item.getStringValue()));
            else // b
            if (exp_aat instanceof NumericType)
                result.add(new XSDouble(item.getStringValue()));
            else // c
            {
                assert exp_aat instanceof CtrType;
                CtrType cons = (CtrType) exp_aat;
                result.concat(cons.constructor(new XSString(item.getStringValue())));
            }
        } else
            // 4
            result.add(item);
    }
    return result.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) CtrType(org.eclipse.wst.xml.xpath2.processor.internal.types.CtrType) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 19 with XSDouble

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

the class FsEq method do_general_pair.

/**
 * Making sure that the types are the same before comparing the inputs.
 *
 * @param a
 *            input1 of any type.
 * @param b
 *            input2 of any type.
 * @param dc
 *              Dynamic Context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of Equality operation.
 */
private static boolean do_general_pair(AnyType a, AnyType b, Method comparator, DynamicContext ec) throws DynamicError {
    // double
    if ((a instanceof XSUntypedAtomic && b instanceof NumericType) || (b instanceof XSUntypedAtomic && a instanceof NumericType)) {
        if (a instanceof XSUntypedAtomic)
            a = new XSDouble(a.getStringValue());
        else
            b = new XSDouble(b.getStringValue());
    } else // untyped to string
    if ((a instanceof XSUntypedAtomic && (b instanceof XSString || b instanceof XSUntypedAtomic) || (b instanceof XSUntypedAtomic && (a instanceof XSString || a instanceof XSUntypedAtomic)))) {
        if (a instanceof XSUntypedAtomic)
            a = new XSString(a.getStringValue());
        if (b instanceof XSUntypedAtomic)
            b = new XSString(b.getStringValue());
    } else // TODO: This makes no sense as implemented before
    if (a instanceof XSUntypedAtomic) {
    // ResultSequence converted = ResultSequenceFactory.create_new(a);
    // assert converted.size() == 1;
    // a = converted.first();
    } else if (b instanceof XSUntypedAtomic) {
    // ResultSequence converted = ResultSequenceFactory.create_new(b);
    // assert converted.size() == 1;
    // b = converted.first();
    }
    // rule d
    // if value comparison is true, return true.
    ResultSequence one = ResultSequenceFactory.create_new(a);
    ResultSequence two = ResultSequenceFactory.create_new(b);
    Collection args = new ArrayList();
    args.add(one);
    args.add(two);
    Object[] margs = { args, ec };
    ResultSequence result = null;
    try {
        result = (ResultSequence) comparator.invoke(null, margs);
    } catch (IllegalAccessException err) {
        assert false;
    } catch (InvocationTargetException err) {
        Throwable ex = err.getTargetException();
        if (ex instanceof RuntimeException)
            throw (RuntimeException) ex;
        throw new RuntimeException(ex);
    }
    if (((XSBoolean) result.first()).value())
        return true;
    return false;
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) InvocationTargetException(java.lang.reflect.InvocationTargetException) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) Collection(java.util.Collection) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)

Example 20 with XSDouble

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

the class XSDouble method times.

/**
 * Mathematical multiplication operator between this XSDouble and the
 * supplied ResultSequence. Due to no numeric type promotion or conversion,
 * the ResultSequence must be of type XSDouble.
 *
 * @param arg
 *            The ResultSequence to perform an multiplication with
 * @return A XSDouble consisting of the result of the mathematical
 *         multiplication.
 */
public ResultSequence times(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
    return ResultSequenceFactory.create_new(new XSDouble(double_value() * val.double_value()));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)17 Item (org.eclipse.wst.xml.xpath2.api.Item)12 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)12 Iterator (java.util.Iterator)9 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)6 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)5 XSFloat (org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat)5 Collection (java.util.Collection)4 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)4 XSUntypedAtomic (org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)4 TypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter)4 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)3 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)2 ComparableTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter)2 ScalarTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1