Add identity checks with various implementations of equals(Object).

This commit is contained in:
asofold 2018-02-11 14:21:14 +01:00
parent 4705f75fa0
commit 4a7efdc3a4
7 changed files with 23 additions and 2 deletions

View File

@ -96,7 +96,8 @@ public class HashMapLOW <K, V> {
// By specification, not intended to be useful here.
if (obj instanceof Entry<?, ?>) {
final Entry<?, ?> entry = (Entry<?, ?>) obj;
return (key == null ? entry.getKey() == null : key.equals(entry.getKey()))
return obj == this
|| (key == null ? entry.getKey() == null : key.equals(entry.getKey()))
&& (value == null ? entry.getValue() == null : value.equals(entry.getValue()));
}
else {

View File

@ -54,11 +54,16 @@ public class TestCoordMap {
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Pos){
Pos other = (Pos) obj;
return other.hash == hash && other.x == x && other.y == y && other.z == z;
}
else return false;
else {
return false;
}
}
@Override
public int hashCode() {

View File

@ -153,6 +153,9 @@ public class BlockChangeReference {
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof BlockChangeReference)) {
return false;
}

View File

@ -228,6 +228,9 @@ public class BlockChangeTracker {
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof BlockChangeEntry)) {
return false;
}

View File

@ -105,6 +105,9 @@ public class RegisteredPermission {
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Integer) {
return id.intValue() == ((Integer) obj).intValue();
}

View File

@ -170,6 +170,9 @@ public abstract class BlockCache {
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof IBlockCacheNode) {
final IBlockCacheNode other = (IBlockCacheNode) obj;
return id == other.getType()

View File

@ -463,6 +463,9 @@ public class BlockProperties {
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof BlockBreakKey) {
final BlockBreakKey other = (BlockBreakKey) obj;
// TODO: Some should be equals later.