From 0b35e77c686bb1a25843d155530009c7d9b498e1 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Wed, 15 May 2013 11:11:56 -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. Second in the set. Change-Id: I5bf19c2bdf33bfde391f30867b27f433fc971a30 Signed-off-by: Ed Warnicke --- .../v6extension/V6StatsReply.java | 3 -- .../v6extension/V6StatsRequest.java | 30 +++++++++++++++---- .../controller/sal/action/Action.java | 18 ++++++++--- .../controller/sal/action/Output.java | 23 ++++++++++---- .../controller/sal/action/PushVlan.java | 29 ++++++++++++++---- 5 files changed, 81 insertions(+), 22 deletions(-) diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java index f88efa36a5..6893fa78e2 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java @@ -12,9 +12,6 @@ package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6e import java.nio.ByteBuffer; import java.util.List; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.openflow.protocol.action.OFAction; import org.openflow.protocol.statistics.OFVendorStatistics; import org.openflow.util.U16; diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsRequest.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsRequest.java index 26d0065a45..593b464d3c 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsRequest.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsRequest.java @@ -9,11 +9,10 @@ package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; +import java.nio.ByteBuffer; + import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.openflow.protocol.statistics.OFVendorStatistics; -import java.nio.ByteBuffer; /** @@ -140,7 +139,13 @@ public class V6StatsRequest extends OFVendorStatistics { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + match_len; + result = prime * result + msgsubtype; + result = prime * result + outPort; + result = prime * result + tableId; + return result; } @Override @@ -151,6 +156,21 @@ public class V6StatsRequest extends OFVendorStatistics { @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; + V6StatsRequest other = (V6StatsRequest) obj; + if (match_len != other.match_len) + return false; + if (msgsubtype != other.msgsubtype) + return false; + if (outPort != other.outPort) + return false; + if (tableId != other.tableId) + return false; + return true; } } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java index 5e4f5f81fa..d8144d7bb7 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java @@ -15,8 +15,6 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlTransient; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -122,12 +120,24 @@ public abstract class Action { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + ((type == null) ? 0 : type.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; + Action other = (Action) obj; + if (type != other.type) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Output.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Output.java index 8c23da8cfa..e09968836f 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Output.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Output.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.core.NodeConnector; /** @@ -46,13 +44,28 @@ public class Output 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; + Output other = (Output) obj; + if (port == null) { + if (other.port != null) + return false; + } else if (!port.equals(other.port)) + return false; + return true; } @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((port == null) ? 0 : port.hashCode()); + return result; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java index d50851ae49..f3b862fe7e 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.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; /** @@ -147,13 +145,34 @@ public class PushVlan 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; + PushVlan other = (PushVlan) obj; + if (cfi != other.cfi) + return false; + if (pcp != other.pcp) + return false; + if (tag != other.tag) + return false; + if (vlanId != other.vlanId) + return false; + return true; } @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + cfi; + result = prime * result + pcp; + result = prime * result + tag; + result = prime * result + vlanId; + return result; } @Override -- 2.36.6