Search in sources :

Example 6 with XSDecimal

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

the class XSDecimal method lt.

/**
 * Comparison between this number and the supplied representation.
 *
 * @param arg
 *            Representation to be compared with (must currently be of type
 *            XSDecimal)
 * @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);
    XSDecimal val = (XSDecimal) get_single_type(carg, XSDecimal.class);
    return (_value.compareTo(val.getValue()) == -1);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 7 with XSDecimal

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

the class TestBugs method testNumberAggregationWithNill2.

public void testNumberAggregationWithNill2() throws Exception {
    URL fileURL = bundle.getEntry("/bugTestFiles/bugNilledNoSchema.xml");
    loadDOMDocument(fileURL);
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = null;
    ResultSequence rs = null;
    String actual = null;
    // a
    xpath = "fn:count(( /root/element1, /root/element2, /root/element3 ))";
    compileXPath(xpath);
    rs = evaluate(domDoc);
    assertTrue(rs.size() > 0);
    actual = ((XSDecimal) rs.first()).getStringValue();
    assertEquals("3", actual);
    // b
    xpath = "fn:sum(( /root/element1, /root/element2, /root/element3 ))";
    compileXPath(xpath);
    rs = evaluate(domDoc);
    assertTrue(rs.size() > 0);
    actual = ((NumericType) rs.first()).getStringValue();
    assertEquals("43", actual);
    // b2
    xpath = "fn:sum(( /root/element1, /root/element2, /root/element3 ), 100)";
    compileXPath(xpath);
    rs = evaluate(domDoc);
    assertTrue(rs.size() > 0);
    actual = ((NumericType) rs.first()).getStringValue();
    assertEquals("143", actual);
    // c
    xpath = "fn:avg(( /root/element1, /root/element2, /root/element3, 1 ))";
    compileXPath(xpath);
    rs = evaluate(domDoc);
    assertTrue(rs.size() > 0);
    actual = ((NumericType) rs.first()).getStringValue();
    assertEquals("11", actual);
    // d
    xpath = "fn:max(( /root/element1, /root/element2, /root/element3 ))";
    compileXPath(xpath);
    rs = evaluate(domDoc);
    assertTrue(rs.size() > 0);
    actual = ((NumericType) rs.first()).getStringValue();
    assertEquals("42", actual);
    // e
    xpath = "fn:min(( /root/element1, /root/element2, /root/element3 ))";
    compileXPath(xpath);
    rs = evaluate(domDoc);
    assertTrue(rs.size() > 0);
    actual = ((NumericType) rs.first()).getStringValue();
    assertEquals("1", actual);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) URL(java.net.URL)

Example 8 with XSDecimal

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

the class TestBugs method testFunctionAtomization2.

public void testFunctionAtomization2() throws Exception {
    // Bug 318313
    URL fileURL = bundle.getEntry("/bugTestFiles/bug318313.xml");
    URL schemaURL = bundle.getEntry("/bugTestFiles/bug318313.xsd");
    loadDOMDocument(fileURL, schemaURL);
    // Get XSModel object for the Schema
    XSModel schema = getGrammar(schemaURL);
    setupDynamicContext(schema);
    String xpath = "fn:round-half-to-even(X,1)";
    compileXPath(xpath);
    ResultSequence rs = evaluate(domDoc);
    XSDecimal result = (XSDecimal) rs.first();
    String actual = result.getStringValue();
    assertEquals("100", actual);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) URL(java.net.URL)

Example 9 with XSDecimal

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

the class TestBugs method testXSYearMonthDurationDivide2.

public void testXSYearMonthDurationDivide2() throws Exception {
    // Bug 279376
    bundle = Platform.getBundle("org.w3c.xqts.testsuite");
    URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "xs:yearMonthDuration('P3Y4M') div xs:yearMonthDuration('-P1Y4M')";
    compileXPath(xpath);
    ResultSequence rs = evaluate(domDoc);
    XSDecimal result = (XSDecimal) rs.first();
    String actual = result.getStringValue();
    assertEquals("-2.5", actual);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) URL(java.net.URL)

Example 10 with XSDecimal

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

the class XSYearMonthDuration method div.

/**
 * Mathematical division between this duration stored and the supplied
 * duration of time (of type XSYearMonthDuration)
 *
 * @param arg
 *            The duration of time to divide by
 * @return New XSYearMonthDuration 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;
        int ret = 0;
        if (!dt.zero())
            ret = (int) Math.round(monthValue() / dt.double_value());
        return ResultSequenceFactory.create_new(new XSYearMonthDuration(ret));
    } else if (at instanceof XSDecimal) {
        XSDecimal dt = (XSDecimal) at;
        int ret = 0;
        if (!dt.zero())
            ret = (int) Math.round(monthValue() / dt.getValue().doubleValue());
        return ResultSequenceFactory.create_new(new XSYearMonthDuration(ret));
    } else if (at instanceof XSYearMonthDuration) {
        XSYearMonthDuration md = (XSYearMonthDuration) at;
        double res = (double) monthValue() / md.monthValue();
        return ResultSequenceFactory.create_new(new XSDecimal(new BigDecimal(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)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