Search in sources :

Example 16 with NodeSetDTM

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;
}
Also used : NodeVector(org.apache.xml.utils.NodeVector) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM)

Aggregations

NodeSetDTM (org.apache.xpath.NodeSetDTM)16 DTM (org.apache.xml.dtm.DTM)10 DTMIterator (org.apache.xml.dtm.DTMIterator)4 NodeVector (org.apache.xml.utils.NodeVector)4 StringVector (org.apache.xml.utils.StringVector)4 XNodeSet (org.apache.xpath.objects.XNodeSet)4 XObject (org.apache.xpath.objects.XObject)4 StringTokenizer (java.util.StringTokenizer)2 Vector (java.util.Vector)2 XMLString (org.apache.xml.utils.XMLString)2 Expression (org.apache.xpath.Expression)2 XPath (org.apache.xpath.XPath)2