public class Rail extends Slot
Rail represents simple railway sections or railway crossings,
which is a
A Rail has an even number of identified neighboring Slots.| Constructor and Description |
|---|
Rail()
Creates a simple rail with two neighbors.
|
Rail(int cross)
Creates a railway crossing, which is a
Rail with twice as much neighbors than the number
of railways crossing at this point given by the parameter cross. |
| Modifier and Type | Method and Description |
|---|---|
static Rail[] |
createSection(int length)
Static method that creates and connects consecutive
Rails. |
Slot |
getNextSlot(Slot previousSlot)
Returns the
Slot a Vehicle standing on this Slot must move to after its
next step determined by previousSlot. |
int |
getNumberOfNeighbors()
Returns the number of
neighbors connected to this Rail. |
void |
setNeighbor(int which,
Slot neighbor)
Sets the one of the neighbors of this
Rail identified by which
to neighbor. |
acquire, addStation, arrive, checkCollision, depart, getStation, getVehicle, isAcquired, releasepublic Rail()
public Rail(int cross)
Rail with twice as much neighbors than the number
of railways crossing at this point given by the parameter cross. The neighbors
are all initially set to the single instance of Ground.cross - the number of rails crossing, which is half as much as the size of
neighbors of this will bepublic static Rail[] createSection(int length)
Rails. The number of
Rails created equals to the parameter length.length - the number of Rails to be createdRails createdpublic int getNumberOfNeighbors()
neighbors connected to this Rail.neighbors arraypublic Slot getNextSlot(Slot previousSlot)
Slot a Vehicle standing on this Slot must move to after its
next step determined by previousSlot.
The neighbor pairs, which are the ends of the railways in the railway crossing are positioned in the
neighbors array so that each pair's elements are exactly half the array's size away from
each other. Using this information the method calculates and returns the next Slot.getNextSlot in class SlotpreviousSlot - Slot that determines the direction of movementSlot to move topublic void setNeighbor(int which,
Slot neighbor)
Rail identified by which
to neighbor.which - the index of the neighbor to be setneighbor - the neighbor to be