ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1685914 - in /webservices/axiom/trunk: implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/...
Date Tue, 16 Jun 2015 21:46:34 GMT
Author: veithen
Date: Tue Jun 16 21:46:34 2015
New Revision: 1685914

URL: http://svn.apache.org/r1685914
Log:
Remove equals and hashCode from OMAttribute implementations.

Rationale:

1. The fact that OMAttribute implementations support equals and hashCode is not mentioned
in the Javadoc of the public API.

2. The implementation uses the following condition:

return (namespace == null ? other.getNamespace() == null :
        namespace.equals(other.getNamespace()) &&
        localName.equals(other.getLocalName()) &&
        (value == null ? other.getAttributeValue() == null :
                value.equals(other.getAttributeValue())));

This is wrong. Since the ternary operator has lower precedence than &&, this code
will compare the local names and values only if the attribute has a namespace. Sure enough
the existing test case didn't test this code on attributes without namespace. Since the code
is so badly broken and nobody ever complained, it is safe to assume that nobody actually relies
on OMAttribute implementing equals and hashCode.

3. It is hard to see what the use case for this feature would be.

Removed:
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/attribute/TestEqualsHashCode.java
Modified:
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
    webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1685914&r1=1685913&r2=1685914&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
Tue Jun 16 21:46:34 2015
@@ -260,73 +260,6 @@ public class AttrImpl extends RootNode i
                 + ":" + localName;
     }
 
-    /**
-     * An instance of <code>AttrImpl</code> can act as an <code>OMAttribute</code>
and as well as an
-     * <code>org.w3c.dom.Attr</code>. So we first check if the object to compare
with (<code>obj</code>)
-     * is of type <code>OMAttribute</code> (this includes instances of <code>OMAttributeImpl</code>
or
-     * <code>AttrImpl</code> (instances of this class)). If so we check for the
equality
-     * of namespaces first (note that if the namespace of this instance is null then for
the <code>obj</code>
-     * to be equal its namespace must also be null). This condition solely doesn't determine
the equality.
-     * So we check for the equality of names and values (note that the value can also be
null in which case
-     * the same argument holds as that for the namespace) of the two instances. If all three
conditions are
-     * met then we say the two instances are equal.
-     *
-     * <p>If <code>obj</code> is of type <code>org.w3c.dom.Attr</code>
then we perform the same equality check
-     * as before. Note that, however, the implementation of the test for equality in this
case is little different
-     * than before.
-     *
-     * <p>If <code>obj</code> is neither of type <code>OMAttribute</code>
nor of type <code>org.w3c.dom.Attr</code>
-     * then we return false.
-     *
-     * @param obj The object to compare with this instance
-     * @return True if the two objects are equal or else false. The equality is checked as
explained above.
-     */
-    public boolean equals(Object obj) {
-        OMNamespace namespace = getNamespace();
-        String localName = getLocalName();
-        String attrValue = getValue();
-        if (obj instanceof OMAttribute) { // Checks equality of an OMAttributeImpl or an
AttrImpl with this instance
-            OMAttribute other = (OMAttribute) obj;
-            return (namespace == null ? other.getNamespace() == null :
-                    namespace.equals(other.getNamespace()) &&
-                    localName.equals(other.getLocalName()) &&
-                    (attrValue == null ? other.getAttributeValue() == null :
-                            attrValue.toString().equals(other.getAttributeValue())));
-        } else if (obj instanceof Attr) {// Checks equality of an org.w3c.dom.Attr with this
instance
-            Attr other = (Attr)obj;
-            String otherNs = other.getNamespaceURI();
-            if (namespace == null) { // I don't have a namespace
-                if (otherNs != null) {
-                    return false; // I don't have a namespace and the other has. So return
false
-                } else {
-                    // Both of us don't have namespaces. So check for name and value equality
only
-                    return (localName.equals(other.getLocalName()) &&
-                            (attrValue == null ? other.getValue() == null :
-                                    attrValue.toString().equals(other.getValue())));
-                }
-            } else { // Ok, now I've a namespace
-                String ns = namespace.getNamespaceURI();
-                String prefix = namespace.getPrefix();
-                String otherPrefix = other.getPrefix();
-                // First check for namespaceURI equality. Then check for prefix equality.
-                // Then check for name and value equality
-                return (ns.equals(otherNs) && (prefix == null ? otherPrefix == null
: prefix.equals(otherPrefix)) &&
-                        (localName.equals(other.getLocalName())) &&
-                        (attrValue == null ? other.getValue() == null :
-                                attrValue.toString().equals(other.getValue())));
-            }
-        }
-        return false;
-    }
-
-    public int hashCode() {
-        OMNamespace namespace = getNamespace();
-        String localName = getLocalName();
-        String attrValue = getValue();
-        return localName.hashCode() ^ (attrValue != null ? attrValue.toString().hashCode()
: 0) ^
-                (namespace != null ? namespace.hashCode() : 0);
-    }
-
     ParentNode shallowClone(OMCloneOptions options, ParentNode targetParent, boolean namespaceRepairing)
{
         // Note: targetParent is always null here
         return new AttrImpl(getLocalName(), getNamespace(), type, getOMFactory());

Modified: webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java?rev=1685914&r1=1685913&r2=1685914&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMAttributeImpl.java
Tue Jun 16 21:46:34 2015
@@ -99,45 +99,6 @@ public class OMAttributeImpl extends OMI
         return this.factory;
     }
 
