Repository navigation
Expand file tree
/
Copy pathInterlocking.java
More file actions
55 lines (52 loc) · 2.46 KB
/
Copy pathInterlocking.java
File metadata and controls
55 lines (52 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public interface Interlocking {
/**
* Adds a train to the rail corridor.
*
* @param trainName A String that identifies a given train. Cannot be the
* same as any other train present.
* @param entryTrackSection The id number of the track section that the train
* is entering into.
* @param destinationTrackSection The id number of the track section that the
* train should exit from.
* @throws IllegalArgumentException if the train name is already in use, or there is no valid path
* from the entry to the destination
* @throws IllegalStateException if the entry track is already occupied
*/
public void addTrain(String trainName, int entryTrackSection, int
destinationTrackSection)
throws IllegalArgumentException, IllegalStateException;
/**
* The listed trains proceed to the next track section.
* Trains only move if they are able to do so, otherwise they remain in their
* current section.
* When a train reaches its destination track section, it exits the rail
* corridor next time it moves.
*
* @param trainNames The names of the trains to move.
* @return The number of trains that have moved.
* @throws IllegalArgumentException if the train name does not exist or is no longer in the rail
* corridor
*/
public int moveTrains(String[] trainNames)
throws IllegalArgumentException;
/**
* Returns the name of the Train currently occupying a given track section
*
* @param trackSection The id number of the section of track.
* @return The name of the train currently in that section, or null if the
* section is empty/unoccupied.
* @throws IllegalArgumentException if the track section does not exist
*/
public String getSection(int trackSection)
throws IllegalArgumentException;
/**
* Returns the track section that a given train is occupying
*
* @param trainName The name of the train.
* @return The id number of section of track the train is occupying, or -1 if
* the train is no longer in the rail corridor
* @throws IllegalArgumentException if the train name does not exist
*/
public int getTrain(String trainName)
throws IllegalArgumentException;
}