[hornetq-commits] JBoss hornetq SVN: r10750 - in trunk/hornetq-commons: src and 6 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri May 27 11:41:56 EDT 2011


Author: borges
Date: 2011-05-27 11:41:56 -0400 (Fri, 27 May 2011)
New Revision: 10750

Added:
   trunk/hornetq-commons/src/test/
   trunk/hornetq-commons/src/test/java/
   trunk/hornetq-commons/src/test/java/org/
   trunk/hornetq-commons/src/test/java/org/hornetq/
   trunk/hornetq-commons/src/test/java/org/hornetq/utils/
   trunk/hornetq-commons/src/test/java/org/hornetq/utils/PairTest.java
Modified:
   trunk/hornetq-commons/pom.xml
   trunk/hornetq-commons/src/main/java/org/hornetq/api/core/Pair.java
Log:
HORNETQ-702 (temporary) Fix to hashCode calculation
(it is probably better to make the fields final)

Modified: trunk/hornetq-commons/pom.xml
===================================================================
--- trunk/hornetq-commons/pom.xml	2011-05-27 15:34:32 UTC (rev 10749)
+++ trunk/hornetq-commons/pom.xml	2011-05-27 15:41:56 UTC (rev 10750)
@@ -21,6 +21,11 @@
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
       </dependency>
+      <dependency>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+         <scope>test</scope>
+      </dependency>
    </dependencies>
 
 

Modified: trunk/hornetq-commons/src/main/java/org/hornetq/api/core/Pair.java
===================================================================
--- trunk/hornetq-commons/src/main/java/org/hornetq/api/core/Pair.java	2011-05-27 15:34:32 UTC (rev 10749)
+++ trunk/hornetq-commons/src/main/java/org/hornetq/api/core/Pair.java	2011-05-27 15:41:56 UTC (rev 10750)
@@ -16,9 +16,9 @@
 import java.io.Serializable;
 
 /**
- * 
+ *
  * A Pair is a holder for 2 objects.
- * 
+ *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  *
  */
@@ -42,6 +42,7 @@
    @Override
    public int hashCode()
    {
+      hash = -1;
       if (hash == -1)
       {
          if (a == null && b == null)
@@ -58,6 +59,7 @@
    }
 
    @Override
+   @SuppressWarnings("rawtypes")
    public boolean equals(final Object other)
    {
       if (other == this)
@@ -70,7 +72,7 @@
          return false;
       }
 
-      Pair<A, B> pother = (Pair<A, B>)other;
+      Pair pother = (Pair)other;
 
       return (pother.a == null ? a == null : pother.a.equals(a)) && (pother.b == null ? b == null : pother.b.equals(b));
 

Added: trunk/hornetq-commons/src/test/java/org/hornetq/utils/PairTest.java
===================================================================
--- trunk/hornetq-commons/src/test/java/org/hornetq/utils/PairTest.java	                        (rev 0)
+++ trunk/hornetq-commons/src/test/java/org/hornetq/utils/PairTest.java	2011-05-27 15:41:56 UTC (rev 10750)
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.utils;
+
+import junit.framework.TestCase;
+
+import org.hornetq.api.core.Pair;
+
+public class PairTest extends TestCase
+{
+
+   public void testPair()
+   {
+      Pair<Integer, Integer> p = new Pair<Integer, Integer>(Integer.valueOf(12), Integer.valueOf(13));
+      int hash = p.hashCode();
+      p.a = null;
+      assertTrue(hash != p.hashCode());
+   }
+}



More information about the hornetq-commits mailing list