📄 xnodeset.java
字号:
// 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. DTMIterator list1 = iterRaw(); DTMIterator list2 = ((XNodeSet) obj2).iterRaw(); int node1; java.util.Vector node2Strings = null; while (DTM.NULL != (node1 = list1.nextNode())) { XMLString s1 = getStringFromNode(node1); if (null == node2Strings) { int node2; while (DTM.NULL != (node2 = list2.nextNode())) { XMLString s2 = getStringFromNode(node2); if (comparator.compareStrings(s1, s2)) { result = true; break; } if (null == node2Strings) node2Strings = new java.util.Vector(); node2Strings.addElement(s2); } } else { int n = node2Strings.size(); for (int i = 0; i < n; i++) { if (comparator.compareStrings(s1, (XMLString)node2Strings.elementAt(i))) { result = true; break; } } } } list1.reset(); list2.reset(); } 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. DTMIterator list1 = iterRaw(); double num2 = obj2.num(); int node; while (DTM.NULL != (node = list1.nextNode())) { double num1 = getNumberFromNode(node); if (comparator.compareNumbers(num1, num2)) { result = true; break; } } list1.reset(); } else if (XObject.CLASS_RTREEFRAG == type) { XMLString s2 = obj2.xstr(); DTMIterator list1 = iterRaw(); int node; while (DTM.NULL != (node = list1.nextNode())) { XMLString s1 = getStringFromNode(node); if (comparator.compareStrings(s1, s2)) { result = true; break; } } list1.reset(); } 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. XMLString s2 = obj2.xstr(); DTMIterator list1 = iterRaw(); int node; while (DTM.NULL != (node = list1.nextNode())) { XMLString s1 = getStringFromNode(node); if (comparator.compareStrings(s1, s2)) { result = true; break; } } list1.reset(); } else { result = comparator.compareNumbers(this.num(), obj2.num()); } return result; } /** * Tell if one object is less than the other. * * @param obj2 object to compare this nodeset to * * @return see this.compare(...) * * @throws javax.xml.transform.TransformerException */ public boolean lessThan(XObject obj2) throws javax.xml.transform.TransformerException { return compare(obj2, S_LT); } /** * Tell if one object is less than or equal to the other. * * @param obj2 object to compare this nodeset to * * @return see this.compare(...) * * @throws javax.xml.transform.TransformerException */ public boolean lessThanOrEqual(XObject obj2) throws javax.xml.transform.TransformerException { return compare(obj2, S_LTE); } /** * Tell if one object is less than the other. * * @param obj2 object to compare this nodeset to * * @return see this.compare(...) * * @throws javax.xml.transform.TransformerException */ public boolean greaterThan(XObject obj2) throws javax.xml.transform.TransformerException { return compare(obj2, S_GT); } /** * Tell if one object is less than the other. * * @param obj2 object to compare this nodeset to * * @return see this.compare(...) * * @throws javax.xml.transform.TransformerException */ public boolean greaterThanOrEqual(XObject obj2) throws javax.xml.transform.TransformerException { return compare(obj2, S_GTE); } /** * Tell if two objects are functionally equal. * * @param obj2 object to compare this nodeset to * * @return see this.compare(...) * * @throws javax.xml.transform.TransformerException */ public boolean equals(XObject obj2) { try { return compare(obj2, S_EQ); } catch(javax.xml.transform.TransformerException te) { throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(te); } } /** * Tell if two objects are functionally not equal. * * @param obj2 object to compare this nodeset to * * @return see this.compare(...) * * @throws javax.xml.transform.TransformerException */ public boolean notEquals(XObject obj2) throws javax.xml.transform.TransformerException { return compare(obj2, S_NEQ); }}/** * compares nodes for various boolean operations. */abstract class Comparator{ /** * Compare two strings * * * @param s1 First string to compare * @param s2 Second String to compare * * @return Whether the strings are equal or not */ abstract boolean compareStrings(XMLString s1, XMLString s2); /** * Compare two numbers * * * @param n1 First number to compare * @param n2 Second number to compare * * @return Whether the numbers are equal or not */ abstract boolean compareNumbers(double n1, double n2);}/** * Compare strings or numbers for less than. */class LessThanComparator extends Comparator{ /** * Compare two strings for less than. * * * @param s1 First string to compare * @param s2 Second String to compare * * @return True if s1 is less than s2 */ boolean compareStrings(XMLString s1, XMLString s2) { return (s1.toDouble() < s2.toDouble()); // return s1.compareTo(s2) < 0; } /** * Compare two numbers for less than. * * * @param n1 First number to compare * @param n2 Second number to compare * * @return true if n1 is less than n2 */ boolean compareNumbers(double n1, double n2) { return n1 < n2; }}/** * Compare strings or numbers for less than or equal. */class LessThanOrEqualComparator extends Comparator{ /** * Compare two strings for less than or equal. * * * @param s1 First string to compare * @param s2 Second String to compare * * @return true if s1 is less than or equal to s2 */ boolean compareStrings(XMLString s1, XMLString s2) { return (s1.toDouble() <= s2.toDouble()); // return s1.compareTo(s2) <= 0; } /** * Compare two numbers for less than or equal. * * * @param n1 First number to compare * @param n2 Second number to compare * * @return true if n1 is less than or equal to n2 */ boolean compareNumbers(double n1, double n2) { return n1 <= n2; }}/** * Compare strings or numbers for greater than. */class GreaterThanComparator extends Comparator{ /** * Compare two strings for greater than. * * * @param s1 First string to compare * @param s2 Second String to compare * * @return true if s1 is greater than s2 */ boolean compareStrings(XMLString s1, XMLString s2) { return (s1.toDouble() > s2.toDouble()); // return s1.compareTo(s2) > 0; } /** * Compare two numbers for greater than. * * * @param n1 First number to compare * @param n2 Second number to compare * * @return true if n1 is greater than n2 */ boolean compareNumbers(double n1, double n2) { return n1 > n2; }}/** * Compare strings or numbers for greater than or equal. */class GreaterThanOrEqualComparator extends Comparator{ /** * Compare two strings for greater than or equal. * * * @param s1 First string to compare * @param s2 Second String to compare * * @return true if s1 is greater than or equal to s2 */ boolean compareStrings(XMLString s1, XMLString s2) { return (s1.toDouble() >= s2.toDouble()); // return s1.compareTo(s2) >= 0; } /** * Compare two numbers for greater than or equal. * * * @param n1 First number to compare * @param n2 Second number to compare * * @return true if n1 is greater than or equal to n2 */ boolean compareNumbers(double n1, double n2) { return n1 >= n2; }}/** * Compare strings or numbers for equality. */class EqualComparator extends Comparator{ /** * Compare two strings for equality. * * * @param s1 First string to compare * @param s2 Second String to compare * * @return true if s1 is equal to s2 */ boolean compareStrings(XMLString s1, XMLString s2) { return s1.equals(s2); } /** * Compare two numbers for equality. * * * @param n1 First number to compare * @param n2 Second number to compare * * @return true if n1 is equal to n2 */ boolean compareNumbers(double n1, double n2) { return n1 == n2; }}/** * Compare strings or numbers for non-equality. */class NotEqualComparator extends Comparator{ /** * Compare two strings for non-equality. * * * @param s1 First string to compare * @param s2 Second String to compare * * @return true if s1 is not equal to s2 */ boolean compareStrings(XMLString s1, XMLString s2) { return !s1.equals(s2); } /** * Compare two numbers for non-equality. * * * @param n1 First number to compare * @param n2 Second number to compare * * @return true if n1 is not equal to n2 */ boolean compareNumbers(double n1, double n2) { return n1 != n2; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -