From 5d121f4f8efb3f08ced19d6378c45166701bf318 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Wed, 15 May 2013 11:31:48 -0500 Subject: [PATCH] Seven 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. Fifth set. Change-Id: I905753ad4b1c2f6947fae8c447de27e091aa7519 Signed-off-by: Ed Warnicke --- .../sal/authorization/Resource.java | 27 +++++++++++++++---- .../sal/authorization/ResourceGroup.java | 27 +++++++++++++++---- .../controller/sal/core/Actions.java | 19 +++++++++---- .../controller/sal/core/Bandwidth.java | 20 ++++++++++---- .../controller/sal/core/Buffers.java | 19 +++++++++---- .../controller/sal/core/Capabilities.java | 19 +++++++++---- .../controller/sal/core/Config.java | 19 +++++++++---- 7 files changed, 115 insertions(+), 35 deletions(-) diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/Resource.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/Resource.java index ef8744b551..9cf7420d1b 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/Resource.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/Resource.java @@ -11,9 +11,6 @@ package org.opendaylight.controller.sal.authorization; import java.io.Serializable; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - /** * It represents the elementary resource along with * the access privilege associated to it @@ -38,12 +35,32 @@ public class Resource implements Serializable { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + + ((privilege == null) ? 0 : privilege.hashCode()); + result = prime * result + + ((resource == null) ? 0 : resource.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; + Resource other = (Resource) obj; + if (privilege != other.privilege) + return false; + if (resource == null) { + if (other.resource != null) + return false; + } else if (!resource.equals(other.resource)) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/ResourceGroup.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/ResourceGroup.java index 61e44dda4b..5a2a17f6cf 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/ResourceGroup.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/ResourceGroup.java @@ -11,9 +11,6 @@ package org.opendaylight.controller.sal.authorization; import java.io.Serializable; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - /** * Represents a group of resources along with the privilege associated to it * @@ -48,12 +45,32 @@ public class ResourceGroup implements Serializable { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + + ((groupName == null) ? 0 : groupName.hashCode()); + result = prime * result + + ((privilege == null) ? 0 : privilege.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; + ResourceGroup other = (ResourceGroup) obj; + if (groupName == null) { + if (other.groupName != null) + return false; + } else if (!groupName.equals(other.groupName)) + return false; + if (privilege != other.privilege) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java index 6fb38a3a90..3f81d0c4c5 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java @@ -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 Actions.java * @@ -83,12 +80,24 @@ public class Actions extends Property { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + actionsValue; + 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; + Actions other = (Actions) obj; + if (actionsValue != other.actionsValue) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Bandwidth.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Bandwidth.java index 32f661ca5f..fa5cc10827 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Bandwidth.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Bandwidth.java @@ -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 BandWidth.java * @@ -84,12 +81,25 @@ public class Bandwidth extends Property { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + + (int) (bandwidthValue ^ (bandwidthValue >>> 32)); + 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; + Bandwidth other = (Bandwidth) obj; + if (bandwidthValue != other.bandwidthValue) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Buffers.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Buffers.java index 91f647d45b..991ed688f2 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Buffers.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Buffers.java @@ -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 Buffers.java * @@ -59,12 +56,24 @@ public class Buffers extends Property { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + buffersValue; + 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; + Buffers other = (Buffers) obj; + if (buffersValue != other.buffersValue) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Capabilities.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Capabilities.java index d4c8cd1b56..a41a0e2290 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Capabilities.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Capabilities.java @@ -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 Capabilities.java * @@ -76,12 +73,24 @@ public class Capabilities extends Property { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + capabilitiesValue; + 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; + Capabilities other = (Capabilities) obj; + if (capabilitiesValue != other.capabilitiesValue) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Config.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Config.java index f8a48997f8..c547c2bb45 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Config.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Config.java @@ -11,9 +11,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 Admin Config status * @@ -53,12 +50,24 @@ public class Config extends Property { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + configValue; + 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; + Config other = (Config) obj; + if (configValue != other.configValue) + return false; + return true; } @Override -- 2.36.6