if(num2 != Double.NaN)
if(!Double.isNaN(num2))
  public boolean compare(XObject obj2, Comparator comparator)    throws org.xml.sax.SAXException  {    boolean result = false;    int type = obj2.getType();    if(XObject.CLASS_NODESET == type)    {      // From http://www.w3.org/TR/xpath:       // If both objects to be compared are node-sets, then the comparison       // will be true if and only if there is a node in the first node-set       // and a node in the second node-set such that the result of performing       // the comparison on the string-values of the two nodes is true.      // Note this little gem from the draft:      // NOTE: If $x is bound to a node-set, then $x="foo"       // does not mean the same as not($x!="foo"): the former       // is true if and only if some node in $x has the string-value       // foo; the latter is true if and only if all nodes in $x have       // the string-value foo.      NodeIterator list1 = nodeset();      NodeIterator list2 = ((XNodeSet)obj2).nodeset();      Node node1;      StringVector node2Strings = null;      while(null != (node1 = list1.nextNode()))      {        String s1 = getStringFromNode(node1);        if(null == node2Strings)        {          Node node2;          while(null != (node2 = list2.nextNode()))          {            String s2 = getStringFromNode(node2);            if(comparator.compareStrings(s1, s2))            {              result = true;              break;            }            if(null == node2Strings)              node2Strings = new StringVector();            node2Strings.addElement(s2);          }        }        else        {          int n = node2Strings.size();          for(int i = 0; i < n; i++)          {            if(comparator.compareStrings(s1, node2Strings.elementAt(i)))            {              result = true;              break;            }          }        }      }    }    else if(XObject.CLASS_BOOLEAN == type)    {      // From http://www.w3.org/TR/xpath:       // If one object to be compared is a node-set and the other is a boolean,       // then the comparison will be true if and only if the result of       // performing the comparison on the boolean and on the result of       // converting the node-set to a boolean using the boolean function       // is true.      double num1 = bool() ? 1.0 : 0.0;      double num2 = obj2.num();      result = comparator.compareNumbers(num1, num2);    }    else if(XObject.CLASS_NUMBER == type)    {      // From http://www.w3.org/TR/xpath:       // If one object to be compared is a node-set and the other is a number,       // then the comparison will be true if and only if there is a       // node in the node-set such that the result of performing the       // comparison on the number to be compared and on the result of       // converting the string-value of that node to a number using       // the number function is true.                   NodeIterator list1 = nodeset();      double num2 = obj2.num();      Node node;      while(null != (node = list1.nextNode()))      {        double num1 = getNumberFromNode(node);        if(comparator.compareNumbers(num1, num2))        {          result = true;          break;        }      }    }    else if(XObject.CLASS_RTREEFRAG == type)    {      // hmmm...       double num2 = obj2.num();      if(num2 != Double.NaN)      {        NodeIterator list1 = nodeset();        Node node;        while(null != (node = list1.nextNode()))        {          double num1 = getNumberFromNode(node);          if(comparator.compareNumbers(num1, num2))          {            result = true;            break;          }        }      }      else      {        String s2 = obj2.str();        NodeIterator list1 = nodeset();        Node node;        while(null != (node = list1.nextNode()))        {          String s1 = getStringFromNode(node);          if(comparator.compareStrings(s1, s2))          {            result = true;            break;          }        }      }    }    else if(XObject.CLASS_STRING == type)    {      // From http://www.w3.org/TR/xpath:       // If one object to be compared is a node-set and the other is a       // string, then the comparison will be true if and only if there       // is a node in the node-set such that the result of performing       // the comparison on the string-value of the node and the other       // string is true.       String s2 = obj2.str();      NodeIterator list1 = nodeset();      Node node;      while(null != (node = list1.nextNode()))      {        String s1 = getStringFromNode(node);        if(comparator.compareStrings(s1, s2))        {          result = true;          break;        }      }    }    else    {      result = comparator.compareNumbers(this.num(), obj2.num());    }    return result;  }