use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method div.
/**
* Mathematical division operator between this XSDouble and the supplied
* ResultSequence.
*
* @param arg
* The ResultSequence to perform an division with
* @return A XSDouble consisting of the result of the mathematical division.
*/
public ResultSequence div(ResultSequence arg) throws DynamicError {
ResultSequence carg = convertResultSequence(arg);
XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
return ResultSequenceFactory.create_new(new XSDouble(double_value() / val.double_value()));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble 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;
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble 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.XSDouble in project webtools.sourceediting by eclipse.
the class TestBugs method testNegativeZeroDouble.
public void testNegativeZeroDouble() throws Exception {
// Bug 279406
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:double('0'))";
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
XSDouble result = (XSDouble) rs.first();
String actual = result.getStringValue();
assertEquals("-0", actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class FnSubsequence method subsequence.
/**
* Subsequence operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:subsequence operation.
*/
public static ResultSequence subsequence(Collection args) throws DynamicError {
ResultBuffer rs = new ResultBuffer();
// get args
Iterator citer = args.iterator();
ResultSequence seq = (ResultSequence) citer.next();
if (seq.empty())
return ResultBuffer.EMPTY;
ResultSequence startLoc = (ResultSequence) citer.next();
ResultSequence length = null;
if (citer.hasNext()) {
length = (ResultSequence) citer.next();
}
Item at = startLoc.first();
if (!(at instanceof NumericType)) {
DynamicError.throw_type_error();
}
at = new XSDouble(at.getStringValue());
int start = (int) ((XSDouble) at).double_value();
// no of items beyond index >= 1 that are added to the result
int effectiveNoItems = 0;
if (length != null) {
// the 3rd argument is present
if (length.size() != 1)
DynamicError.throw_type_error();
at = length.first();
if (!(at instanceof NumericType)) {
DynamicError.throw_type_error();
}
at = new XSDouble(at.getStringValue());
int len = (int) ((XSDouble) at).double_value();
if (len < 0) {
DynamicError.throw_type_error();
}
if (start <= 0) {
effectiveNoItems = start + len - 1;
start = 1;
} else {
effectiveNoItems = len;
}
} else {
// 3rd argument is absent
if (start <= 0) {
start = 1;
effectiveNoItems = seq.size();
} else {
effectiveNoItems = seq.size() - start + 1;
}
}
// index running parallel to the iterator
int pos = 1;
int addedItems = 0;
if (effectiveNoItems > 0) {
for (Iterator seqIter = seq.iterator(); seqIter.hasNext(); ) {
at = (AnyType) seqIter.next();
if (start <= pos && addedItems < effectiveNoItems) {
rs.add(at);
addedItems++;
}
pos++;
}
}
return rs.getSequence();
}
Aggregations