Class Warehouse

java.lang.Object
  |
  +--java.util.Observable
        |
        +--Warehouse

public class Warehouse
extends Observable

A warehouse storing parcels in orders.


Field Summary
protected  Crane crane
          Crane used to operate on this warehouse.
protected  Space[][] spaces
          Array of spaces in this warehouse.
 
Constructor Summary
Warehouse(int width, int height)
          Creates a warehouse that can fit the given number of parcels per side.
 
Method Summary
 boolean addOrder(Order anOrder)
          Places the given order in the warehouse and returns true, or returns false if it could not be placed.
 int getColumnCount()
          Returns the number of columns in this warehouse.
 Crane getCrane()
          Returns the crane used to operate on this warehouse.
 Parcel getParcel(int row, int col)
          Returns the parcel stored in this warehouse in the space at the given row and column indices.
 int getRowCount()
          Returns the number of rows in this warehouse.
 Space[][] getSpaces()
          Returns the array of spaces in this warehouse.
 void hit(Point p)
          "Hits" the space at the given location.
 boolean isEmpty(int row, int col)
          Returns whether or not the space at the given row and column indices is empty.
 boolean isFragmented(Order anOrder)
          Returns whether or not the given order is fragmented.
 boolean isFull()
          Returns true if there are no empty spaces in this warehouse, and false if at least one empty space exists.
 boolean removeOrder(Order anOrder)
          Removes the given order from the warehouse and returns true, or returns false if it could not be removed.
 void reset()
          Empties the warehouse and moves its crane to the default starting location.
 Parcel setParcel(int row, int col, Parcel p)
          Sets the parcel stored in this warehouse in the space at the given row and column indices to the given parcel.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

crane

protected Crane crane
Crane used to operate on this warehouse.


spaces

protected Space[][] spaces
Array of spaces in this warehouse.

Constructor Detail

Warehouse

public Warehouse(int width,
                 int height)
Creates a warehouse that can fit the given number of parcels per side. If either the given width or height is less than 1, it is set to a value of 1.

Parameters:
width - the width of the warehouse in parcels
height - the height of the warehouse in parcels
Method Detail

getRowCount

public int getRowCount()
Returns the number of rows in this warehouse.


getColumnCount

public int getColumnCount()
Returns the number of columns in this warehouse.


getSpaces

public Space[][] getSpaces()
Returns the array of spaces in this warehouse.


isEmpty

public boolean isEmpty(int row,
                       int col)
Returns whether or not the space at the given row and column indices is empty.

Parameters:
row - the row index of the space
col - the column index of the space
Throws:
ArrayIndexOutOfBoundsException - if the given row or column index is out of bounds

setParcel

public Parcel setParcel(int row,
                        int col,
                        Parcel p)
Sets the parcel stored in this warehouse in the space at the given row and column indices to the given parcel.

Parameters:
row - the row index of the space
col - the column index of the space
p - the parcel to be placed in the space
Returns:
the parcel previously stored in the space, or null if the space was empty
Throws:
ArrayIndexOutOfBoundsException - if the given row or column index is out of bounds

getParcel

public Parcel getParcel(int row,
                        int col)
Returns the parcel stored in this warehouse in the space at the given row and column indices.

Parameters:
row - the row index of the space
col - the column index of the space
Throws:
ArrayIndexOutOfBoundsException - if the given row or column index is out of bounds

hit

public void hit(Point p)
"Hits" the space at the given location.


getCrane

public Crane getCrane()
Returns the crane used to operate on this warehouse.


reset

public void reset()
Empties the warehouse and moves its crane to the default starting location.


addOrder

public boolean addOrder(Order anOrder)
Places the given order in the warehouse and returns true, or returns false if it could not be placed.

Parameters:
anOrder - order to place

removeOrder

public boolean removeOrder(Order anOrder)
Removes the given order from the warehouse and returns true, or returns false if it could not be removed.

Parameters:
anOrder - order to remove

isFragmented

public boolean isFragmented(Order anOrder)
Returns whether or not the given order is fragmented.


isFull

public boolean isFull()
Returns true if there are no empty spaces in this warehouse, and false if at least one empty space exists.