Search in sources :

Example 1 with XSFloat

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

the class FnMax method max.

/**
 * Max operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param context
 *            Relevant dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:max operation.
 */
public static ResultSequence max(Collection args, DynamicContext dynamicContext) throws DynamicError {
    ResultSequence arg = get_arg(args, CmpGt.class);
    if (arg.empty())
        return ResultSequenceFactory.create_new();
    CmpGt max = null;
    TypePromoter tp = new ComparableTypePromoter();
    tp.considerSequence(arg);
    for (Iterator i = arg.iterator(); i.hasNext(); ) {
        AnyAtomicType conv = tp.promote((AnyType) i.next());
        if (conv != null) {
            if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
                return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
            }
            if (max == null || ((CmpGt) conv).gt((AnyType) max, dynamicContext)) {
                max = (CmpGt) conv;
            }
        }
    }
    return ResultSequenceFactory.create_new((AnyType) max);
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) TypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 2 with XSFloat

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

the class FnMin method min.

/**
 * Min operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dynamic
 *            Dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:min operation.
 */
public static ResultSequence min(Collection args, DynamicContext context) throws DynamicError {
    ResultSequence arg = FnMax.get_arg(args, CmpLt.class);
    if (arg.empty())
        return ResultSequenceFactory.create_new();
    CmpLt max = null;
    TypePromoter tp = new ComparableTypePromoter();
    tp.considerSequence(arg);
    for (Iterator i = arg.iterator(); i.hasNext(); ) {
        AnyAtomicType conv = tp.promote((AnyType) i.next());
        if (conv != null) {
            if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
                return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
            }
            if (max == null || ((CmpLt) conv).lt((AnyType) max, context)) {
                max = (CmpLt) conv;
            }
        }
    }
    return ResultSequenceFactory.create_new((AnyType) max);
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) TypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 3 with XSFloat

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

the class FnAvg method avg.

/**
 * Average value operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:avg operation.
 */
public static ResultSequence avg(Collection args) throws DynamicError {
    ResultSequence arg = (ResultSequence) args.iterator().next();
    if (arg.empty())
        return ResultSequenceFactory.create_new();
    int elems = 0;
    MathPlus total = null;
    TypePromoter tp = new ScalarTypePromoter();
    tp.considerSequence(arg);
    for (Iterator i = arg.iterator(); i.hasNext(); ) {
        ++elems;
        AnyAtomicType conv = tp.promote((AnyType) i.next());
        if (conv != null) {
            if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
                return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
            }
            if (total == null) {
                total = (MathPlus) conv;
            } else {
                total = (MathPlus) total.plus(ResultSequenceFactory.create_new(conv)).first();
            }
        }
    }
    if (!(total instanceof MathDiv))
        DynamicError.throw_type_error();
    return ((MathDiv) total).div(ResultSequenceFactory.create_new(new XSInteger(BigInteger.valueOf(elems))));
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) ScalarTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) TypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter) ScalarTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)

Example 4 with XSFloat

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

the class XSFloat method mod.

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

Example 5 with XSFloat

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

the class XSFloat method lt.

/**
 * Comparison between this number and the supplied representation.
 *
 * @param arg
 *            The datatype to compare with
 * @return True if the supplied representation is a greater number than the
 *         one stored. False otherwise
 * @throws DynamicError
 */
public boolean lt(AnyType arg, DynamicContext context) throws DynamicError {
    Item carg = convertArg(arg);
    XSFloat val = (XSFloat) get_single_type(carg, XSFloat.class);
    return float_value() < val.float_value();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)10 Item (org.eclipse.wst.xml.xpath2.api.Item)6 XSFloat (org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat)6 Iterator (java.util.Iterator)5 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)5 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)4 TypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter)4 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)3 ComparableTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter)2 ScalarTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter)2 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 XSModel (org.apache.xerces.xs.XSModel)1 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)1 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)1 XSDecimal (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal)1 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)1 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)1