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 Slot
s.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
Rail s. |
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, release
public 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)
Rail
s. The number of
Rail
s created equals to the parameter length
.length
- the number of Rail
s to be createdRail
s 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 Slot
previousSlot
- 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