code: public short compareDocumentPosition(Node other) throws DOMException {
          if (other instanceof NodeImpl) {
              NodeImpl otherNode = (NodeImpl) other;
              if (this.tree == otherNode.tree) {
                  if (tree.nodeOrdinal[node] > tree.nodeOrdinal[otherNode.node]) {
                      int ancestor = tree.nodeParentNodeRepID[node];
                      while (ancestor != Integer.MAX_VALUE
                          && tree.nodeOrdinal[ancestor] >= tree.nodeOrdinal[otherNode.node]) {
                          if (ancestor == otherNode.node)
                              return DOCUMENT_POSITION_CONTAINS
                                  | DOCUMENT_POSITION_PRECEDING;
                          ancestor = tree.nodeParentNodeRepID[ancestor];
                      }
                      return DOCUMENT_POSITION_PRECEDING;
                  } else {
                      int ancestor = tree.nodeParentNodeRepID[otherNode.node];
                      while (ancestor != Integer.MAX_VALUE
                          && tree.nodeOrdinal[ancestor] <= tree.nodeOrdinal[otherNode.node]) {
                          if (ancestor == node)
                              return DOCUMENT_POSITION_CONTAINED_BY
                                  | DOCUMENT_POSITION_FOLLOWING;
                          ancestor = tree.nodeParentNodeRepID[ancestor];
                      }
                      return DOCUMENT_POSITION_FOLLOWING;
                  }
              } else {
                  return DOCUMENT_POSITION_DISCONNECTED;
              }
          } else {
              throw new DOMException(DOMException.NOT_SUPPORTED_ERR, null);
          }
      }
docs: {@inheritDoc}