-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.java
More file actions
128 lines (116 loc) · 4.69 KB
/
Copy pathGrid.java
File metadata and controls
128 lines (116 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* AP(r) Computer Science GridWorld Case Study:
* Copyright(c) 2002-2006 College Entrance Examination Board
* (http://www.collegeboard.com).
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* @author Alyce Brady
* @author APCS Development Committee
* @author Cay Horstmann
*/
import java.util.ArrayList;
/**
* <code>Grid</code> provides an interface for a two-dimensional, grid-like
* environment containing arbitrary objects. <br />
* This interface is testable on the AP CS A and AB exams.
*/
public interface Grid<E>
{
/**
* Returns the number of rows in this grid.
* @return the number of rows, or -1 if this grid is unbounded
*/
int getNumRows();
/**
* Returns the number of columns in this grid.
* @return the number of columns, or -1 if this grid is unbounded
*/
int getNumCols();
/**
* Checks whether a location is valid in this grid. <br />
* Precondition: <code>loc</code> is not <code>null</code>
* @param loc the location to check
* @return <code>true</code> if <code>loc</code> is valid in this grid,
* <code>false</code> otherwise
*/
boolean isValid(Location loc);
/**
* Puts an object at a given location in this grid. <br />
* Precondition: (1) <code>loc</code> is valid in this grid (2)
* <code>obj</code> is not <code>null</code>
* @param loc the location at which to put the object
* @param obj the new object to be added
* @return the object previously at <code>loc</code> (or <code>null</code>
* if the location was previously unoccupied)
*/
E put(Location loc, E obj);
/**
* Removes the object at a given location from this grid. <br />
* Precondition: <code>loc</code> is valid in this grid
* @param loc the location of the object that is to be removed
* @return the object that was removed (or <code>null<code> if the location
* is unoccupied)
*/
E remove(Location loc);
/**
* Returns the object at a given location in this grid. <br />
* Precondition: <code>loc</code> is valid in this grid
* @param loc a location in this grid
* @return the object at location <code>loc</code> (or <code>null<code>
* if the location is unoccupied)
*/
E get(Location loc);
/**
* Gets the locations in this grid that contain objects.
* @return an array list of all occupied locations in this grid
*/
ArrayList<Location> getOccupiedLocations();
/**
* Gets the valid locations adjacent to a given location in all eight
* compass directions (north, northeast, east, southeast, south, southwest,
* west, and northwest). <br />
* Precondition: <code>loc</code> is valid in this grid
* @param loc a location in this grid
* @return an array list of the valid locations adjacent to <code>loc</code>
* in this grid
*/
ArrayList<Location> getValidAdjacentLocations(Location loc);
/**
* Gets the valid empty locations adjacent to a given location in all eight
* compass directions (north, northeast, east, southeast, south, southwest,
* west, and northwest). <br />
* Precondition: <code>loc</code> is valid in this grid
* @param loc a location in this grid
* @return an array list of the valid empty locations adjacent to
* <code>loc</code> in this grid
*/
ArrayList<Location> getEmptyAdjacentLocations(Location loc);
/**
* Gets the valid occupied locations adjacent to a given location in all
* eight compass directions (north, northeast, east, southeast, south,
* southwest, west, and northwest). <br />
* Precondition: <code>loc</code> is valid in this grid
* @param loc a location in this grid
* @return an array list of the valid occupied locations adjacent to
* <code>loc</code> in this grid
*/
ArrayList<Location> getOccupiedAdjacentLocations(Location loc);
/**
* Gets the neighboring occupants in all eight compass directions (north,
* northeast, east, southeast, south, southwest, west, and northwest).
* <br />
* Precondition: <code>loc</code> is valid in this grid
* @param loc a location in this grid
* @return returns an array list of the objects in the occupied locations
* adjacent to <code>loc</code> in this grid
*/
ArrayList<E> getNeighbors(Location loc);
}