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