1 package org.opentrafficsim.road.gtu.lane.perception;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.opentrafficsim.core.gtu.GTUDirectionality;
9 import org.opentrafficsim.core.gtu.GTUType;
10 import org.opentrafficsim.road.network.lane.Lane;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class LaneDirectionRecord implements LaneRecord<LaneDirectionRecord>
27 {
28
29
30 private final Lane lane;
31
32
33 private final GTUDirectionality dir;
34
35
36 private final Length startDistance;
37
38
39 private final GTUType gtuType;
40
41
42 private List<LaneDirectionRecord> next;
43
44
45 private List<LaneDirectionRecord> prev;
46
47
48
49
50
51
52
53
54 public LaneDirectionRecord(final Lane lane, final GTUDirectionality dir, final Length startDistance, final GTUType gtuType)
55 {
56 this.lane = lane;
57 this.dir = dir;
58 this.startDistance = startDistance;
59 this.gtuType = gtuType;
60 }
61
62
63 @Override
64 public List<LaneDirectionRecord> getNext()
65 {
66 if (this.next == null)
67 {
68 Map<Lane, GTUDirectionality> map = this.lane.downstreamLanes(this.dir, this.gtuType);
69 this.next = new ArrayList<>();
70 Length distance = this.startDistance.plus(getLength());
71 for (Lane down : map.keySet())
72 {
73 this.next.add(new LaneDirectionRecord(down, map.get(down), distance, this.gtuType));
74 }
75 }
76 return this.next;
77 }
78
79
80 @Override
81 public List<LaneDirectionRecord> getPrev()
82 {
83 if (this.prev == null)
84 {
85 Map<Lane, GTUDirectionality> map = this.lane.upstreamLanes(this.dir, this.gtuType);
86 this.prev = new ArrayList<>();
87 for (Lane up : map.keySet())
88 {
89 this.prev.add(new LaneDirectionRecord(up, map.get(up), this.startDistance.minus(up.getLength()), this.gtuType));
90 }
91 }
92 return this.prev;
93 }
94
95
96 @Override
97 public Length getStartDistance()
98 {
99 return this.startDistance;
100 }
101
102
103 @Override
104 public Length getLength()
105 {
106 return this.lane.getLength();
107 }
108
109
110 @Override
111 public GTUDirectionality getDirection()
112 {
113 return this.dir;
114 }
115
116
117 @Override
118 public Lane getLane()
119 {
120 return this.lane;
121 }
122
123 }