-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New coordinate classes which will be useful as keys for different kin…
…ds of Maps (collections).
- Loading branch information
Pavel Fedin
committed
Nov 25, 2016
1 parent
e87a50e
commit f932036
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/ru/wpstuio/amorphine/utils/Coordinates2d.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ru.wpstuio.amorphine.utils; | ||
|
||
/** | ||
* The class has been created to use as a key for hash maps containing chunks, regions and so on. | ||
* All new inctanses of the class with simular params returns the same hash code | ||
*/ | ||
public class Coordinates2d { | ||
private final int x; | ||
private final int z; | ||
|
||
private final String coordinates_as_string; | ||
|
||
public Coordinates2d(int x, int z) { | ||
this.x = x; | ||
this.z = z; | ||
|
||
this.coordinates_as_string = "(" + x + ";" + z + ")"; | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getZ() { | ||
return z; | ||
} | ||
|
||
public String toString() { | ||
return coordinates_as_string; | ||
} | ||
public int hashCode() { | ||
return this.coordinates_as_string.hashCode(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/ru/wpstuio/amorphine/utils/Coordinates3d.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ru.wpstuio.amorphine.utils; | ||
|
||
/** | ||
* The class has been created to use as a key for hash maps containing chunks, regions and so on. | ||
* All new inctanses of the class with simular params returns the same hash code | ||
*/ | ||
public class Coordinates3d { | ||
private final int x; | ||
private final int y; | ||
private final int z; | ||
|
||
private final String coordinates_as_string; | ||
|
||
public Coordinates3d(int x, int y, int z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
|
||
this.coordinates_as_string = "(" + x + ";" + y + ";" + z + ")"; | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public int getZ() { | ||
return z; | ||
} | ||
|
||
public String toString() { | ||
return coordinates_as_string; | ||
} | ||
|
||
public int hashCode() { | ||
return this.coordinates_as_string.hashCode(); | ||
} | ||
} |