Class Bridges

java.lang.Object
   |
   +----Bridges

public class Bridges
extends Object
The class representing a river and a set of bridges crossing it. An instance not only provides methods for crossing bridges, it also generates Person objects to exercise the simulation.

See Also:
Person, Drowning

Variable Index

 o GOEAST
Cross bridge from West to East
 o GOWEST
Cross bridge from East to West

Constructor Index

 o Bridges(int, int)
Create an instance with a given number of bridges and a given capacity per bridge.

Method Index

 o bridgeCapacity()
The capcity of each bridge.
 o bridgeCount()
The number of bridges.
 o cross(int, int)
Cross a bridge (when we come to it).
 o runSimulation(boolean, int)
Run a simulation with an optional ThreadScheduler to simulate preemptive scheduling.

Person objects are created at random times on random sides of the river and started up inside threads.

 o runSimulation(int)
Run a simulation without preemption.
 o toString()
Returns a string representation of the bridges, as a sequence of integers, one for each bridge.
 o verbose(int)
Control the verbosity of diagnostic information.

Variables

 o GOEAST
 public static final int GOEAST
Cross bridge from West to East

 o GOWEST
 public static final int GOWEST
Cross bridge from East to West

Constructors

 o Bridges
 public Bridges(int bridgeCount,
                int capacity)
Create an instance with a given number of bridges and a given capacity per bridge. Both bridgeCount and capacity must be positive integers.

Parameters:
bridgeCount - the number of bridges.
capacity - the maximum number of persons a bridge can carry at one time.

Methods

 o bridgeCount
 public int bridgeCount()
The number of bridges.

Returns:
the number of bridges.
 o bridgeCapacity
 public int bridgeCapacity()
The capcity of each bridge.

Returns:
the maximum number of people who can use one bridge at at time.
 o verbose
 public int verbose(int verbosity)
Control the verbosity of diagnostic information.

Parameters:
verbosity - the desired level of verbosity. Higher numbers produce more output. Level 0 turns off all output. Level 1 (the default) prints summary information at the end.
Returns:
the previous level of verbosity.
 o cross
 public void cross(int bridge,
                   int direction) throws Drowning, IllegalArgumentException
Cross a bridge (when we come to it).

Parameters:
bridge - the bridge number to cross 0..bridgeCount()-1
direction - direction to cross the bridge (GOEAST or GOWEST).
Throws: Drowning
if the bridge exceeds its capacity or if it currently has someone going the other way.
Throws: IllegalArgumentException
if bridge is out of range or direction is not valid.
See Also:
GOWEST, GOEAST
 o runSimulation
 public void runSimulation(boolean preempt,
                           int personCount)
Run a simulation with an optional ThreadScheduler to simulate preemptive scheduling.

Person objects are created at random times on random sides of the river and started up inside threads. When all the threads have completed, this method returns.

Parameters:
preempt - if true use a ThreadScheduler to periodically switch between active threads.
personCount - the number of Person objects to create.
See Also:
Person, ThreadScheduler
 o runSimulation
 public void runSimulation(int personCount)
Run a simulation without preemption. The same as runSimulation(false, personCount).

Parameters:
personCount - the number of Person objects to create.
See Also:
Person, runSimulation
 o toString
 public String toString()
Returns a string representation of the bridges, as a sequence of integers, one for each bridge. Positive numbers indicate a number of eastbound people and negative number indicate westbound people.

Returns:
a string representation of this Bridges object.
Overrides:
toString in class Object