use of org.sirix.api.Axis in project sirix by sirixdb.
the class Matching method containedDescendants.
/**
* Counts the number of descendant nodes in the subtrees of x and y that are also in the matching.
*
* @param nodeX first subtree root node
* @param nodeY second subtree root node
* @return number of descendant which have been matched
*/
public long containedDescendants(@Nonnegative final long nodeX, @Nonnegative final long nodeY) {
long retVal = 0;
mRtxOld.moveTo(nodeX);
for (final Axis axis = new DescendantAxis(mRtxOld, IncludeSelf.YES); axis.hasNext(); ) {
axis.next();
retVal += mIsInSubtree.get(nodeY, partner(mRtxOld.getNodeKey())) ? 1 : 0;
if (mRtxOld.getKind() == Kind.ELEMENT) {
for (int i = 0, nspCount = mRtxOld.getNamespaceCount(); i < nspCount; i++) {
mRtxOld.moveToNamespace(i);
retVal += mIsInSubtree.get(nodeY, partner(axis.getTrx().getNodeKey())) ? 1 : 0;
mRtxOld.moveToParent();
}
for (int i = 0, attCount = mRtxOld.getAttributeCount(); i < attCount; i++) {
mRtxOld.moveToAttribute(i);
retVal += mIsInSubtree.get(nodeY, partner(axis.getTrx().getNodeKey())) ? 1 : 0;
mRtxOld.moveToParent();
}
}
}
return retVal;
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class XPathParser method parseForwardStep.
/**
* Parses the the rule ForwardStep according to the following production rule:
* <p>
* [29] ForwardStep ::= (ForwardAxis NodeTest) | AbbrevForwardStep .
* </p>
*
* @throws SirixXPathException
*/
private void parseForwardStep() throws SirixXPathException {
Axis axis;
Filter filter;
if (isForwardAxis()) {
axis = parseForwardAxis();
filter = parseNodeTest(axis.getClass() == AttributeAxis.class);
mPipeBuilder.addStep(axis, filter);
} else {
axis = parseAbbrevForwardStep();
mPipeBuilder.addStep(axis);
}
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class FNBoolean method computeResult.
/**
* {@inheritDoc}
*/
@Override
protected byte[] computeResult() throws SirixXPathException {
final Axis axis = getArgs().get(0);
boolean value = false;
if (axis.hasNext()) {
mKey = axis.next();
final XdmNodeReadTrx rtx = axis.getTrx();
if (rtx.getNodeKey() >= 0) {
// first item is a real node
// ->
// true
value = true;
} else {
final Type type = Type.getType(rtx.getTypeKey());
if (type.derivesFrom(Type.BOOLEAN)) {
value = Boolean.parseBoolean(rtx.getValue());
// value = TypedValue.parseBoolean(rtx.getRawValue());
} else if (type.derivesFrom(Type.STRING) || type.derivesFrom(Type.ANY_URI) || type.derivesFrom(Type.UNTYPED_ATOMIC)) {
// if length = 0 -> false
value = (rtx.getValue().length() > 0);
} else if (type.isNumericType()) {
final double dValue = Double.parseDouble(rtx.getValue());
value = !(Double.isNaN(dValue) || dValue == 0.0d);
} else {
// for all other types throw error FORG0006
throw EXPathError.FORG0006.getEncapsulatedException();
}
// if is not a singleton
if (axis.hasNext()) {
throw EXPathError.FORG0006.getEncapsulatedException();
}
}
} else {
// expression is an empty sequence -> false
value = false;
}
return TypedValue.getBytes(Boolean.toString(value));
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class FNCount method computeResult.
/**
* {@inheritDoc}
*/
@Override
protected byte[] computeResult() {
final Axis axis = getArgs().get(0);
Integer count = 0;
while (axis.hasNext()) {
axis.next();
count++;
}
return TypedValue.getBytes(count.toString());
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class FNSum method computeResult.
/**
* {@inheritDoc}
*/
@Override
protected byte[] computeResult() {
final Axis axis = getArgs().get(0);
Integer count = 0;
while (axis.hasNext()) {
axis.next();
count++;
}
return TypedValue.getBytes(count.toString());
}
Aggregations