| 1 | package atmsdriver.model; |
|---|
| 2 | |
|---|
| 3 | import atmsdriver.model.Station.DIRECTION; |
|---|
| 4 | import java.util.ArrayList; |
|---|
| 5 | import java.util.List; |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * Highway represents a freeway that has two directions of traffic. A highway is |
|---|
| 9 | * identified by its highway number. A highway contains lane detector stations, |
|---|
| 10 | * called Stations, along its length. |
|---|
| 11 | * |
|---|
| 12 | * @author jdalbey |
|---|
| 13 | */ |
|---|
| 14 | final public class Highway |
|---|
| 15 | { |
|---|
| 16 | /** The identifying number for this highway, e.g., 101 */ |
|---|
| 17 | public final Integer routeNumber; |
|---|
| 18 | /** The ordered list of stations (lane detector stations) on this highway */ |
|---|
| 19 | public final List<Station> stations; |
|---|
| 20 | |
|---|
| 21 | /** Construct a highway |
|---|
| 22 | * |
|---|
| 23 | * @param highwayNum integer identifier for this highway |
|---|
| 24 | * @param stations ordered list of stations on this highway |
|---|
| 25 | */ |
|---|
| 26 | public Highway(Integer routeNumber, ArrayList<Station> stations) |
|---|
| 27 | { |
|---|
| 28 | this.routeNumber = routeNumber; |
|---|
| 29 | this.stations = stations; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * |
|---|
| 34 | */ |
|---|
| 35 | public List<DIRECTION> getDirections() |
|---|
| 36 | { |
|---|
| 37 | // Get available directions for route |
|---|
| 38 | ArrayList<DIRECTION> availDirs = new ArrayList<>(); |
|---|
| 39 | for(Station stn : stations) |
|---|
| 40 | { |
|---|
| 41 | if(!availDirs.contains(stn.direction)) |
|---|
| 42 | { |
|---|
| 43 | availDirs.add(stn.direction); |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | return availDirs; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | @Override |
|---|
| 50 | public String toString() |
|---|
| 51 | { |
|---|
| 52 | return Integer.toString(this.routeNumber); |
|---|
| 53 | } |
|---|
| 54 | } |
|---|