Skip to content

Commit

Permalink
Implemented equals() method which is important for coords being keys …
Browse files Browse the repository at this point in the history
…for Maps.
  • Loading branch information
Pavel Fedin committed Nov 25, 2016
1 parent 3b4527a commit 6c35e60
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/ru/wpstuio/amorphine/utils/Coordinates2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,25 @@ public int getZ() {
public String toString() {
return coordinates_as_string;
}

public int hashCode() {
return this.coordinates_as_string.hashCode();
}

public boolean equals(Object obj) {
if(obj == this)
return true;


if(obj == null)
return false;

if(!(getClass() == obj.getClass()))
return false;
else
{
Coordinates2d tmp = (Coordinates2d)obj;
return tmp.toString().equals(this.toString());
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/ru/wpstuio/amorphine/utils/Coordinates3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,21 @@ public String toString() {
public int hashCode() {
return this.coordinates_as_string.hashCode();
}

public boolean equals(Object obj) {
if(obj == this)
return true;


if(obj == null)
return false;

if(!(getClass() == obj.getClass()))
return false;
else
{
Coordinates3d tmp = (Coordinates3d)obj;
return tmp.toString().equals(this.toString());
}
}
}

0 comments on commit 6c35e60

Please sign in to comment.