@@ -0,0 +1,2026 @@
+package j2048;%0A%0A/**%0A * A data structure representing a point on the grid. This point may or may not%0A * contain a tile. This class is immutable.%0A * %0A * @author William Chargin%0A * %0A */%0Apublic final class BoardLocation %7B%0A%0A%09/**%0A%09 * The %7B@code x%7D-position of this location in the grid. The leftmost cells%0A%09 * in the grid have %7B@code x%7D-position %7B@code 0%7D.%0A%09 */%0A%09private final int x;%0A%0A%09/**%0A%09 * The %7B@code y%7D-position of this location in the grid. The topmost cells in%0A%09 * the grid have %7B@code y%7D-position %7B@code 0%7D.%0A%09 */%0A%09private final int y;%0A%0A%09/**%0A%09 * Creates a location with the given coordinates. The coordinates must be%0A%09 * non-negative (greater than or equal to zero).%0A%09 * %0A%09 * @param x%0A%09 *            the %7B@code x%7D-position for this tile%0A%09 * @param y%0A%09 *            the %7B@code y%7D-position for this tile%0A%09 * @throws IllegalArgumentException%0A%09 *             if %7B@code x %3C 0%7D or %7B@code y %3C 0%7D%0A%09 */%0A%09public BoardLocation(int x, int y) throws IllegalArgumentException %7B%0A%09%09if (x %3C 0) %7B%0A%09%09%09throw new IllegalArgumentException(%22x is negative: %22 + x);%0A%09%09%7D else if (y %3C 0) %7B%0A%09%09%09throw new IllegalArgumentException(%22y is negative: %22 + y);%0A%09%09%7D%0A%09%09this.x = x;%0A%09%09this.y = y;%0A%09%7D%0A%0A%09@Override%0A%09public boolean equals(Object obj) %7B%0A%09%09if (this == obj)%0A%09%09%09return true;%0A%09%09if (obj == null)%0A%09%09%09return false;%0A%09%09if (getClass() != obj.getClass())%0A%09%09%09return false;%0A%09%09BoardLocation other = (BoardLocation) obj;%0A%09%09if (x != other.x)%0A%09%09%09return false;%0A%09%09if (y != other.y)%0A%09%09%09return false;%0A%09%09return true;%0A%09%7D%0A%0A%09/**%0A%09 * Gets the %7B@code x%7D-coordinate of this location in the grid.%0A%09 * %0A%09 * @return the %7B@code x%7D-coordinate%0A%09 */%0A%09public int getX() %7B%0A%09%09return x;%0A%09%7D%0A%0A%09/**%0A%09 * Gets the %7B@code y%7D-coordinate of this location in the grid.%0A%09 * %0A%09 * @return the %7B@code y%7D-coordinate%0A%09 */%0A%09public int getY() %7B%0A%09%09return y;%0A%09%7D%0A%0A%09@Override%0A%09public int hashCode() %7B%0A%09%09final int prime = 31;%0A%09%09int result = 1;%0A%09%09result = prime * result + x;%0A%09%09result = prime * result + y;%0A%09%09return result;%0A%09%7D%0A%0A%09@Override%0A%09public String toString() %7B%0A%09%09return String.format(%22(%25s, %25s)%22, x, y);%0A%09%7D%0A%0A%7D%0A

Create a BoardLocation data structure