Changeset 129 in tmcsimulator


Ignore:
Timestamp:
10/17/2017 10:38:23 AM (9 years ago)
Author:
jdalbey
Message:

ATMSBatchDriver.java Updated to add an incident field to each event and create a map of incidents to list of events. This should enable implementing the feature that allows operator to clear all events for an incident.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/ATMSBatchDriver.java

    r128 r129  
    1515import java.text.ParseException; 
    1616import java.text.SimpleDateFormat; 
     17import java.util.ArrayList; 
    1718import java.util.Date; 
     19import java.util.HashMap; 
    1820import java.util.InputMismatchException; 
    1921import java.util.LinkedList; 
     22import java.util.List; 
     23import java.util.Map; 
    2024import java.util.Properties; 
    2125import java.util.Queue; 
     
    111115     */ 
    112116    private Queue<String> eventQueue; 
     117    /** 
     118     * Map of incidents to events 
     119     */ 
     120    private Map<String, List<String>> incidents; 
    113121     
    114122    /** Instance of ConsoleDriver that contains the highway model */ 
     
    132140            System.exit(0); 
    133141        } 
     142        incidents = new HashMap<String, List<String>> (); 
    134143        highways = new Highways( 
    135144        "config/vds_data/lds.txt", 
     
    179188                    // Get the time to launch the next event 
    180189                    String nextEvent = eventQueue.peek(); 
    181                     String eventTimeField = nextEvent.substring(0,8); 
     190//                    String eventTimeField = nextEvent.substring(0,8); 
     191                    Scanner evtScan = new Scanner(nextEvent); 
     192                    String inci = evtScan.next();       
     193                    String eventTimeField = evtScan.next(); 
    182194                    Date eventTime = new Date(); 
    183195                    try { 
     
    200212                        try 
    201213                        { 
     214                        lineScan.next(); // skip incident number field 
    202215                        lineScan.next(); // skip time field 
    203216                        int routeNumber = lineScan.nextInt(); 
     
    233246        try { 
    234247            fis = new FileInputStream("config/vds_data/atmsBatchEvents.txt"); 
     248            eventQueue = new LinkedList<String>(); 
     249            // Read all lines from the file of events 
    235250            Scanner scan = new Scanner(fis); 
    236             eventQueue = new LinkedList<String>(); 
    237251            while (scan.hasNext()) 
    238252            { 
    239                 eventQueue.add(scan.nextLine()); 
     253                // Read a line and add it to the event queue 
     254                String line = scan.nextLine(); 
     255                eventQueue.add(line); 
     256                // Parse the incident from the line 
     257                Scanner lineScan = new Scanner(line); 
     258                String incident = lineScan.next(); 
     259                // Add the line to the list for the corresponding incident 
     260                List evtList; 
     261                if (incidents.containsKey(incident)) 
     262                { 
     263                    evtList = incidents.get(incident); 
     264                } 
     265                else 
     266                { 
     267                    evtList = new ArrayList<String>(); 
     268                }                
     269                evtList.add(line); 
     270                // and put it back in the map 
     271                incidents.put(incident, evtList); 
    240272            } 
    241273        } catch (FileNotFoundException ex) { 
Note: See TracChangeset for help on using the changeset viewer.