use of org.apache.xpath.NodeSetDTM in project robovm by robovm.
the class NodeSequence method addNodeInDocOrder.
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @return insertIndex.
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a mutable type.
*/
protected int addNodeInDocOrder(int node) {
assertion(hasCache(), "addNodeInDocOrder must be done on a mutable sequence!");
int insertIndex = -1;
NodeVector vec = getVector();
// This needs to do a binary search, but a binary search
// is somewhat tough because the sequence test involves
// two nodes.
int size = vec.size(), i;
for (i = size - 1; i >= 0; i--) {
int child = vec.elementAt(i);
if (child == node) {
// Duplicate, suppress insert
i = -2;
break;
}
DTM dtm = m_dtmMgr.getDTM(node);
if (!dtm.isNodeAfter(node, child)) {
break;
}
}
if (i != -2) {
insertIndex = i + 1;
vec.insertElementAt(node, insertIndex);
}
// checkDups();
return insertIndex;
}
Aggregations