package tmcsim.highwaymodel;

import tmcsim.highwaymodel.Station.DIRECTION;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * Highway represents a freeway that has two directions of traffic. A highway is
 * identified by its highway number.  A highway contains lane detector stations,
 * called Stations, along its length.
 *
 * @author jdalbey
 */
final public class Highway implements Comparable<Highway>
{
    /** The identifying number for this highway, e.g., 101 */
    public final Integer routeNumber;
    /** The ordered list of stations (lane detector stations) on this highway */
    public final List<Station> stations;
    /** The directions for this highway, either N/S or E/W */
    public final Set<DIRECTION> availDirs = new TreeSet<DIRECTION>();
    
    /** Construct a highway 
     * 
     * @param highwayNum integer identifier for this highway
     * @param stations ordered list of stations on this highway
     */
    public Highway(Integer routeNumber, ArrayList<Station> stations)
    {
        this.routeNumber = routeNumber;
        this.stations = stations;
        // Get available directions for route
        if (stations != null)
        {
            for(Station stn : stations)
            {
                availDirs.add(stn.direction);
            }
        }
    }
    
    @Override
    public String toString()
    {
        return Integer.toString(this.routeNumber);
    }

    @Override
    public int compareTo(Highway other)
    {
        int otherRoute = ((Highway) other).routeNumber; 
        //ascending order
        return this.routeNumber - otherRoute;        
    }
}
