1 package org.opentrafficsim.road.network.lane;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.opentrafficsim.core.geometry.OTSLine3D;
10 import org.opentrafficsim.core.gtu.GTUType;
11 import org.opentrafficsim.core.network.LinkType;
12 import org.opentrafficsim.core.network.LongitudinalDirectionality;
13 import org.opentrafficsim.core.network.OTSLink;
14 import org.opentrafficsim.core.network.OTSNode;
15 import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class CrossSectionLink extends OTSLink implements Serializable
30 {
31
32 private static final long serialVersionUID = 20141015L;
33
34
35 private final List<CrossSectionElement> crossSectionElementList = new ArrayList<>();
36
37
38 private final List<Lane> lanes = new ArrayList<>();
39
40
41 private final LaneKeepingPolicy laneKeepingPolicy;
42
43
44
45
46
47
48
49
50
51
52
53 public CrossSectionLink(final String id, final OTSNode startNode, final OTSNode endNode, final LinkType linkType,
54 final OTSLine3D designLine, final Map<GTUType, LongitudinalDirectionality> directionalityMap,
55 final LaneKeepingPolicy laneKeepingPolicy)
56 {
57 super(id, startNode, endNode, linkType, designLine, directionalityMap);
58 this.laneKeepingPolicy = laneKeepingPolicy;
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72 public CrossSectionLink(final String id, final OTSNode startNode, final OTSNode endNode, final LinkType linkType,
73 final OTSLine3D designLine, final LongitudinalDirectionality directionality,
74 final LaneKeepingPolicy laneKeepingPolicy)
75 {
76 super(id, startNode, endNode, linkType, designLine, directionality);
77 this.laneKeepingPolicy = laneKeepingPolicy;
78 }
79
80
81
82
83
84
85
86
87
88
89
90 public CrossSectionLink(final String id, final OTSNode startNode, final OTSNode endNode, final LinkType linkType,
91 final OTSLine3D designLine, final LaneKeepingPolicy laneKeepingPolicy)
92 {
93 this(id, startNode, endNode, linkType, designLine, new HashMap<GTUType, LongitudinalDirectionality>(),
94 laneKeepingPolicy);
95 }
96
97
98
99
100
101
102 protected final void addCrossSectionElement(final CrossSectionElement cse)
103 {
104 this.crossSectionElementList.add(cse);
105 if (cse instanceof Lane)
106 {
107 this.lanes.add((Lane) cse);
108 }
109 }
110
111
112
113
114
115
116
117 protected final void addCrossSectionElement(final CrossSectionElement cse, final int index)
118 {
119 this.crossSectionElementList.add(index, cse);
120 if (cse instanceof Lane)
121 {
122 this.lanes.add((Lane) cse);
123 }
124 }
125
126
127
128
129 public final List<CrossSectionElement> getCrossSectionElementList()
130 {
131 return this.crossSectionElementList;
132 }
133
134
135
136
137 public final LaneKeepingPolicy getLaneKeepingPolicy()
138 {
139 return this.laneKeepingPolicy;
140 }
141
142
143
144
145
146 public final CrossSectionElement getCrossSectionElement(final String id)
147 {
148 for (CrossSectionElement cse : this.crossSectionElementList)
149 {
150 if (cse.getId().equals(id))
151 {
152 return cse;
153 }
154 }
155 return null;
156 }
157
158
159
160
161 public final List<Lane> getLanes()
162 {
163 return this.lanes;
164 }
165 }