TSim
Class TSimInterface
java.lang.Object
|
+--TSim.TSimInterface
- public class TSimInterface
- extends java.lang.Object
- implements java.lang.Runnable
The TSimInterface is the intended interface between TSim and the
laboration. It handles the extraction of information from TSim and
provides methods for manipulating trains, sensors and switches.
Method Summary |
SensorEvent |
getSensor(int trainId)
Wait until the specified train passes a sensor. |
protected void |
reportTrainEvent(TrainEvent e)
Helper method that reports an error event on standard error. |
void |
run()
|
void |
setSpeed(int trainId,
int speed)
Method that issues a command to a secific train to set its speed
to the given value. |
void |
setSwitch(int xPos,
int yPos,
int switchPos)
Set the position of the specified switch. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
SWITCH_LEFT
public static final int SWITCH_LEFT
SWITCH_RIGHT
public static final int SWITCH_RIGHT
commandFIFO
protected SynchronizedFIFO commandFIFO
trainVec
protected SynchronizedTrainEventVector trainVec
sensorVec
protected SynchronizedSensorVector sensorVec
sTSim
protected TSimStream sTSim
TSimInterface
public TSimInterface()
- Create a new TSimInterface
run
public void run()
- Specified by:
- run in interface java.lang.Runnable
reportTrainEvent
protected void reportTrainEvent(TrainEvent e)
- Helper method that reports an error event on standard error.
- Parameters:
e
- the error event.
setSpeed
public void setSpeed(int trainId,
int speed)
throws CommandException
- Method that issues a command to a secific train to set its speed
to the given value.
- Parameters:
trainId
- the id of the train to be affected by the command.speed
- the new speed of the train.- Throws:
- CommandException - if the supplied id was false (NO_SUCH_TRAIN),
if the speed was illegal (ILLEGAL_SPEED)
or if the train had crashed.
setSwitch
public void setSwitch(int xPos,
int yPos,
int switchPos)
throws CommandException
- Set the position of the specified switch. Valid positions are
SWITCH_LEFT and SWITCH_RIGHT.
- Parameters:
xPos
- the x coordinate of the switch.yPos
- the y coordinate of the switch.switchPos
- the new position of the switch.
getSensor
public SensorEvent getSensor(int trainId)
throws CommandException
- Wait until the specified train passes a sensor.
- Parameters:
trainId
- the id of the train to wait for.- Returns:
- a SensorEvent representing the information about the event