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);
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations