Author: borges
Date: 2012-01-09 06:18:03 -0500 (Mon, 09 Jan 2012)
New Revision: 12001
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/PacketImpl.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationFailedMessage.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationMessage.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/DisconnectMessage.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/HornetQExceptionMessage.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/PacketsConfirmedMessage.java
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/Ping.java
trunk/hornetq-core/src/main/java/org/hornetq/core/version/impl/VersionImpl.java
Log:
Override equals and hashCode consistently.
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/PacketImpl.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/PacketImpl.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/PacketImpl.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -14,7 +14,6 @@
package org.hornetq.core.protocol.core.impl;
import org.hornetq.api.core.HornetQBuffer;
-import org.hornetq.core.logging.Logger;
import org.hornetq.core.protocol.core.Packet;
import org.hornetq.spi.core.protocol.RemotingConnection;
import org.hornetq.utils.DataConstants;
@@ -28,9 +27,8 @@
{
// Constants
-------------------------------------------------------------------------
- private static final Logger log = Logger.getLogger(PacketImpl.class);
-
- // The minimal size for all the packets, Common data for all the packets (look at
PacketImpl.encode)
+ // The minimal size for all the packets, Common data for all the packets (look at
+ // PacketImpl.encode)
public static final int PACKET_HEADERS_SIZE = DataConstants.SIZE_INT +
DataConstants.SIZE_BYTE +
DataConstants.SIZE_LONG;
@@ -302,20 +300,31 @@
}
@Override
- public boolean equals(final Object other)
+ public int hashCode()
{
- if (other instanceof PacketImpl == false)
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int)(channelID ^ (channelID >>> 32));
+ result = prime * result + size;
+ result = prime * result + type;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
{
+ return true;
+ }
+ if (!(obj instanceof PacketImpl))
+ {
return false;
}
-
- PacketImpl r = (PacketImpl)other;
-
- return r.type == type && r.channelID == channelID;
+ PacketImpl other = (PacketImpl)obj;
+ return (channelID == other.channelID) && (size == other.size) &&
(type != other.type);
}
- // Package protected ---------------------------------------------
-
protected String getParentString()
{
return "PACKET(" + this.getClass().getSimpleName() + ")[type="
+ type + ", channelID=" + channelID + ", packetObject=" +
this.getClass().getSimpleName();
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationFailedMessage.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationFailedMessage.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationFailedMessage.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -79,4 +79,41 @@
errorCode = buffer.readInt();
}
}
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + errorCode;
+ result = prime * result + ((problem == null) ? 0 : problem.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof BackupRegistrationFailedMessage))
+ {
+ return false;
+ }
+ BackupRegistrationFailedMessage other = (BackupRegistrationFailedMessage)obj;
+ if (errorCode != other.errorCode)
+ {
+ return false;
+ }
+ if (problem != other.problem)
+ {
+ return false;
+ }
+ return true;
+ }
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationMessage.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationMessage.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/BackupRegistrationMessage.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -83,4 +83,79 @@
return clusterPassword;
}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((clusterPassword == null) ? 0 :
clusterPassword.hashCode());
+ result = prime * result + ((clusterUser == null) ? 0 : clusterUser.hashCode());
+ result = prime * result + ((connector == null) ? 0 : connector.hashCode());
+ result = prime * result + ((nodeID == null) ? 0 : nodeID.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof BackupRegistrationMessage))
+ {
+ return false;
+ }
+ BackupRegistrationMessage other = (BackupRegistrationMessage)obj;
+ if (clusterPassword == null)
+ {
+ if (other.clusterPassword != null)
+ {
+ return false;
+ }
+ }
+ else if (!clusterPassword.equals(other.clusterPassword))
+ {
+ return false;
+ }
+ if (clusterUser == null)
+ {
+ if (other.clusterUser != null)
+ {
+ return false;
+ }
+ }
+ else if (!clusterUser.equals(other.clusterUser))
+ {
+ return false;
+ }
+ if (connector == null)
+ {
+ if (other.connector != null)
+ {
+ return false;
+ }
+ }
+ else if (!connector.equals(other.connector))
+ {
+ return false;
+ }
+ if (nodeID == null)
+ {
+ if (other.nodeID != null)
+ {
+ return false;
+ }
+ }
+ else if (!nodeID.equals(other.nodeID))
+ {
+ return false;
+ }
+ return true;
+ }
+
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/DisconnectMessage.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/DisconnectMessage.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/DisconnectMessage.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -17,13 +17,6 @@
import org.hornetq.api.core.SimpleString;
import org.hornetq.core.protocol.core.impl.PacketImpl;
-/**
- *
- * A Ping
- *
- * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- *
- */
public class DisconnectMessage extends PacketImpl
{
// Constants -----------------------------------------------------
@@ -31,7 +24,7 @@
// Attributes ----------------------------------------------------
private SimpleString nodeID;
-
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -77,29 +70,47 @@
}
@Override
- public boolean equals(final Object other)
+ public final boolean isRequiresConfirmations()
{
- if (other instanceof DisconnectMessage == false)
- {
- return false;
- }
+ return false;
+ }
- DisconnectMessage r = (DisconnectMessage)other;
-
- return super.equals(other) && nodeID.equals(r.nodeID);
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((nodeID == null) ? 0 : nodeID.hashCode());
+ return result;
}
@Override
- public final boolean isRequiresConfirmations()
+ public boolean equals(Object obj)
{
- return false;
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof DisconnectMessage))
+ {
+ return false;
+ }
+ DisconnectMessage other = (DisconnectMessage)obj;
+ if (nodeID == null)
+ {
+ if (other.nodeID != null)
+ {
+ return false;
+ }
+ }
+ else if (!nodeID.equals(other.nodeID))
+ {
+ return false;
+ }
+ return true;
}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/HornetQExceptionMessage.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/HornetQExceptionMessage.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/HornetQExceptionMessage.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -15,24 +15,15 @@
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.api.core.HornetQException;
-import org.hornetq.core.logging.Logger;
import org.hornetq.core.protocol.core.impl.PacketImpl;
/**
* @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- *
- * @version <tt>$Revision$</tt>
- *
*/
public class HornetQExceptionMessage extends PacketImpl
{
- // Constants -----------------------------------------------------
- private static final Logger log = Logger.getLogger(HornetQExceptionMessage.class);
-
- // Attributes ----------------------------------------------------
-
private HornetQException exception;
// Static --------------------------------------------------------
@@ -87,23 +78,41 @@
}
@Override
- public boolean equals(final Object other)
+ public int hashCode()
{
- if (other instanceof HornetQExceptionMessage == false)
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((exception == null) ? 0 : exception.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
{
+ return true;
+ }
+ if (!super.equals(obj))
+ {
return false;
}
-
- HornetQExceptionMessage r = (HornetQExceptionMessage)other;
-
- return super.equals(other) && exception.equals(r.exception);
+ if (!(obj instanceof HornetQExceptionMessage))
+ {
+ return false;
+ }
+ HornetQExceptionMessage other = (HornetQExceptionMessage)obj;
+ if (exception == null)
+ {
+ if (other.exception != null)
+ {
+ return false;
+ }
+ }
+ else if (!exception.equals(other.exception))
+ {
+ return false;
+ }
+ return true;
}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/PacketsConfirmedMessage.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/PacketsConfirmedMessage.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/PacketsConfirmedMessage.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -17,9 +17,9 @@
import org.hornetq.core.protocol.core.impl.PacketImpl;
/**
- *
+ *
* A PacketsConfirmedMessage
- *
+ *
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
*
*/
@@ -66,36 +66,48 @@
commandID = buffer.readInt();
}
+
@Override
+ public final boolean isRequiresConfirmations()
+ {
+ return false;
+ }
+
+ @Override
public String toString()
{
return getParentString() + ", commandID=" + commandID + "]";
}
@Override
- public boolean equals(final Object other)
+ public int hashCode()
{
- if (other instanceof PacketsConfirmedMessage == false)
- {
- return false;
- }
-
- PacketsConfirmedMessage r = (PacketsConfirmedMessage)other;
-
- return super.equals(other) && commandID == r.commandID;
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + commandID;
+ return result;
}
@Override
- public final boolean isRequiresConfirmations()
+ public boolean equals(Object obj)
{
- return false;
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof PacketsConfirmedMessage))
+ {
+ return false;
+ }
+ PacketsConfirmedMessage other = (PacketsConfirmedMessage)obj;
+ if (commandID != other.commandID)
+ {
+ return false;
+ }
+ return true;
}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
}
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/Ping.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/Ping.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/protocol/core/impl/wireformat/Ping.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -20,12 +20,12 @@
import org.hornetq.spi.core.protocol.RemotingConnection;
/**
- *
+ *
* Ping is sent on the client side at {@link ClientSessionFactoryImpl}
* At the server's side is treated at {@link RemotingServiceImpl}
- *
+ *
* @See {@link RemotingConnection#checkDataReceived()}
- *
+ *
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
*
*/
@@ -73,6 +73,12 @@
}
@Override
+ public final boolean isRequiresConfirmations()
+ {
+ return false;
+ }
+
+ @Override
public String toString()
{
StringBuffer buf = new StringBuffer(getParentString());
@@ -82,29 +88,34 @@
}
@Override
- public boolean equals(final Object other)
+ public int hashCode()
{
- if (other instanceof Ping == false)
- {
- return false;
- }
-
- Ping r = (Ping)other;
-
- return super.equals(other) && connectionTTL == r.connectionTTL;
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + (int)(connectionTTL ^ (connectionTTL >>> 32));
+ return result;
}
@Override
- public final boolean isRequiresConfirmations()
+ public boolean equals(Object obj)
{
- return false;
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!super.equals(obj))
+ {
+ return false;
+ }
+ if (!(obj instanceof Ping))
+ {
+ return false;
+ }
+ Ping other = (Ping)obj;
+ if (connectionTTL != other.connectionTTL)
+ {
+ return false;
+ }
+ return true;
}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
}
Modified: trunk/hornetq-core/src/main/java/org/hornetq/core/version/impl/VersionImpl.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/version/impl/VersionImpl.java 2012-01-09
11:17:36 UTC (rev 12000)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/version/impl/VersionImpl.java 2012-01-09
11:18:03 UTC (rev 12001)
@@ -14,8 +14,8 @@
package org.hornetq.core.version.impl;
import java.io.Serializable;
+import java.util.Arrays;
-import org.hornetq.core.logging.Logger;
import org.hornetq.core.version.Version;
/**
@@ -25,16 +25,8 @@
*/
public class VersionImpl implements Version, Serializable
{
- // Constants -----------------------------------------------------
-
private static final long serialVersionUID = -5271227256591080403L;
- private static final Logger log = Logger.getLogger(VersionImpl.class);
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
private final String versionName;
private final int majorVersion;
@@ -46,7 +38,7 @@
private final int incrementingVersion;
private final String versionSuffix;
-
+
private final String nettyVersion;
private final int[] compatibleVersionList;
@@ -75,7 +67,7 @@
this.versionSuffix = versionSuffix;
this.nettyVersion = nettyVersion;
-
+
this.compatibleVersionList = compatibleVersionList;
}
@@ -136,33 +128,91 @@
return compatibleVersionList;
}
- // Public -------------------------------------------------------
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(compatibleVersionList);
+ result = prime * result + incrementingVersion;
+ result = prime * result + majorVersion;
+ result = prime * result + microVersion;
+ result = prime * result + minorVersion;
+ result = prime * result + ((nettyVersion == null) ? 0 : nettyVersion.hashCode());
+ result = prime * result + ((versionName == null) ? 0 : versionName.hashCode());
+ result = prime * result + ((versionSuffix == null) ? 0 :
versionSuffix.hashCode());
+ return result;
+ }
@Override
- public boolean equals(final Object other)
+ public boolean equals(Object obj)
{
- if (other == this)
+ if (this == obj)
{
return true;
}
- if (other instanceof Version == false)
+ if (obj == null)
{
return false;
}
- Version v = (Version)other;
-
- return versionName.equals(v.getVersionName()) && majorVersion ==
v.getMajorVersion() &&
- minorVersion == v.getMinorVersion() &&
- microVersion == v.getMicroVersion() &&
- versionSuffix.equals(v.getVersionSuffix()) &&
- incrementingVersion == v.getIncrementingVersion();
+ if (!(obj instanceof VersionImpl))
+ {
+ return false;
+ }
+ VersionImpl other = (VersionImpl)obj;
+ if (!Arrays.equals(compatibleVersionList, other.compatibleVersionList))
+ {
+ return false;
+ }
+ if (incrementingVersion != other.incrementingVersion)
+ {
+ return false;
+ }
+ if (majorVersion != other.majorVersion)
+ {
+ return false;
+ }
+ if (microVersion != other.microVersion)
+ {
+ return false;
+ }
+ if (minorVersion != other.minorVersion)
+ {
+ return false;
+ }
+ if (nettyVersion == null)
+ {
+ if (other.nettyVersion != null)
+ {
+ return false;
+ }
+ }
+ else if (!nettyVersion.equals(other.nettyVersion))
+ {
+ return false;
+ }
+ if (versionName == null)
+ {
+ if (other.versionName != null)
+ {
+ return false;
+ }
+ }
+ else if (!versionName.equals(other.versionName))
+ {
+ return false;
+ }
+ if (versionSuffix == null)
+ {
+ if (other.versionSuffix != null)
+ {
+ return false;
+ }
+ }
+ else if (!versionSuffix.equals(other.versionSuffix))
+ {
+ return false;
+ }
+ return true;
}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
}