Backout RevObject's object-identity based equals implementation
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>
This commit is contained in:
parent
8d761febc3
commit
2d3a806271
|
@ -52,7 +52,7 @@ public void testId() throws Exception {
|
||||||
assertSame(a, a.getId());
|
assertSame(a, a.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEqualsIsIdentity() throws Exception {
|
public void testEquals() throws Exception {
|
||||||
final RevCommit a1 = commit();
|
final RevCommit a1 = commit();
|
||||||
final RevCommit b1 = commit();
|
final RevCommit b1 = commit();
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ public void testEqualsIsIdentity() throws Exception {
|
||||||
assertTrue(a1.equals((Object) a1));
|
assertTrue(a1.equals((Object) a1));
|
||||||
assertFalse(a1.equals(b1));
|
assertFalse(a1.equals(b1));
|
||||||
|
|
||||||
assertFalse(a1.equals(a1.copy()));
|
assertTrue(a1.equals(a1.copy()));
|
||||||
assertFalse(a1.equals((Object) a1.copy()));
|
assertTrue(a1.equals((Object) a1.copy()));
|
||||||
assertFalse(a1.equals(""));
|
assertFalse(a1.equals(""));
|
||||||
|
|
||||||
final RevWalk rw2 = new RevWalk(db);
|
final RevWalk rw2 = new RevWalk(db);
|
||||||
|
@ -70,8 +70,8 @@ public void testEqualsIsIdentity() throws Exception {
|
||||||
assertNotSame(a1, a2);
|
assertNotSame(a1, a2);
|
||||||
assertNotSame(b1, b2);
|
assertNotSame(b1, b2);
|
||||||
|
|
||||||
assertFalse(a1.equals(a2));
|
assertTrue(a1.equals(a2));
|
||||||
assertFalse(b1.equals(b2));
|
assertTrue(b1.equals(b2));
|
||||||
|
|
||||||
assertEquals(a1.hashCode(), a2.hashCode());
|
assertEquals(a1.hashCode(), a2.hashCode());
|
||||||
assertEquals(b1.hashCode(), b2.hashCode());
|
assertEquals(b1.hashCode(), b2.hashCode());
|
||||||
|
|
|
@ -230,11 +230,11 @@ public int hashCode() {
|
||||||
* the other id to compare to. May be null.
|
* the other id to compare to. May be null.
|
||||||
* @return true only if both ObjectIds have identical bits.
|
* @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;
|
return other != null ? equals(this, other) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(final Object o) {
|
public final boolean equals(final Object o) {
|
||||||
if (o instanceof AnyObjectId)
|
if (o instanceof AnyObjectId)
|
||||||
return equals((AnyObjectId) o);
|
return equals((AnyObjectId) o);
|
||||||
else
|
else
|
||||||
|
|
|
@ -96,16 +96,6 @@ public final ObjectId getId() {
|
||||||
return this;
|
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.
|
* Test to see if the flag has been set on this object.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue