Warning: Can't use blame annotator:
svn blame failed on trunk/src/atmsdriver/model/TrafficEvent.java: ("Can't find a temporary directory: Internal error", 20014)

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

Revision 204, 2.6 KB checked in by jdalbey, 9 years ago (diff)

TrafficModelManager?.java Refactor for code sharing with TrafficModelEventDriver?. Write unit test.

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