Skip to content

Commit

Permalink
New coordinate classes which will be useful as keys for different kin…
Browse files Browse the repository at this point in the history
…ds of Maps (collections).
  • Loading branch information
Pavel Fedin committed Nov 25, 2016
1 parent e87a50e commit f932036
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/ru/wpstuio/amorphine/utils/Coordinates2d.java
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 src/main/java/ru/wpstuio/amorphine/utils/Coordinates3d.java
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();
}
}

0 comments on commit f932036

Please sign in to comment.