Search in sources :

Example 21 with XSDecimal

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

the class XSDecimal method minus.

/**
 * Mathematical subtraction operator between this XSDecimal and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform a subtraction with
 * @return A XSDecimal consisting of the result of the mathematical
 *         subtraction.
 */
public ResultSequence minus(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    Item at = get_single_arg(carg);
    if (!(at instanceof XSDecimal))
        DynamicError.throw_type_error();
    XSDecimal dt = (XSDecimal) at;
    return ResultSequenceFactory.create_new(new XSDecimal(_value.subtract(dt.getValue())));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 22 with XSDecimal

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

the class XSDecimal method eq.

// comparisons
/**
 * Equality comparison between this number and the supplied representation.
 * @param at
 *            Representation to be compared with (must currently be of type
 *            XSDecimal)
 *
 * @return True if the 2 representation represent the same number. False
 *         otherwise
 */
public boolean eq(AnyType at, DynamicContext dynamicContext) throws DynamicError {
    XSDecimal dt = null;
    if (!(at instanceof XSDecimal)) {
        ResultSequence rs = ResultSequenceFactory.create_new(at);
        ResultSequence crs = constructor(rs);
        if (crs.empty()) {
            throw DynamicError.throw_type_error();
        }
        Item cat = crs.first();
        dt = (XSDecimal) cat;
    } else {
        dt = (XSDecimal) at;
    }
    return (_value.compareTo(dt.getValue()) == 0);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 23 with XSDecimal

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

Example 24 with XSDecimal

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

the class XSDayTimeDuration method times.

/**
 * Mathematical multiplication between this duration stored and the supplied
 * duration of time (of type XSDayTimeDuration)
 *
 * @param arg
 *            The duration of time to multiply by
 * @return New XSDayTimeDuration representing the resulting duration after
 *         the multiplication
 * @throws DynamicError
 */
public ResultSequence times(ResultSequence arg) throws DynamicError {
    ResultSequence convertedRS = arg;
    if (arg.size() == 1) {
        Item argValue = arg.first();
        if (argValue instanceof XSDecimal) {
            convertedRS = ResultSequenceFactory.create_new(new XSDouble(argValue.getStringValue()));
        }
    }
    XSDouble val = (XSDouble) NumericType.get_single_type(convertedRS, XSDouble.class);
    if (val.nan()) {
        throw DynamicError.nan();
    }
    double res = value() * val.double_value();
    return ResultSequenceFactory.create_new(new XSDayTimeDuration(res));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 25 with XSDecimal

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

the class ABSFuncTest method test_fn_abs_more_args_026.

// Negative Test gives FORG0001.
public void test_fn_abs_more_args_026() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Functions/NumericFunc/ABSFunc/fn-abs-more-args-026.xq";
    // Test is wrong...should expect FOCA0002...test suite says FORG0001, but other XSDecimal tests say FOCA0002.
    String expectedResult = "FOCA0002";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        actual = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)14 Item (org.eclipse.wst.xml.xpath2.api.Item)10 BigDecimal (java.math.BigDecimal)9 XSDecimal (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal)8 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)7 URL (java.net.URL)6 XSModel (org.apache.xerces.xs.XSModel)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 Collection (java.util.Collection)4 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 DefaultDynamicContext (org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)1 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)1 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)1 JFlexCupParser (org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)1 StaticChecker (org.eclipse.wst.xml.xpath2.processor.StaticChecker)1 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)1 StaticNameResolver (org.eclipse.wst.xml.xpath2.processor.StaticNameResolver)1