From a5c550a84aa96ecd6225654133599d3041d9ffe5 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Wed, 15 May 2013 11:14:48 -0500 Subject: [PATCH] Five more Equals/HashCode/StringBuilder replacements 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. Third in the set. Change-Id: If8008c7e9db88022edd50fbc36f82cd32cdb6bad Signed-off-by: Ed Warnicke --- .../controller/sal/action/SetDlDst.java | 22 +++++++++++++---- .../controller/sal/action/SetDlSrc.java | 22 +++++++++++++---- .../controller/sal/action/SetDlType.java | 20 ++++++++++++---- .../controller/sal/action/SetNwDst.java | 24 ++++++++++++++----- .../controller/sal/action/SetNwSrc.java | 24 ++++++++++++++----- 5 files changed, 85 insertions(+), 27 deletions(-) diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlDst.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlDst.java index 53c2806443..2413c23314 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlDst.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlDst.java @@ -9,13 +9,13 @@ package org.opendaylight.controller.sal.action; +import java.util.Arrays; + import javax.xml.bind.annotation.XmlAccessType; 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.utils.HexEncode; /** @@ -52,13 +52,25 @@ public class SetDlDst extends Action { } @Override - public boolean equals(Object other) { - return EqualsBuilder.reflectionEquals(this, other); + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + SetDlDst other = (SetDlDst) obj; + if (!Arrays.equals(address, other.address)) + return false; + return true; } @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Arrays.hashCode(address); + return result; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlSrc.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlSrc.java index 9d31fe274e..3cdd5b6170 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlSrc.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlSrc.java @@ -9,13 +9,13 @@ package org.opendaylight.controller.sal.action; +import java.util.Arrays; + import javax.xml.bind.annotation.XmlAccessType; 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.utils.HexEncode; /** @@ -56,13 +56,25 @@ public class SetDlSrc extends Action { } @Override - public boolean equals(Object other) { - return EqualsBuilder.reflectionEquals(this, other); + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + SetDlSrc other = (SetDlSrc) obj; + if (!Arrays.equals(address, other.address)) + return false; + return true; } @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Arrays.hashCode(address); + return result; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlType.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlType.java index 51a24a6ac2..f76000c649 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlType.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetDlType.java @@ -14,8 +14,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.utils.EtherTypes; /** @@ -55,13 +53,25 @@ public class SetDlType extends Action { } @Override - public boolean equals(Object other) { - return EqualsBuilder.reflectionEquals(this, other); + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + SetDlType other = (SetDlType) obj; + if (dlType != other.dlType) + return false; + return true; } @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + dlType; + return result; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwDst.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwDst.java index 7db7081ab9..bccca3f1f2 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwDst.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwDst.java @@ -16,9 +16,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; - /** * Set network destination address action */ @@ -53,13 +50,28 @@ public class SetNwDst extends Action { } @Override - public boolean equals(Object other) { - return EqualsBuilder.reflectionEquals(this, other); + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + SetNwDst other = (SetNwDst) obj; + if (address == null) { + if (other.address != null) + return false; + } else if (!address.equals(other.address)) + return false; + return true; } @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((address == null) ? 0 : address.hashCode()); + return result; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwSrc.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwSrc.java index 3e75e47502..5595b610de 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwSrc.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SetNwSrc.java @@ -16,9 +16,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; - /** * Set network source address action */ @@ -53,13 +50,28 @@ public class SetNwSrc extends Action { } @Override - public boolean equals(Object other) { - return EqualsBuilder.reflectionEquals(this, other); + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + SetNwSrc other = (SetNwSrc) obj; + if (address == null) { + if (other.address != null) + return false; + } else if (!address.equals(other.address)) + return false; + return true; } @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((address == null) ? 0 : address.hashCode()); + return result; } @Override -- 2.36.6