[utilities COMMIT] in /java-support/trunk/src: main/java/net/shibboleth/utilities/java/support/collection/Pair.java t...

noreply at shibboleth.net noreply at shibboleth.net
Thu Jan 5 10:26:44 GMT 2012


Author: rdw
Date: Thu Jan  5 10:26:44 2012
New Revision: 189

URL: http://svn.shibboleth.net/view/utilities?rev=189&view=rev
Log:
Pair.hashCode now uses com.google.common.base.Objects#hashCode.  Test enhanced to check that this is OK.

Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/TestPair.java

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java?rev=189&r1=188&r2=189&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java Thu Jan  5 10:26:44 2012
@@ -96,14 +96,7 @@
 
     /** {@inheritDoc} */
     public int hashCode() {
-        int result = 17;
-        if (first != null) {
-            result = 37 * result + first.hashCode();
-        }
-        if (second != null) {
-            result = 37 * result + second.hashCode();
-        }
-        return result;
+        return Objects.hashCode(first, second);
     }
 
     /** {@inheritDoc} */

Modified: java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/TestPair.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/TestPair.java?rev=189&r1=188&r2=189&view=diff
==============================================================================
--- java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/TestPair.java (original)
+++ java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/TestPair.java Thu Jan  5 10:26:44 2012
@@ -26,15 +26,10 @@
     private final static String STRING_1 = "StringOne";
 
     private final static String STRING_2 = "StringTwo";
-
-    private final static String STRING_3 = "StringThree";
     
     private final static Integer INTEGER_1 = new Integer(-6); 
 
     private final static Integer INTEGER_2 = new Integer(0); 
-
-    private final static Integer INTEGER_3 = new Integer(2); 
-
     
     @Test
     public void testPair() {
@@ -59,8 +54,10 @@
         Assert.assertEquals(pair1.getFirst(), INTEGER_2, "Should find " + INTEGER_2);
         Assert.assertEquals(pair1.getSecond(), STRING_2, "Should find " + STRING_2);
         
-        Assert.assertEquals(pair1, pair4, "Same contebts");
+        Assert.assertEquals(pair1, pair4, "Same contents");
+        Assert.assertEquals(pair1.hashCode(), pair4.hashCode(), "Same contents, same hashcode");
         Assert.assertEquals(pair2, pair3, "null pairs are equal");
+        Assert.assertEquals(pair2.hashCode(), pair3.hashCode(), "null pairs have equal hashcode");
         Assert.assertNotSame(pair1, pair3);
         
         pair3.setFirst(STRING_2);pair3.setSecond(INTEGER_2); 



More information about the commits mailing list