Author: mbenson
Date: Tue Mar 2 19:14:35 2010
New Revision: 918156
URL: http://svn.apache.org/viewvc?rev=918156&view=rev
Log:
[JXPATH-133] use == or .equals on parent node comparison in compareTo();
associated refactorings
Modified:
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
Modified:
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
URL:
http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java?rev=918156&r1=918155&r2=918156&view=diff
==============================================================================
---
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
(original)
+++
commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
Tue Mar 2 19:14:35 2010
@@ -422,10 +422,10 @@
String testPrefix = testName.getPrefix();
String nodePrefix = nodeName.getPrefix();
- if (!equalStrings(testPrefix, nodePrefix)) {
+ if (!safeEquals(testPrefix, nodePrefix)) {
String testNS = getNamespaceURI(testPrefix);
String nodeNS = getNamespaceURI(nodePrefix);
- if (!equalStrings(testNS, nodeNS)) {
+ if (!safeEquals(testNS, nodeNS)) {
return false;
}
}
@@ -439,16 +439,6 @@
}
/**
- * Compare two strings, either of which may be null, for equality.
- * @param s1 the first String to compare
- * @param s2 the second String to compare
- * @return true if both Strings are null, same or equal
- */
- private static boolean equalStrings(String s1, String s2) {
- return s1 == s2 || s1 != null && s1.equals(s2);
- }
-
- /**
* Called directly by JXPathContext. Must create path and
* set value.
* @param context the owning JXPathContext
@@ -740,7 +730,7 @@
}
// Let it throw a ClassCastException
NodePointer pointer = (NodePointer) object;
- if (parent == pointer.parent) {
+ if (safeEquals(parent, pointer.parent)) {
return parent == null ? 0 : parent.compareChildNodePointers(this,
pointer);
}
@@ -791,7 +781,7 @@
return r == 0 ? 1 : r;
}
//henceforth depth1 == depth2:
- if (p1 == p2 || p1 != null && p1.equals(p2)) {
+ if (safeEquals(p1, p2)) {
return 0;
}
if (depth1 == 1) {
@@ -920,4 +910,8 @@
printDeep(pointer.getImmediateParentPointer(), indent + " ");
}
}
+
+ private static boolean safeEquals(Object o1, Object o2) {
+ return o1 == o2 || o1 != null && o1.equals(o2);
+ }
}