Changeset 191 in tmcsimulator


Ignore:
Timestamp:
10/30/2017 01:35:05 PM (9 years ago)
Author:
jdalbey
Message:

Highways.java: Added toString() method. Station.java: Added getColorByDirection method. Added testToString to HighwaysTest?.

Location:
trunk
Files:
3 edited

Legend:

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

    r190 r191  
    198198        { 
    199199            Scanner sc = new Scanner(new File(highwaysMapFileName)); 
     200            // first line of file contains number of FEP Lines 
    200201            String firstLine = sc.nextLine(); 
    201  
    202202            Scanner linesc = new Scanner(firstLine); 
    203203            int numLines = linesc.nextInt(); 
    204204            linesc.close(); 
    205  
     205            // FOR each FEP Line 
    206206            for (int i = 0; i < numLines; i++) 
    207207            { 
     
    227227        String line = sc.nextLine(); 
    228228        Scanner scline = new Scanner(line); 
    229  
     229        // Get the attribute of this FEP Line 
    230230        int lineNum = scline.nextInt(); 
    231231        int count = scline.nextInt(); 
    232232        int numStations = scline.nextInt(); 
    233233        ArrayList<Station> stations = new ArrayList<>(); 
     234        // Read all the stations for thie FEP Line 
    234235        for (int i = 0; i < numStations; i++) 
    235236        { 
     
    473474    } 
    474475 
     476    /** Return a string representation of the Highways */ 
     477    public String toString() 
     478    { 
     479        StringBuilder result = new StringBuilder(); 
     480        for (Highway hwy: highways) 
     481        { 
     482            result.append(""+String.format("%3s ",hwy.routeNumber)); 
     483            for (Station stat: hwy.stations) 
     484            { 
     485                result.append(stat.getColorByDirection(stat.direction)); 
     486            } 
     487            result.append("\n"); 
     488        } 
     489        return result.toString(); 
     490    } 
    475491    /** 
    476492     * XML tags used in writeToXML() 
  • trunk/src/atmsdriver/model/Station.java

    r190 r191  
    195195     
    196196    /** 
     197     * Return the color for the lanes in a given direction. 
     198     * @param direction 
     199     * @return character representing color of lanes in given direction 
     200     * '@' = red,  '+' = yellow, '-' = green 
     201     */ 
     202    public char getColorByDirection(DIRECTION direction) 
     203    { 
     204        /* For now just use the color of the first lane.  
     205         * TODO: Average the color in all the lanes for the given direction */ 
     206 
     207        String laneDir = "OS"; 
     208        if(direction.equals(this.direction)) 
     209        { 
     210            laneDir = "ML"; 
     211        } 
     212        // Examine all the lanes in a given direction 
     213        for(LoopDetector loop : loops) 
     214        { 
     215            if(loop.loopLocation.startsWith(laneDir)) 
     216            { 
     217                // Return color according to loop volume 
     218                if (loop.vol == 1) return '@'; 
     219                if (loop.vol == 3) return '+'; 
     220            } 
     221        } 
     222        // Default case 
     223        return '-'; 
     224                 
     225    } 
     226     
     227    /** 
    197228     * Output for updateByDirection. Logs the update to the console. 
    198229     *  
  • trunk/test/atmsdriver/model/HighwaysTest.java

    r185 r191  
    4343 
    4444    /** 
    45      * Test of toXML method, of class Network. 
     45     * Test of toString method 
     46     */ 
     47    public void testToString() { 
     48        System.out.println("toString"); 
     49        Highways highways = new Highways( 
     50                "config/vds_data/highways_fullmap.txt", 
     51                "localhost", 8080); 
     52        highways.getHighwayByRouteNumber(5).stations.get(0).loops.get(0).vol = 1; 
     53        String result = highways.toString(); 
     54        System.out.println(result); 
     55        assertEquals(expString, result); 
     56    } 
     57    String expString =  
     58 "241 ------------------------------------------------------------\n" 
     59+"  5 @-------------------------------------------------------------------------------------------------------------------------------------------\n" 
     60+"405 --------------------------------------------------------------------------------\n" 
     61+"133 ----------------\n" 
     62+"261 -----------------\n" 
     63+" 22 ----------------------------------\n" 
     64+" 55 ------------------------------------------\n" 
     65+" 73 -----------------------------------------------------\n" 
     66+" 57 ------------------------------------------\n" 
     67+" 91 --------------------------------------------------------------\n" 
     68+"605 ---\n"; 
     69 
     70    /** 
     71     * Test of toXML method 
    4672     */ 
    4773    public void testToXML() { 
    4874        System.out.println("toXML"); 
    4975        Highways highways = new Highways( 
    50                 "config/vds_data/highwaysMeta.txt", 
     76                "config/vds_data/highways_fullmap.txt", 
    5177                "localhost", 8080); 
    5278        String result = highways.toXML(); 
Note: See TracChangeset for help on using the changeset viewer.