Changeset 220 in tmcsimulator for trunk


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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/application.properties

    r218 r220  
    1 #Fri, 03 Nov 2017 00:16:13 -0700 
     1#Fri, 03 Nov 2017 16:03:39 -0700 
    22 
    3 Application.revision=217 
     3Application.revision=218 
    44 
    55Application.buildnumber=69 
  • 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 
  • trunk/test/tmcsim/cadsimulator/managers/TrafficModelManagerTest.java

    r204 r220  
    3535    } 
    3636 
    37     /** 
    38      * Test of readBatchFile method, of class TrafficModelManager. 
    39      */ 
    4037    public void testReadBatchFile() throws SimulationException, ParseException 
    4138    { 
     
    5552        assertEquals(expResult, result); 
    5653    } 
    57      
     54    /** 
     55     * Test of readBatchFile method, of class TrafficModelManager. 
     56     */ 
     57    public void testReadBatchFile2() throws SimulationException, ParseException 
     58    { 
     59        System.out.println("readBatchFile blank lines test"); 
     60        String alpha = "    "; 
     61        String bravo = "187 00:00:37  55 S 6.88 0.2 R"; 
     62        String dataIn = alpha + "\n" + bravo + "\n"; 
     63        Scanner scan = new Scanner(dataIn); 
     64         
     65        LinkedList<TrafficEvent> result = TrafficModelManager.readBatchFile(scan); 
     66        assertEquals(1,result.size()); 
     67    } 
     68         
    5869    public void testCreateIncidentMap() throws ParseException 
    5970    { 
Note: See TracChangeset for help on using the changeset viewer.