source: tmcsimulator/trunk/src/atmsdriver/model/TrafficEvent.java @ 183

Revision 183, 2.2 KB checked in by jdalbey, 9 years ago (diff)

ATMSBatchDriver.java Enhanced to automatically sort events chronologically (using new class TrafficEvent?).

Line 
1
2package atmsdriver.model;
3
4import java.text.ParseException;
5import java.text.SimpleDateFormat;
6import java.util.Date;
7import java.util.Scanner;
8import java.util.logging.Level;
9import java.util.logging.Logger;
10import tmcsim.client.ATMSBatchDriver;
11
12/**
13 * Traffic Event represents some occurrence in the traffic on
14 * a highway network.  A traffic event occurs at a particular time
15 * and belongs to a unique simulation incident.  The event occurs on
16 * a specified section of a given highway route.  Each event specifies
17 * the level of traffic congestion by a color.  Events are comparable
18 * by the time of their occurrence.
19 * @author jdalbey
20 */
21public final class TrafficEvent implements Comparable<TrafficEvent>
22{
23    public final String incident;
24    public final String eventTime;
25    public final Date eventDate;  // for convenience
26    public final int routeNumber;
27    public final LoopDetector.DOTCOLOR color;
28    public final Station.DIRECTION dir;
29    public final double postmile;
30    public final double range;
31    public final String rawString;
32    private final static SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
33
34    /** Create an event from a string as in this example:
35     * 181 00:12:30 405 S 0.6 11.0 G
36     * @param eventString
37     * @return traffic event
38     * @throws Scanner exception if string improperly formatted
39     */
40    public TrafficEvent(String eventString) throws ParseException
41    {
42        this.rawString = eventString;
43        Scanner lineScan = new Scanner(eventString);
44        this.incident = lineScan.next();
45        this.eventTime = lineScan.next(); // time field
46        // may throw parseexception
47        this.eventDate = formatter.parse(eventTime);
48        this.routeNumber = lineScan.nextInt();
49        this.dir = Station.DIRECTION.toDirection(lineScan.next());
50        this.postmile = lineScan.nextDouble();
51        this.range = lineScan.nextDouble();
52        this.color = LoopDetector.DOTCOLOR.toDotColor(lineScan.next());   
53    }
54
55    @Override
56    public int compareTo(TrafficEvent o)
57    {
58        return eventDate.compareTo(o.eventDate);
59    }
60    @Override
61    public String toString()
62    {
63        return rawString;
64    }
65}
Note: See TracBrowser for help on using the repository browser.