Five more Equals/HashCode/StringBuilder replacements 70/370/4
authorEd Warnicke <eaw@cisco.com>
Fri, 17 May 2013 15:07:18 +0000 (08:07 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 23 May 2013 08:33:43 +0000 (08:33 +0000)
I'm intentionally breaking these up into small groups so they can
be reasonably reviewed, rather than one giant group that can't.
Contributes to fixing bug 20.

Eighth set.

Change-Id: I47e13d6ae3ecfcb574aa33c78579271eee16b2eb
Signed-off-by: Ed Warnicke <eaw@cisco.com>
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Property.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/State.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tables.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/TimeStamp.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/flowprogrammer/Flow.java

index 15d9976106f5df07c683ca37bd42d077ca970bfd..d50c81e8d79cd519968a441ac664766a8dc33fa1 100644 (file)
@@ -14,10 +14,6 @@ import java.io.Serializable;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-
 /**
  * @file   Property.java
  *
@@ -69,16 +65,31 @@ abstract public class Property implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Property other = (Property) obj;
+        if (name == null) {
+            if (other.name != null)
+                return false;
+        } else if (!name.equals(other.name))
+            return false;
+        return true;
     }
 
     @Override
     public String toString() {
-        return "Property[" + ReflectionToStringBuilder.toString(this) + "]";
+        return "Property [name=" + name + "]";
     }
 }
index 4edc1f1d232b54055b70f0db0bedba83f16b0d2c..ba67e0d8213454e76d3fc8fc9760177745e0bec9 100644 (file)
@@ -12,9 +12,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * The class represents the State property of an Edge
  *
@@ -54,12 +51,24 @@ public class State extends Property {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + stateValue;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        State other = (State) obj;
+        if (stateValue != other.stateValue)
+            return false;
+        return true;
     }
 
     @Override
index 4370c4c598aae44764bbc7d21bb356bf39bb68d9..22cff90bb5dd3a9fc7f3852e7e100ab9b5fb65ff 100644 (file)
@@ -12,9 +12,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * @file   Tables.java
  *
@@ -58,12 +55,24 @@ public class Tables extends Property {
     
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + tablesValue;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Tables other = (Tables) obj;
+        if (tablesValue != other.tablesValue)
+            return false;
+        return true;
     }
 
     @Override
index 6b2467ee5daa6f496787fcdfd3ac83e21df098ca..a15b3fa9cd10166b3179e163c80b5de7f50170ba 100644 (file)
@@ -12,9 +12,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * @file   TimeStamp.java
  *
@@ -74,12 +71,31 @@ public class TimeStamp extends Property {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
+        result = prime * result
+                + ((timestampName == null) ? 0 : timestampName.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        TimeStamp other = (TimeStamp) obj;
+        if (timestamp != other.timestamp)
+            return false;
+        if (timestampName == null) {
+            if (other.timestampName != null)
+                return false;
+        } else if (!timestampName.equals(other.timestampName))
+            return false;
+        return true;
     }
 
     @Override
index ed6d0e503394c820fd48da0236e55ac0f1850434..f56c13d34524efe0685047c005baeb71ed26130f 100644 (file)
@@ -20,8 +20,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.action.Action;
 import org.opendaylight.controller.sal.action.ActionType;
 import org.opendaylight.controller.sal.action.SetDlType;
@@ -181,12 +179,45 @@ public class Flow implements Cloneable, Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((actions == null) ? 0 : actions.hashCode());
+        result = prime * result + hardTimeout;
+        result = prime * result + (int) (id ^ (id >>> 32));
+        result = prime * result + idleTimeout;
+        result = prime * result + ((match == null) ? 0 : match.hashCode());
+        result = prime * result + priority;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Flow other = (Flow) obj;
+        if (actions == null) {
+            if (other.actions != null)
+                return false;
+        } else if (!actions.equals(other.actions))
+            return false;
+        if (hardTimeout != other.hardTimeout)
+            return false;
+        if (id != other.id)
+            return false;
+        if (idleTimeout != other.idleTimeout)
+            return false;
+        if (match == null) {
+            if (other.match != null)
+                return false;
+        } else if (!match.equals(other.match))
+            return false;
+        if (priority != other.priority)
+            return false;
+        return true;
     }
 
     @Override