1 package org.opentrafficsim.road.network.factory.opendrive;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.opentrafficsim.core.network.NetworkException;
9 import org.w3c.dom.Node;
10 import org.w3c.dom.NodeList;
11 import org.xml.sax.SAXException;
12
13
14
15
16
17
18
19
20
21
22
23 class LanesTag implements Serializable
24 {
25
26
27 private static final long serialVersionUID = 20150723L;
28
29
30 @SuppressWarnings("checkstyle:visibilitymodifier")
31 List<LaneSectionTag> laneSectionTags = new ArrayList<LaneSectionTag>();
32
33
34
35
36
37
38
39
40
41 @SuppressWarnings("checkstyle:needbraces")
42 static void parseLanes(final NodeList nodeList, final OpenDriveNetworkLaneParser parser, final RoadTag roadTag)
43 throws SAXException, NetworkException
44 {
45 int laneSectionCount = 0;
46 LanesTag lanesTag = new LanesTag();
47
48 for (Node node0 : XMLParser.getNodes(nodeList, "lanes"))
49 for (Node node : XMLParser.getNodes(node0.getChildNodes(), "laneSection"))
50 {
51 LaneSectionTag laneSectionTag = LaneSectionTag.parseLaneSection(node, parser);
52 laneSectionTag.id = laneSectionCount;
53 laneSectionCount++;
54
55 lanesTag.laneSectionTags.add(laneSectionTag);
56 }
57 roadTag.lanesTag = lanesTag;
58
59 }
60
61
62
63
64
65 public LaneSectionTag findDrivingLaneSec(Length s)
66 {
67 for (int i = 0; i < this.laneSectionTags.size(); i++)
68 {
69 if (i < this.laneSectionTags.size() - 1)
70 {
71 LaneSectionTag currentSec = this.laneSectionTags.get(i);
72 LaneSectionTag nextSec = this.laneSectionTags.get(i + 1);
73
74 if (s.si <= nextSec.s.si && s.si >= currentSec.s.si)
75 {
76 return currentSec;
77 }
78 }
79 else
80 {
81 LaneSectionTag currentSec = this.laneSectionTags.get(i);
82 if (s.si >= currentSec.s.si)
83 {
84 return currentSec;
85 }
86 }
87 }
88 return null;
89 }
90
91
92 @Override
93 public final String toString()
94 {
95 return "LanesTag [laneSectionTags=" + this.laneSectionTags + "]";
96 }
97 }