use of org.apache.xpath.objects.XNumber in project robovm by robovm.
the class XPathParser method Number.
/**
*
* Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
*
*
* @throws javax.xml.transform.TransformerException
*/
protected void Number() throws javax.xml.transform.TransformerException {
if (null != m_token) {
// Mutate the token to remove the quotes and have the XNumber object
// already made.
double num;
try {
// XPath 1.0 does not support number in exp notation
if ((m_token.indexOf('e') > -1) || (m_token.indexOf('E') > -1))
throw new NumberFormatException();
num = Double.valueOf(m_token).doubleValue();
} catch (NumberFormatException nfe) {
// to shut up compiler.
num = 0.0;
error(XPATHErrorResources.ER_COULDNOT_BE_FORMATTED_TO_NUMBER, //m_token+" could not be formatted to a number!");
new Object[] { m_token });
}
m_ops.m_tokenQueue.setElementAt(new XNumber(num), m_queueMark - 1);
m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
nextToken();
}
}
use of org.apache.xpath.objects.XNumber in project robovm by robovm.
the class FuncRound method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
final XObject obj = m_arg0.execute(xctxt);
final double val = obj.num();
if (val >= -0.5 && val < 0)
return new XNumber(-0.0);
if (val == 0.0)
return new XNumber(val);
return new XNumber(java.lang.Math.floor(val + 0.5));
}
use of org.apache.xpath.objects.XNumber in project j2objc by google.
the class FuncSum method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
double sum = 0.0;
int pos;
while (DTM.NULL != (pos = nodes.nextNode())) {
DTM dtm = nodes.getDTM(pos);
XMLString s = dtm.getStringValue(pos);
if (null != s)
sum += s.toDouble();
}
nodes.detach();
return new XNumber(sum);
}
use of org.apache.xpath.objects.XNumber in project j2objc by google.
the class FunctionPattern method execute.
/**
* Test a node to see if it matches the given node test.
*
* @param xctxt XPath runtime context.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt, int context, DTM dtm, int expType) throws javax.xml.transform.TransformerException {
DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl) {
int n;
while (DTM.NULL != (n = nl.nextNode())) {
score = (n == context) ? SCORE_OTHER : SCORE_NONE;
if (score == SCORE_OTHER) {
context = n;
break;
}
}
nl.detach();
}
return score;
}
use of org.apache.xpath.objects.XNumber in project j2objc by google.
the class FunctionPattern method execute.
/**
* Test a node to see if it matches the given node test.
*
* @param xctxt XPath runtime context.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
int context = xctxt.getCurrentNode();
DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl) {
int n;
while (DTM.NULL != (n = nl.nextNode())) {
score = (n == context) ? SCORE_OTHER : SCORE_NONE;
if (score == SCORE_OTHER) {
context = n;
break;
}
}
nl.detach();
}
return score;
}
Aggregations