Changeset 220 in tmcsimulator for trunk/src/tmcsim/cadsimulator/managers


Ignore:
Timestamp:
11/03/2017 02:55:08 PM (8 years ago)
Author:
jdalbey
Message:

TrafficModelManager?.java: Modify readBatchFile() to ignore blank lines in events file. Add unit test for this feature.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java

    r210 r220  
    290290    { 
    291291        LinkedList<TrafficEvent> eventList = new LinkedList<TrafficEvent>(); 
    292             while (scan.hasNext()) 
    293             { 
    294                 // Read a line and add it to the event queue 
    295                 String line = scan.nextLine().trim(); 
    296                 if (line.charAt(0) != '#') 
    297                 { 
    298                     TrafficEvent evt; 
    299                     try 
    300                     { 
    301                         evt = new TrafficEvent(line); 
    302                         eventList.add(evt); 
    303                     } 
    304                     catch (ParseException ex) 
    305                     { 
    306                         Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, ex); 
    307                         System.out.println("Wrong format data in batch event file: " + line + " \nskipping."); 
    308                         System.out.println("Skipping badly formatted event."); 
    309                     } 
    310                 } 
    311             } 
     292        while (scan.hasNext()) 
     293        { 
     294            // Read a line and add it to the event queue 
     295            String line = scan.nextLine().trim(); 
     296            // Ignore blank lines and comments 
     297            if (line.length() > 0 && line.charAt(0) != '#') 
     298            { 
     299                TrafficEvent evt; 
     300                try 
     301                { 
     302                    evt = new TrafficEvent(line); 
     303                    eventList.add(evt); 
     304                } 
     305                catch (ParseException ex) 
     306                { 
     307                    Logger.getLogger(TrafficModelManager.class.getName()).log(Level.SEVERE, null, ex); 
     308                    System.out.println("Wrong format data in batch event file: " + line + " \nskipping."); 
     309                    System.out.println("Skipping badly formatted event."); 
     310                } 
     311            } 
     312        } 
    312313        System.out.println("Events file read, " + eventList.size() + " events queued."); 
    313314        // Put the events in chronological order 
Note: See TracChangeset for help on using the changeset viewer.