svn commit: r1054173 - /lenya/docu/modules/diff/java/src/org/apache/lenya/modules/diff/xml/impl/NamedXmlNodeImpl.java
[email protected] Fri, 31 Dec 2010 21:14:03 -0000
| Newsgroups | gmane.comp.cms.lenya.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: andreas
Date: Fri Dec 31 21:14:03 2010
New Revision: 1054173
URL: http://svn.apache.org/viewvc?rev=1054173&view=rev
Log:
Avoid NPE, code simplification.
Modified:
lenya/docu/modules/diff/java/src/org/apache/lenya/modules/diff/xml/impl/NamedXmlNodeImpl.java
Modified: lenya/docu/modules/diff/java/src/org/apache/lenya/modules/diff/xml/impl/NamedXmlNodeImpl.java
URL: http://svn.apache.org/viewvc/lenya/docu/modules/diff/java/src/org/apache/lenya/modules/diff/xml/impl/NamedXmlNodeImpl.java?rev=1054173&r1=1054172&r2=1054173&view=diff
==============================================================================
--- lenya/docu/modules/diff/java/src/org/apache/lenya/modules/diff/xml/impl/NamedXmlNodeImpl.java (original)
+++ lenya/docu/modules/diff/java/src/org/apache/lenya/modules/diff/xml/impl/NamedXmlNodeImpl.java Fri Dec 31 21:14:03 2010
@@ -8,6 +8,8 @@ import org.apache.lenya.util.Assert;
public abstract class NamedXmlNodeImpl extends AbstractComparableNode implements XmlNode {
+ protected static final String NULL_VALUE = "<NULL>";
+
private String namespaceUri;
private String localName;
@@ -34,22 +36,20 @@ public abstract class NamedXmlNodeImpl e
return this.localName;
}
+ protected final String nonNullValue(final String string) {
+ return string == null ? NULL_VALUE : string;
+ }
+
+ protected boolean equals(final String s1, final String s2) {
+ return nonNullValue(s1).equals(nonNullValue(s2));
+ }
+
public boolean equals(Comparable comparable) {
if (!super.equals(comparable)) {
return false;
}
- NamedXmlNodeImpl otherNode = (NamedXmlNodeImpl) comparable;
- String otherNs = otherNode.getNamespaceUri();
- String ns = getNamespaceUri();
-
- String otherLocalName = otherNode.getLocalName();
- final String nullValue = "<NULL>";
- otherLocalName = otherLocalName == null ? nullValue : otherLocalName;
- String localName = getLocalName();
- localName = localName == null ? nullValue : localName;
-
- return ((ns == null && otherNs == null) || ns.equals(otherNs))
- && otherLocalName.equals(localName);
+ final NamedXmlNodeImpl otherNode = (NamedXmlNodeImpl) comparable;
+ return equals(getNamespaceUri(), otherNode.getNamespaceUri()) && equals(getLocalName(), otherNode.getLocalName());
}
public static final String getKey(String namespaceUri, String localName) {