Implement equals and hashCode for BlockPositionGet.

This commit is contained in:
asofold 2016-06-11 19:09:25 +02:00
parent 087d800de4
commit bd68362197

View File

@ -1,7 +1,11 @@
package fr.neatmonster.nocheatplus.components.location;
import fr.neatmonster.nocheatplus.utilities.ds.map.CoordHash;
/**
* Simple immutable block position.
* Simple immutable block position. Both hashCode and equals are implemented,
* with equals accepting any IGetBlockPosition instance for comparison of block
* coordinates.
*
* @author asofold
*
@ -33,6 +37,21 @@ public class BlockPositionGet implements IGetBlockPosition {
return z;
}
// TODO: equals vs. IGetBlockPosition, Coord(Hash)Map compatible hashCode.
@Override
public int hashCode() {
return CoordHash.hashCode3DPrimes(x, y, z);
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof IGetBlockPosition) {
final IGetBlockPosition other = (IGetBlockPosition) obj;
return x == other.getBlockX() && y == other.getBlockY() && z == other.getBlockZ();
}
return false;
}
}