1 | package vnsim.vehicular.routePlan.cityRouting; |
---|
2 | |
---|
3 | import java.util.StringTokenizer; |
---|
4 | |
---|
5 | import vnsim.map.object.Globals; |
---|
6 | import vnsim.vehicular.simulator.intersections.DirectedRoadSegment; |
---|
7 | import vnsim.vehicular.simulator.intersections.Intersection; |
---|
8 | |
---|
9 | public class RoadSegmentCongestion { |
---|
10 | |
---|
11 | private int crossRoadIndex; |
---|
12 | private int segmentIndex; |
---|
13 | private Double congestion; |
---|
14 | |
---|
15 | public RoadSegmentCongestion(int crossIdx, int segmentIdx, Double congestion) { |
---|
16 | crossRoadIndex = crossIdx; |
---|
17 | segmentIndex = segmentIdx; |
---|
18 | this.congestion = congestion; |
---|
19 | } |
---|
20 | |
---|
21 | public int getCrossRoadIndex() { |
---|
22 | return crossRoadIndex; |
---|
23 | } |
---|
24 | |
---|
25 | public int getSegmentIndex() { |
---|
26 | return segmentIndex; |
---|
27 | } |
---|
28 | |
---|
29 | public Double getCongestion() { |
---|
30 | return congestion; |
---|
31 | } |
---|
32 | |
---|
33 | public void setCongestion(Double congestion) { |
---|
34 | this.congestion = congestion; |
---|
35 | } |
---|
36 | |
---|
37 | public boolean equals(RoadSegmentCongestion rsc) { |
---|
38 | return crossRoadIndex == rsc.getCrossRoadIndex() |
---|
39 | && segmentIndex == rsc.getSegmentIndex(); |
---|
40 | } |
---|
41 | |
---|
42 | public boolean equals(DirectedRoadSegment drs) { |
---|
43 | // all intersections must be in server db |
---|
44 | Intersection it = Globals.map.allIntersections.get(crossRoadIndex); |
---|
45 | DirectedRoadSegment thissegment = it.segments.get(segmentIndex); |
---|
46 | return drs.equals(thissegment); |
---|
47 | } |
---|
48 | |
---|
49 | public RoadSegmentCongestion clone() { |
---|
50 | return new RoadSegmentCongestion(crossRoadIndex, segmentIndex, |
---|
51 | congestion); |
---|
52 | } |
---|
53 | |
---|
54 | public static RoadSegmentCongestion createRoadSegmentCongestion(String str) { |
---|
55 | StringTokenizer st = new StringTokenizer(str); |
---|
56 | int crosIdx = Integer.parseInt(st.nextToken()); |
---|
57 | int segmentIdx = Integer.parseInt(st.nextToken()); |
---|
58 | Double congestion = Double.parseDouble(st.nextToken()); |
---|
59 | return new RoadSegmentCongestion(crosIdx, segmentIdx, congestion); |
---|
60 | } |
---|
61 | |
---|
62 | public String toString() { |
---|
63 | return "" + crossRoadIndex + " " + segmentIndex + " " + congestion; |
---|
64 | } |
---|
65 | } |
---|