Search in sources :

Example 21 with XSDouble

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

the class XSDouble method eq.

/**
 * Equality comparison between this number and the supplied representation.
 * @param aa
 *            Representation to be compared with (must currently be of type
 *            XSDouble)
 *
 * @return True if the 2 representations represent the same number. False
 *         otherwise
 * @since 1.1
 */
public boolean eq(AnyType aa, DynamicContext dynamicContext) throws DynamicError {
    ResultSequence rs = ResultSequenceFactory.create_new(aa);
    ResultSequence crs = constructor(rs);
    if (crs.empty()) {
        throw DynamicError.throw_type_error();
    }
    Item cat = crs.first();
    XSDouble d = (XSDouble) cat;
    if (d.nan() && nan()) {
        return false;
    }
    Double thatvalue = new Double(d.double_value());
    Double thisvalue = new Double(double_value());
    return thisvalue.equals(thatvalue);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 22 with XSDouble

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

the class XSDouble method constructor.

/**
 * Creates a new result sequence consisting of the retrievable double number
 * in the supplied result sequence
 *
 * @param arg
 *            The result sequence from which to extract the double number.
 * @throws DynamicError
 * @return A new result sequence consisting of the double number supplied.
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    Item aat = arg.first();
    if (aat instanceof XSDuration || aat instanceof CalendarType || aat instanceof XSBase64Binary || aat instanceof XSHexBinary || aat instanceof XSAnyURI) {
        throw DynamicError.invalidType();
    }
    if (!isCastable(aat)) {
        throw DynamicError.cant_cast(null);
    }
    XSDouble d = castDouble(aat);
    if (d == null)
        throw DynamicError.cant_cast(null);
    return d;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 23 with XSDouble

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

the class XSDouble method lt.

/**
 * Comparison between this number and the supplied representation. Currently
 * no numeric type promotion exists so the supplied representation must be
 * of type XSDouble.
 *
 * @param arg
 *            Representation to be compared with (must currently be of type
 *            XSDouble)
 * @return True if the supplied type represents a number greater than this
 *         one stored. False otherwise
 */
public boolean lt(AnyType arg, DynamicContext context) throws DynamicError {
    Item carg = convertArg(arg);
    XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
    return double_value() < val.double_value();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 24 with XSDouble

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

the class XSDouble method minus.

/**
 * Mathematical subtraction operator between this XSDouble and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform an subtraction with
 * @return A XSDouble consisting of the result of the mathematical
 *         subtraction.
 */
public ResultSequence minus(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)

Example 25 with XSDouble

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

the class XSDayTimeDuration method div.

/**
 * Mathematical division between this duration stored and the supplied
 * duration of time (of type XSDayTimeDuration)
 *
 * @param arg
 *            The duration of time to divide by
 * @return New XSDayTimeDuration representing the resulting duration after
 *         the division
 * @throws DynamicError
 */
public ResultSequence div(ResultSequence arg) throws DynamicError {
    if (arg.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg.first();
    if (at instanceof XSDouble) {
        XSDouble dt = (XSDouble) at;
        double retval = 0;
        if (dt.nan()) {
            throw DynamicError.nan();
        }
        if (!dt.zero()) {
            BigDecimal ret = new BigDecimal(0);
            if (dt.infinite()) {
                retval = value() / dt.double_value();
            } else {
                ret = new BigDecimal(value());
                ret = ret.divide(new BigDecimal(dt.double_value()), 18, BigDecimal.ROUND_HALF_EVEN);
                retval = ret.doubleValue();
            }
        } else {
            throw DynamicError.overflowUnderflow();
        }
        return ResultSequenceFactory.create_new(new XSDayTimeDuration(retval));
    } else if (at instanceof XSDecimal) {
        XSDecimal dt = (XSDecimal) at;
        BigDecimal ret = new BigDecimal(0);
        if (!dt.zero()) {
            ret = new BigDecimal(value());
            ret = ret.divide(dt.getValue(), 18, BigDecimal.ROUND_HALF_EVEN);
        } else {
            throw DynamicError.overflowUnderflow();
        }
        return ResultSequenceFactory.create_new(new XSDayTimeDuration(ret.intValue()));
    } else if (at instanceof XSDayTimeDuration) {
        XSDuration md = (XSDuration) at;
        BigDecimal res = null;
        res = new BigDecimal(this.value());
        BigDecimal l = new BigDecimal(md.value());
        res = res.divide(l, 18, BigDecimal.ROUND_HALF_EVEN);
        return ResultSequenceFactory.create_new(new XSDecimal(res));
    } else {
        DynamicError.throw_type_error();
        // unreach
        return null;
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigDecimal(java.math.BigDecimal)

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