private static int compare_node(NodeType a, NodeType b) { Node nodeA = a.node_value(); Node nodeB = b.node_value(); if (nodeA == nodeB || nodeA.isSameNode(nodeB)) { return(0); } Document docA = getDocument(nodeA); Document docB = getDocument(nodeB); if (docA != docB && !docA.isSameNode(docB)) { return(compareDocuments(docA, docB)); } short relation = nodeA.compareDocumentPosition(nodeB); if ((relation & NodeConstants.DOCUMENT_POSITION_PRECEDING) != 0) { return(1); } if ((relation & NodeConstants.DOCUMENT_POSITION_FOLLOWING) != 0) { return(-1); } throw new Exception("Unexpected result from node comparison: " + relation); }
public static bool same(NodeType a, NodeType b) { return(a.node_value().isSameNode(b.node_value())); // While compare_node(a, b) == 0 is tempting, it is also expensive }