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

noreply at shibboleth.net noreply at shibboleth.net
Thu Jan 5 10:54:24 GMT 2012


Author: rdw
Date: Thu Jan  5 10:54:24 2012
New Revision: 190

URL: http://svn.shibboleth.net/view/utilities?rev=190&view=rev
Log:
Add toString, equals and hashCode.  Also tests for the last two methods.

Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSetTest.java

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java?rev=190&r1=189&r2=190&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java Thu Jan  5 10:54:24 2012
@@ -152,6 +152,29 @@
     private void removeFromIndex(final T o) {
         index.remove(getIndexClass(o));
     }
+    
+    /** {@inheritDoc} */
+    public String toString() {
+        return set.toString();
+    }
+    
+    /** {@inheritDoc} */
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj == null || this.getClass() != obj.getClass()) {
+            return false;
+        }
+
+        return set.equals(((ClassIndexedSet<?>) obj).set);
+    }
+    
+    /** {@inheritDoc} */
+    public int hashCode() {
+        return set.hashCode();
+    }
 
     /**
      * Iterator for set implementation {@link ClassIndexedSet}.

Modified: java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSetTest.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSetTest.java?rev=190&r1=189&r2=190&view=diff
==============================================================================
--- java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSetTest.java (original)
+++ java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSetTest.java Thu Jan  5 10:54:24 2012
@@ -244,6 +244,27 @@
             // do nothing, should fail
         }
     }
+    
+    @Test
+    public void testEqualsHash() {
+        memberSet = new ClassIndexedSet<Member>();
+        ClassIndexedSet<Member> other = new ClassIndexedSet<Member>();
+        Assert.assertEquals(memberSet, other, "Empty sets are equal");
+        Assert.assertEquals(memberSet.hashCode(), other.hashCode(), "Empty sets have equal hashes");
+
+        A memberA = new A("owner");
+        B memberB = new B("algorithm");
+        memberSet.add(memberB);
+        memberSet.add(memberA);
+        Assert.assertNotSame(memberSet, other, "Different sets should differ");
+        Assert.assertNotSame(memberSet.hashCode(), other.hashCode(), "Different sets should have different hashes ");
+        
+        other.add(memberA);
+        other.add(memberB);
+        Assert.assertEquals(memberSet, other, "Equal sets are equal");
+        Assert.assertEquals(memberSet.hashCode(), other.hashCode(), "Equal sets have equal hashes");
+
+    }
 
     /* Classes used for testing. */
 



More information about the commits mailing list