Search in sources :

Example 1 with ComparableTypePromoter

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

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

Aggregations

Iterator (java.util.Iterator)2 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)2 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)2 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)2 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)2 XSFloat (org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat)2 ComparableTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter)2 TypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter)2