1 package org.opentrafficsim.road.network.factory.xml.old;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.opentrafficsim.core.network.NetworkException;
8 import org.w3c.dom.NamedNodeMap;
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 class ShortestRouteMixTag implements Serializable
23 {
24
25 private static final long serialVersionUID = 20150723L;
26
27
28 @SuppressWarnings("checkstyle:visibilitymodifier")
29 String name = null;
30
31
32 @SuppressWarnings("checkstyle:visibilitymodifier")
33 List<ShortestRouteTag> routes = new ArrayList<ShortestRouteTag>();
34
35
36 @SuppressWarnings("checkstyle:visibilitymodifier")
37 List<Double> weights = new ArrayList<Double>();
38
39
40
41
42
43
44
45
46 @SuppressWarnings("checkstyle:needbraces")
47 static void parseShortestRouteMix(final NodeList nodeList, final XmlNetworkLaneParserOld parser)
48 throws SAXException, NetworkException
49 {
50 for (Node node : XMLParser.getNodes(nodeList, "SHORTESTROUTEMIX"))
51 {
52 NamedNodeMap attributes = node.getAttributes();
53 ShortestRouteMixTag shortestRouteMixTag = new ShortestRouteMixTag();
54
55 if (attributes.getNamedItem("NAME") == null)
56 throw new SAXException("SHORTESTROUTEMIX: missing attribute NAME");
57 shortestRouteMixTag.name = attributes.getNamedItem("NAME").getNodeValue().trim();
58 if (parser.routeTags.keySet().contains(shortestRouteMixTag.name))
59 throw new SAXException("SHORTESTROUTEMIX: NAME " + shortestRouteMixTag.name + " defined twice");
60
61 List<Node> shortestRouteList = XMLParser.getNodes(node.getChildNodes(), "SHORTESTROUTE");
62 if (shortestRouteList.size() == 0)
63 throw new SAXException("SHORTESTROUTEMIX: missing tag SHORTESTROUTE");
64 for (Node shortestRouteNode : shortestRouteList)
65 {
66 parseRouteMixRouteTag(shortestRouteNode, parser, shortestRouteMixTag);
67 }
68
69 parser.shortestRouteMixTags.put(shortestRouteMixTag.name, shortestRouteMixTag);
70 }
71 }
72
73
74
75
76
77
78
79
80
81 @SuppressWarnings("checkstyle:needbraces")
82 private static void parseRouteMixRouteTag(final Node shortestRouteNode, final XmlNetworkLaneParserOld parser,
83 final ShortestRouteMixTag shortestRouteMixTag) throws NetworkException, SAXException
84 {
85 NamedNodeMap attributes = shortestRouteNode.getAttributes();
86
87 Node shortestRouteName = attributes.getNamedItem("NAME");
88 if (shortestRouteName == null)
89 throw new NetworkException("SHORTESTROUTEMIX: No SHORTESTROUTE NAME defined");
90 if (!parser.routeTags.containsKey(shortestRouteName.getNodeValue().trim()))
91 throw new NetworkException("SHORTESTROUTEMIX: " + shortestRouteMixTag.name + " SHORTESTROUTE "
92 + shortestRouteName.getNodeValue().trim() + " not defined");
93 shortestRouteMixTag.routes.add(parser.shortestRouteTags.get(shortestRouteName.getNodeValue().trim()));
94
95 Node weight = attributes.getNamedItem("WEIGHT");
96 if (weight == null)
97 throw new NetworkException("SHORTESTROUTEMIX: " + shortestRouteMixTag.name + " SHORTESTROUTE "
98 + shortestRouteName.getNodeValue().trim() + ": weight not defined");
99 shortestRouteMixTag.weights.add(Double.parseDouble(weight.getNodeValue()));
100 }
101
102
103 @Override
104 public final String toString()
105 {
106 return "ShortestRouteMixTag [name=" + this.name + ", routes=" + this.routes + ", weights=" + this.weights + "]";
107 }
108
109 }