I have a class having two methods: getY() and getX() (it's a sort of map).
Y's and X's domain is [-1000.0, + 1000.0], and they're doubles.
I have written a hashCode() method:
@Override
public int hashCode()
{
int hash=(int) (getX()/EPSILON);
hash+= (int) ( (1000.0/EPSILON)*getY() );
return hash;
}
Where EPSILON is the maximum error tolerated.
But the problem is that values are too high and I get an overflow if X=1000.0 and Y=1000.0 .
How to write a hashCode() method that handles the overflow and is still able to return two hash codes for two different objects in every case?