Changeset 343 in tmcsimulator for trunk/src/atmsdriver/model/Highways.java


Ignore:
Timestamp:
03/23/2019 05:40:52 PM (7 years ago)
Author:
jdalbey
Message:

Fix defect #117. Update HighwaysTest?.java for new highway model.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/model/Highways.java

    r306 r343  
    4343 * FEP Simulator. 
    4444 * 
    45  * Currently, there is no driving logic within the highways class. It is only 
    46  * done through an instance of the ConsoleDriver.java class. Eventually, it will 
    47  * receive incident data (from exchange.xml or better yet, directly from the 
    48  * TMCSimulator itself) and drive the highways using resident logic. 
    4945 * 
    5046 * @author John A. Torres 
     
    124120    } 
    125121 
     122    /** Search for a station with the given attributes  
     123     *  
     124     * @param routeNumber 
     125     * @param direction 
     126     * @param postmile 
     127     * @return the desired station, or null if not found. 
     128     */ 
     129    public Station findStation(Integer routeNumber, Station.DIRECTION direction, 
     130            Double postmile) 
     131    { 
     132        // Get the highway by route number 
     133        Highway highway = getHighwayByRouteNumber(routeNumber); 
     134        if (highway == null) 
     135        { 
     136            Logger.getLogger(Highways.class.getName()).log(Level.SEVERE,   
     137                    "Highway "+routeNumber+" not found in findStation()", ""); 
     138            return null; 
     139        } 
     140        //Search the stations on this highway for a match 
     141        for (Station station : highway.stations) 
     142        { 
     143            if (station.matches(direction, postmile)) 
     144            { 
     145                return station; 
     146            } 
     147        } 
     148        return null; 
     149    } 
    126150    /** 
    127151     * Applies specified color to the specified highway stretch. Route number 
     
    158182        // postmiles increase from s to n and w to e 
    159183        // if the direction is south or west 
    160         if (direction.equals(Station.DIRECTION.SOUTH) || direction.equals(Station.DIRECTION.WEST)) 
     184        if (direction.equals(Station.DIRECTION.NORTH) || direction.equals(Station.DIRECTION.EAST)) 
    161185        { 
    162186            // add range value to startPost to get 
     
    440464    /** 
    441465     * Returns the Highways model data in XML format. 
    442      *  
     466     * Probably obsolete, since we aren't using exchange.xml any longer. 
    443467     * @return highways data in XML format 
    444468     */ 
     
    507531        { 
    508532            // Consider each route direction 
    509             for (DIRECTION dir: DIRECTION.values()) 
     533            for (DIRECTION dir: hwy.availDirs) 
    510534            { 
    511535                String rowLabel = ""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' '; 
     
    514538                for (Station stat: hwy.stations) 
    515539                { 
     540                    if (stat.direction.equals(dir)) 
     541                    { 
    516542                    //lineout.append("" + dir.getLetter() + stat.postmile); 
    517543                    lineout.append(stat.getColor()); 
    518544                    //lineout.append("  "); 
     545                    } 
     546                    else  
     547                    { 
     548                        lineout.append("."); 
     549                    } 
    519550                } 
    520551                // See if there were stations for this direction 
Note: See TracChangeset for help on using the changeset viewer.