Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 32830 invoked from network); 2 Mar 2010 19:15:03 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Mar 2010 19:15:03 -0000 Received: (qmail 43237 invoked by uid 500); 2 Mar 2010 19:14:58 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 43188 invoked by uid 500); 2 Mar 2010 19:14:58 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 43180 invoked by uid 99); 2 Mar 2010 19:14:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 19:14:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 19:14:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 852AE2388900; Tue, 2 Mar 2010 19:14:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r918156 - /commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java Date: Tue, 02 Mar 2010 19:14:35 -0000 To: commits@commons.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100302191435.852AE2388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); + } }