-    /**
-     * Checks for the equality of two <code>OMAttribute</code> instances. Thus
the object to compare
-     * this with may be an instance of <code>OMAttributeImpl</code> (an instance
of this class) or
-     * an instance of <code>AttrImpl</code>. The method returns false for any
object of type other
-     * than <code>OMAttribute</code>.
-     *
-     * <p>We check for the equality of namespaces first (note that if the namespace
of this instance is null
-     * then for the <code>obj</code> to be equal its namespace must also be null).
This condition solely
-     * doesn't determine the equality. So we check for the equality of names and values (note
that the value
-     * can also be null in which case the same argument holds as that for the namespace)
of the two instances.
-     * If all three conditions are met then we say the two instances are equal.
-     *
-     * Note: We ignore the owner when checking for the equality. This is simply because the
owner is
-     * introduced just to keep things simple for the programmer and not as part of an attribute
itself.
-     *
-     * @param obj The object to compare with this instance.
-     * @return True if obj is equal to this or else false.
-     */
-    public boolean equals(Object obj) {
-        if (! (obj instanceof OMAttribute)) return false;
-        OMAttribute other = (OMAttribute)obj;
-        OMNamespace namespace = getNamespace();
-        String localName = getLocalName();
-        //first check namespace then localName then value to improve performance
-        return (namespace == null ? other.getNamespace() == null :
-                namespace.equals(other.getNamespace()) &&
-                localName.equals(other.getLocalName()) &&
-                (value == null ? other.getAttributeValue() == null :
-                        value.equals(other.getAttributeValue())));
-
-    }
-
-    public int hashCode() {
-        OMNamespace namespace = getNamespace();
-        String localName = getLocalName();
-        return localName.hashCode() ^ (value != null ? value.hashCode() : 0) ^
-                (namespace != null ? namespace.hashCode() : 0);
-    }
-
     public OMInformationItem clone(OMCloneOptions options) {
         return new OMAttributeImpl(getLocalName(), getNamespace(), value, factory);
     }

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1685914&r1=1685913&r2=1685914&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Tue Jun 16 21:46:34 2015
@@ -67,7 +67,6 @@ public class OMTestSuiteBuilder extends
     protected void addTests() {
         addTest(new org.apache.axiom.ts.om.attribute.TestDigestWithNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.attribute.TestDigestWithoutNamespace(metaFactory));
-        addTest(new org.apache.axiom.ts.om.attribute.TestEqualsHashCode(metaFactory));
         addTest(new org.apache.axiom.ts.om.attribute.TestGetAttributeTypeDefault(metaFactory));
         addTest(new org.apache.axiom.ts.om.attribute.TestGetNamespaceNormalized(metaFactory));
         addTest(new org.apache.axiom.ts.om.attribute.TestGetNamespaceURIWithNamespace(metaFactory));



Mime
View raw message