Hows this?

This commit is contained in:
boy0001 2014-11-07 22:15:19 +11:00
parent 12c476f3c2
commit c606b4d893
2 changed files with 40 additions and 12 deletions

View File

@ -288,12 +288,26 @@ public class Plot implements Cloneable {
*/
@Override
public int hashCode() {
final int
x = getId().x,
z = getId().y;
String
xL = (x + "").length() + "",
zL = (z + "").length() + "";
return Integer.parseInt(xL + x + zL + z);
int x = id.x;
int y = id.y;
if (x >= 0) {
if (y >= 0) {
return x*x + 3*x + 2*x*y + y + y*y;
}
else {
int y1 = -y;
return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1;
}
}
else {
int x1 = -x;
if (y >= 0) {
return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y);
}
else {
int y1 = -y;
return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1);
}
}
}
}

View File

@ -45,10 +45,24 @@ public class PlotId {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.y;
return result;
if (x >= 0) {
if (y >= 0) {
return x*x + 3*x + 2*x*y + y + y*y;
}
else {
int y1 = -y;
return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1;
}
}
else {
int x1 = -x;
if (y >= 0) {
return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y);
}
else {
int y1 = -y;
return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1);
}
}
}
}