]> source.dussan.org Git - jgit.git/commitdiff
Backout RevObject's object-identity based equals implementation 13/1313/1
authorMatthias Sohn <matthias.sohn@sap.com>
Sun, 15 Aug 2010 21:12:58 +0000 (23:12 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 15 Aug 2010 21:12:58 +0000 (23:12 +0200)
This restores the transitivity and symmetry properties of the equals
methods on the AnyObjectId type hierarchy as defined in [1].
Following [2] we declare these equals methods final to ensure that
semantics of equals are consistent across AnyObjectId's type hierarchy.

[1] http://download-llnw.oracle.com/javase/6/docs/api/java/lang/Object.html#equals(java.lang.Object)
[2] http://www.angelikalanger.com/Articles/JavaSolutions/SecretsOfEquals/Equals.html

Bug: 321502
Change-Id: Ibace21fa268c4aa15da6c65d42eb705ab1aa24b3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java

index d4f289a16bc17c2e0cfe12557e712349dc7167cf..2b24aa49adadf754ea3bd973ec1926c302e5f08b 100644 (file)
@@ -52,7 +52,7 @@ public class RevObjectTest extends RevWalkTestCase {
                assertSame(a, a.getId());
        }
 
-       public void testEqualsIsIdentity() throws Exception {
+       public void testEquals() throws Exception {
                final RevCommit a1 = commit();
                final RevCommit b1 = commit();
 
@@ -60,8 +60,8 @@ public class RevObjectTest extends RevWalkTestCase {
                assertTrue(a1.equals((Object) a1));
                assertFalse(a1.equals(b1));
 
-               assertFalse(a1.equals(a1.copy()));
-               assertFalse(a1.equals((Object) a1.copy()));
+               assertTrue(a1.equals(a1.copy()));
+               assertTrue(a1.equals((Object) a1.copy()));
                assertFalse(a1.equals(""));
 
                final RevWalk rw2 = new RevWalk(db);
@@ -70,8 +70,8 @@ public class RevObjectTest extends RevWalkTestCase {
                assertNotSame(a1, a2);
                assertNotSame(b1, b2);
 
-               assertFalse(a1.equals(a2));
-               assertFalse(b1.equals(b2));
+               assertTrue(a1.equals(a2));
+               assertTrue(b1.equals(b2));
 
                assertEquals(a1.hashCode(), a2.hashCode());
                assertEquals(b1.hashCode(), b2.hashCode());
index ecaa82b75a30871d96cdf3c5b655de39877e4481..aeb0812c4d7f2a010bb52f450e10ac64d43f2150 100644 (file)
@@ -230,11 +230,11 @@ public abstract class AnyObjectId implements Comparable {
         *            the other id to compare to. May be null.
         * @return true only if both ObjectIds have identical bits.
         */
-       public boolean equals(final AnyObjectId other) {
+       public final boolean equals(final AnyObjectId other) {
                return other != null ? equals(this, other) : false;
        }
 
-       public boolean equals(final Object o) {
+       public final boolean equals(final Object o) {
                if (o instanceof AnyObjectId)
                        return equals((AnyObjectId) o);
                else
index a19f4d83ea5a11f087922174ad158e91f4851708..85191224df062aecfebb8397b136ec11b32c8812 100644 (file)
@@ -96,16 +96,6 @@ public abstract class RevObject extends ObjectId {
                return this;
        }
 
-       @Override
-       public final boolean equals(final AnyObjectId o) {
-               return this == o;
-       }
-
-       @Override
-       public final boolean equals(final Object o) {
-               return this == o;
-       }
-
        /**
         * Test to see if the flag has been set on this object.
         *