package model.world.graphs; import model.world.Position; import java.util.Objects; public class Vertex implements Comparable { private int x, y; /** * @param x Position x on the map * @param y Position y on the map */ public Vertex(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public Position getPos() { return new Position(x, y); } /** * Return -1 if this is more topLeft than vertex. 0 if equals and 1 otherwise * * @param vertex - the vertex to compare to * @return - 1 if this > vertex, 0 if this == vertex, -1 if this < vertex */ @Override public int compareTo(Vertex vertex) { return this.getPos().compareTo(vertex.getPos()); } /** * @param object can be any object * @return true if the object is a Vertex and this.compareTo(vertex) == 0 */ @Override public boolean equals(Object object) { if (object instanceof Vertex) return this.compareTo((Vertex) object) == 0; return super.equals(object); } /** * @return unique hash based on constructor parameters (x, y) */ @Override public int hashCode() { return Objects.hash(x, y); } }