Search in sources :

Example 21 with XSDuration

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

the class XSBoolean method constructor.

/**
 * Creates a new result sequence consisting of the retrievable boolean value
 * in the supplied result sequence
 *
 * @param arg
 *            The result sequence from which to extract the boolean value.
 * @throws DynamicError
 * @return A new result sequence consisting of the boolean value supplied.
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    Item anyType = arg.first();
    if (anyType instanceof XSDuration || anyType instanceof CalendarType || anyType instanceof XSBase64Binary || anyType instanceof XSHexBinary || anyType instanceof XSAnyURI) {
        throw DynamicError.invalidType();
    }
    String str_value = anyType.getStringValue();
    if (!(isCastable(anyType, str_value))) {
        throw DynamicError.cant_cast(null);
    }
    return XSBoolean.valueOf(!isFalse(str_value));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 22 with XSDuration

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

XSDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration)18 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)8 Collection (java.util.Collection)7 ArrayList (java.util.ArrayList)6 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)6 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 URL (java.net.URL)4 XSModel (org.apache.xerces.xs.XSModel)4 Item (org.eclipse.wst.xml.xpath2.api.Item)4 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)4 BigDecimal (java.math.BigDecimal)2 Iterator (java.util.Iterator)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Duration (javax.xml.datatype.Duration)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)1 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)1 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)1