ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1794388 - in /webservices/neethi/trunk/src/main/java/org/apache/neethi/builders: PolicyContainingPrimitiveAssertion.java PrimitiveAssertion.java
Date Mon, 08 May 2017 15:12:04 GMT
Author: dkulp
Date: Mon May  8 15:12:04 2017
New Revision: 1794388

URL: http://svn.apache.org/viewvc?rev=1794388&view=rev
Log:
[NEETHI-18] Add equals/hashCode to PrimitiveAssertion
Patch from Adrei Shakirin applied

Modified:
    webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
    webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java

Modified: webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
URL: http://svn.apache.org/viewvc/webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java?rev=1794388&r1=1794387&r2=1794388&view=diff
==============================================================================
--- webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
(original)
+++ webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
Mon May  8 15:12:04 2017
@@ -104,6 +104,25 @@ public class PolicyContainingPrimitiveAs
         return getPolicy().equal(other.getPolicy());
     }
     
+    @Override
+    public boolean equals(Object obj) {
+      if (!(obj instanceof PolicyContainingPrimitiveAssertion)) {
+          return false;
+      }
+      
+      PolicyContainingPrimitiveAssertion pa = (PolicyContainingPrimitiveAssertion) obj;
+      
+      if (!super.equals(obj)) {
+          return false;
+      }
+      
+      if (!getPolicy().equal(pa.getPolicy())) {
+          return false;
+      }
+      
+      return true;
+    }
+    
     public void setPolicy(Policy n) {
         nested = n;
     }

Modified: webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
URL: http://svn.apache.org/viewvc/webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java?rev=1794388&r1=1794387&r2=1794388&view=diff
==============================================================================
--- webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
(original)
+++ webservices/neethi/trunk/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
Mon May  8 15:12:04 2017
@@ -20,6 +20,7 @@
 package org.apache.neethi.builders;
 
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -80,6 +81,15 @@ public class PrimitiveAssertion implemen
         }
         return null;
     }
+
+    public Map<QName, String> getAttributes() {
+        if (attributes != null) {
+            return new HashMap<QName, String>(attributes);
+        } else {
+            return Collections.emptyMap();
+        }
+    }
+
     public synchronized void addAttribute(QName n, String value) {
         if (attributes == null) {
             attributes = new HashMap<QName, String>();
@@ -113,6 +123,61 @@ public class PrimitiveAssertion implemen
         return getName().equals(((Assertion)policyComponent).getName());
     }
 
+    @Override
+    public boolean equals(Object obj) {
+      if (!(obj instanceof PrimitiveAssertion)) {
+          return false;
+      }
+      
+      PrimitiveAssertion pa = (PrimitiveAssertion) obj;
+      
+      if ((pa.getName() != null) && (!pa.getName().equals(this.getName()))) {
+          return false;
+      }
+      
+      if ((this.getName() != null) && (!this.getName().equals(pa.getName()))) {
+          return false;
+      }
+
+      if ((pa.isOptional() ^ this.isOptional()) || (pa.isIgnorable() ^ this.isIgnorable()))
{
+          return false;
+      }
+
+      if ( (pa.getTextValue() != null) && (!pa.getTextValue().equals(this.getTextValue())))
{
+          return false;
+      }
+
+      if ( (this.getTextValue() != null) && (!this.getTextValue().equals(pa.getTextValue())))
{
+          return false;
+      }
+      
+      Map<QName, String> attrs1 = getAttributes();
+      Map<QName, String> attrs2 = pa.getAttributes();
+      for (QName key : attrs1.keySet()) {
+          if ((!attrs2.containsKey(key)) || (!attrs1.get(key).equals(attrs2.get(key)))) {
+              return false;
+          } else {
+              attrs2.remove(key);
+          }
+      }
+      if (!attrs2.isEmpty()) {
+          return false;
+      }
+      
+      return true;
+    }
+    
+
+    @Override
+    public int hashCode() {
+        int hash = 17;
+        hash = 31 * hash + (name != null ? name.hashCode() : 0);
+        hash = 31 * hash + ((optional) ? 1 : 0);
+        hash = 31 * hash + ((ignorable) ? 1 : 0);
+        hash = 31 * hash + (textValue != null ? textValue.hashCode() : 0);
+        return hash;
+    }
+
     public short getType() {
         return Constants.TYPE_ASSERTION;
     }
@@ -256,4 +321,4 @@ public class PrimitiveAssertion implemen
         return new PrimitiveAssertion(name, isoptional, ignorable, attributes, textValue);
     }
 
-}
\ No newline at end of file
+}



Mime
View raw message