use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal in project webtools.sourceediting by eclipse.
the class XSYearMonthDuration method times.
/**
* Mathematical multiplication between this duration stored and the supplied
* duration of time (of type XSYearMonthDuration)
*
* @param arg
* The duration of time to multiply by
* @return New XSYearMonthDuration 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();
}
if (val.infinite()) {
throw DynamicError.overflowDateTime();
}
int res = (int) Math.round(monthValue() * val.double_value());
return ResultSequenceFactory.create_new(new XSYearMonthDuration(res));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal in project webtools.sourceediting by eclipse.
the class TestBugs method testNumberAggregationWithNill.
public void testNumberAggregationWithNill() throws Exception {
URL fileURL = bundle.getEntry("/bugTestFiles/bugNilled.xml");
URL schemaURL = bundle.getEntry("/bugTestFiles/bugNilled.xsd");
loadDOMDocument(fileURL, schemaURL);
// Get XSModel object for the Schema
XSModel schema = getGrammar(schemaURL);
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 = ((XSDecimal) 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 = ((XSDecimal) 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 = ((XSDecimal) 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 = ((XSDecimal) 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 = ((XSDecimal) rs.first()).getStringValue();
assertEquals("1", actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal in project webtools.sourceediting by eclipse.
the class TestBugs method testSequenceAggregationOnEmpty.
public void testSequenceAggregationOnEmpty() throws Exception {
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 = null;
ResultSequence rs = null;
// a)
xpath = "fn:sum((1,2,3,() ))";
compileXPath(xpath);
rs = evaluate(domDoc);
XSDecimal val = (XSDecimal) rs.first();
assertEquals("6", val.string_value());
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal in project webtools.sourceediting by eclipse.
the class StaticContextAdapterTest method testFunctionCall.
public void testFunctionCall() {
XPathParser xpp = new JFlexCupParser();
XPath xpath = xpp.parse("fn:sum((1,2,3))");
DefaultStaticContext sc = new DefaultStaticContext(null);
sc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
sc.add_function_library(new FnFunctionLibrary());
StaticChecker namecheck = new StaticNameResolver(sc);
namecheck.check(xpath);
DefaultDynamicContext dc = new DefaultDynamicContext(null, null);
dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
dc.add_function_library(new FnFunctionLibrary());
Evaluator eval = new DefaultEvaluator(dc, null);
ResultSequence rs = eval.evaluate(xpath);
assertEquals(1, rs.size());
XSDecimal result = (XSDecimal) rs.first();
String actual = result.getStringValue();
assertEquals("6", actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal in project webtools.sourceediting by eclipse.
the class FnSecondsFromDuration method seconds_from_duration.
/**
* Seconds-from-Duration operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:seconds-from-duration operation.
*/
public static ResultSequence seconds_from_duration(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
XSDuration dtd = (XSDuration) arg1.first();
double res = dtd.seconds();
if (dtd.negative())
res *= -1;
return new XSDecimal(new BigDecimal(res));
}
Aggregations