Class Crane

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

public class Crane
extends Observable

A crane used in a warehouse to store and remove parcels from a grid of possible locations using row and column coordinates. A crane can hold an arbitrary number of parcels, whether performing an add or remove operation.


Field Summary
protected static int delay
          Delay time for all cranes.
protected  Point destination
          Current move destination in warehouse.
static String DESTINATION
          Bound property name for the destination property.
protected  ACraneStrategy driver
          Device driver governing the operation of this crane.
protected  SwingPropertyChangeSupport listeners
          Helper object for property change support.
protected  Point location
          Current location in warehouse.
static String LOCATION
          Bound property name for the location property.
protected  Statistics stats
          Current operating statistics for this crane.
protected  String status
          Status description for this crane.
static String STATUS
          Bound property name for the status property.
protected  boolean stopNow
          Whether or not this crane should stop operation.
static String STRATEGY
          Bound property name for the strategy property.
protected  Warehouse warehouse
          Warehouse on which this crane operates.
 
Constructor Summary
Crane(Warehouse w)
          Constructs a crane operating on the given warehouse.
 
Method Summary
 Parcel add(Parcel p)
          Sets the parcel at the current crane location to the given parcel.
 boolean addOrder(Order anOrder)
          Places the given order in the warehouse and returns true, or returns false if it could not be placed.
 void addPropertyChangeListener(PropertyChangeListener l)
          Adds the given property change listener to the list of property change listeners for this crane.
 boolean contains(Parcel p)
          Returns true if the current crane location contains the given parcel, or false if it does not contain the given parcel.
protected  void delay()
          Delays operation of this crane.
static int distance(Point p, Point q)
          Returns the number of steps required for a crane to move from the first given point to the second given point.
 int getColumn()
          Returns the column index of the location of this crane.
 Point getDestination()
          Returns the destination of this crane, or null if it has no current destination.
 Point getLocation()
          Returns the location of this crane.
protected  Parcel getParcel()
          Returns the parcel at the current crane location.
 int getRow()
          Returns the row index of the location of this crane.
 Statistics getStatistics()
          Returns the current operating statistics for this crane.
 String getStatus()
          Returns the status description for this crane.
 ACraneStrategy getStrategy()
          Returns the strategy for this crane.
 void installStrategy(ACraneStrategy d)
          Installs the given device driver into this crane.
 boolean isEmpty()
          Returns whether or not the current crane location is an empty warehouse location.
protected  void moved()
          Called every time this crane moves.
protected  void moveDown()
          Moves this crane one row to the south.
protected  void moveLeft()
          Moves this crane one column to the left.
protected  void moveRight()
          Moves this crane one column to the right.
 void moveTo(int row, int col)
          Moves this crane to the given warehouse location.
protected  void moveUp()
          Moves this crane one row to the north.
 void quit()
          Stops the operation of this crane.
 Parcel remove()
          Removes and returns the parcel at the current crane location.
 boolean removeOrder(Order anOrder)
          Removes the given order from the warehouse and returns true, or returns false if it could not be removed.
 void removePropertyChangeListener(PropertyChangeListener l)
          Adds the given property change listener to the list of property change listeners for this crane.
 void reset()
          Resets this crane.
static void setDelay(int delayTime)
          Sets the delay time for all warehouse cranes to the given number of milliseconds.
protected  void setDestination(Point p)
          Sets the destination for this crane to the given destination.
protected  Parcel setParcel(Parcel p)
          Sets the parcel at the current crane location to the given parcel.
protected  void setStatus(String description)
          Sets the status description for this crane to the given description.
 
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

STRATEGY

public static final String STRATEGY
Bound property name for the strategy property.

See Also:
Constant Field Values

LOCATION

public static final String LOCATION
Bound property name for the location property.

See Also:
Constant Field Values

DESTINATION

public static final String DESTINATION
Bound property name for the destination property.

See Also:
Constant Field Values

STATUS

public static final String STATUS
Bound property name for the status property.

See Also:
Constant Field Values

delay

protected static int delay
Delay time for all cranes.


warehouse

protected Warehouse warehouse
Warehouse on which this crane operates.


driver

protected ACraneStrategy driver
Device driver governing the operation of this crane.


stats

protected Statistics stats
Current operating statistics for this crane.


status

protected String status
Status description for this crane.


location

protected Point location
Current location in warehouse.


destination

protected Point destination
Current move destination in warehouse.


stopNow

protected boolean stopNow
Whether or not this crane should stop operation.


listeners

protected SwingPropertyChangeSupport listeners
Helper object for property change support.

Constructor Detail

Crane

public Crane(Warehouse w)
Constructs a crane operating on the given warehouse.

Parameters:
w - the warehouse on which this crane is to operate
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Adds the given property change listener to the list of property change listeners for this crane.

Parameters:
l - the listener to be added

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Adds the given property change listener to the list of property change listeners for this crane.

Parameters:
l - the listener to be added

reset

public void reset()
Resets this crane.


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

installStrategy

public void installStrategy(ACraneStrategy d)
Installs the given device driver into this crane.

Parameters:
d - the device driver for this crane

getStrategy

public ACraneStrategy getStrategy()
Returns the strategy for this crane.


quit

public void quit()
Stops the operation of this crane.


getStatistics

public Statistics getStatistics()
Returns the current operating statistics for this crane.


getStatus

public String getStatus()
Returns the status description for this crane.


getLocation

public Point getLocation()
Returns the location of this crane.


getRow

public int getRow()
Returns the row index of the location of this crane.


getColumn

public int getColumn()
Returns the column index of the location of this crane.


getDestination

public Point getDestination()
Returns the destination of this crane, or null if it has no current destination.


moveTo

public void moveTo(int row,
                   int col)
Moves this crane to the given warehouse location.

Parameters:
row - the row number of the location
col - the column number of the location

isEmpty

public boolean isEmpty()
Returns whether or not the current crane location is an empty warehouse location.


contains

public boolean contains(Parcel p)
Returns true if the current crane location contains the given parcel, or false if it does not contain the given parcel.

Parameters:
p - the parcel for the query

add

public Parcel add(Parcel p)
Sets the parcel at the current crane location to the given parcel.

Parameters:
p - the parcel to place in the space

remove

public Parcel remove()
Removes and returns the parcel at the current crane location.


setStatus

protected void setStatus(String description)
Sets the status description for this crane to the given description.

Parameters:
description - a description of the status of this crane

getParcel

protected Parcel getParcel()
Returns the parcel at the current crane location.


setParcel

protected Parcel setParcel(Parcel p)
Sets the parcel at the current crane location to the given parcel.

Parameters:
p - the parcel to place at the current location
Returns:
the parcel previously stored at the current location or null if the space is empty

setDestination

protected void setDestination(Point p)
Sets the destination for this crane to the given destination.

Parameters:
p - the destination space for this crane

moved

protected void moved()
Called every time this crane moves.


moveLeft

protected void moveLeft()
Moves this crane one column to the left.


moveRight

protected void moveRight()
Moves this crane one column to the right.


moveUp

protected void moveUp()
Moves this crane one row to the north.


moveDown

protected void moveDown()
Moves this crane one row to the south.


delay

protected void delay()
Delays operation of this crane.


setDelay

public static void setDelay(int delayTime)
Sets the delay time for all warehouse cranes to the given number of milliseconds.

Parameters:
delayTime - the delay time in milliseconds

distance

public static int distance(Point p,
                           Point q)
Returns the number of steps required for a crane to move from the first given point to the second given point.

Parameters:
p - the first point
q - the second point