Changeset 306 in tmcsimulator for trunk/src


Ignore:
Timestamp:
03/12/2019 11:23:26 AM (7 years ago)
Author:
jdalbey
Message:

Highways.java Enhanced/fixed so toJson() outputs each station only once (by removing Dir loop)

File:
1 edited

Legend:

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

    r287 r306  
    556556        for (Highway hwy: highways) 
    557557        { 
    558             // Consider each route direction 
    559             for (DIRECTION dir: DIRECTION.values()) 
    560             { 
    561                 // Examine every station on this highway and direction 
    562                 StringBuilder lineout = new StringBuilder(); 
    563                 for (Station stat: hwy.stations) 
    564                 { 
    565                     String pmID = "" + hwy.routeNumber + " "  
    566                             + stat.direction.getLetter() + " "  
    567                             + stat.postmile; 
    568                     PostmileCoords.Postmile currentPM = pmList.find(pmID); 
    569                     if (currentPM == null) 
    570                     {  
    571                     Logger.getLogger(Highways.class.getName()).log(Level.INFO,  
    572                             "Postmile Coords lookup couldn't find Station: "+pmID, 
    573                             " "); 
    574                     } 
    575                     if (currentPM != null) 
    576                     {     
    577                         //lineout.append("" + dir.getLetter() + stat.postmile); 
    578                         //lineout.append(stat.getColorByDirection(dir)); 
    579                         String outString = currentPM.toJson(); 
    580                         // replace the color code with the color name 
    581                         String colorName=stat.getColorName(); 
    582                         outString = outString.replace("desiredcolor",colorName); 
    583                         lineout.append(outString); 
    584                         lineout.append("  "); 
    585                     } 
    586                 } 
    587                 //result.append(rowLabel); 
    588                 result.append(lineout + "\n"); 
    589  
    590             } 
     558            // Examine every station on this highway 
     559            StringBuilder lineout = new StringBuilder(); 
     560            for (Station stat: hwy.stations) 
     561            { 
     562                String pmID = "" + hwy.routeNumber + " "  
     563                        + stat.direction.getLetter() + " "  
     564                        + stat.postmile; 
     565                PostmileCoords.Postmile currentPM = pmList.find(pmID); 
     566                if (currentPM == null) 
     567                {  
     568                Logger.getLogger(Highways.class.getName()).log(Level.INFO,  
     569                        "Postmile Coords lookup couldn't find Station: "+pmID, 
     570                        " "); 
     571                } 
     572                if (currentPM != null) 
     573                {     
     574                    //lineout.append("" + dir.getLetter() + stat.postmile); 
     575                    //lineout.append(stat.getColorByDirection(dir)); 
     576                    String outString = currentPM.toJson(); 
     577                    // replace the color code with the color name 
     578                    String colorName=stat.getColorName(); 
     579                    outString = outString.replace("desiredcolor",colorName); 
     580                    lineout.append(outString); 
     581                    lineout.append("  "); 
     582                } 
     583            } 
     584            //result.append(rowLabel); 
     585            result.append(lineout + "\n"); 
     586 
    591587        } 
    592588        // remove last trailing comma 
Note: See TracChangeset for help on using the changeset viewer.