RovkirHexus

Grid

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