package j2048;

/**
 * A data structure representing a point on the grid. This point may or may not
 * contain a tile. This class is immutable.
 * 
 * @author William Chargin
 * 
 */
public final class BoardLocation {

	/**
	 * The {@code x}-position of this location in the grid. The leftmost cells
	 * in the grid have {@code x}-position {@code 0}.
	 */
	private final int x;

	/**
	 * The {@code y}-position of this location in the grid. The topmost cells in
	 * the grid have {@code y}-position {@code 0}.
	 */
	private final int y;

	/**
	 * Creates a location with the given coordinates. The coordinates must be
	 * non-negative (greater than or equal to zero).
	 * 
	 * @param x
	 *            the {@code x}-position for this tile
	 * @param y
	 *            the {@code y}-position for this tile
	 * @throws IllegalArgumentException
	 *             if {@code x < 0} or {@code y < 0}
	 */
	public BoardLocation(int x, int y) throws IllegalArgumentException {
		if (x < 0) {
			throw new IllegalArgumentException("x is negative: " + x);
		} else if (y < 0) {
			throw new IllegalArgumentException("y is negative: " + y);
		}
		this.x = x;
		this.y = y;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BoardLocation other = (BoardLocation) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

	/**
	 * Gets the {@code x}-coordinate of this location in the grid.
	 * 
	 * @return the {@code x}-coordinate
	 */
	public int getX() {
		return x;
	}

	/**
	 * Gets the {@code y}-coordinate of this location in the grid.
	 * 
	 * @return the {@code y}-coordinate
	 */
	public int getY() {
		return y;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public String toString() {
		return String.format("(%s, %s)", x, y);
	}

}

Create a BoardLocation data structure