File |
Line |
org\opentrafficsim\road\network\factory\xml\demand\XMLParser.java |
22 |
org\opentrafficsim\road\network\factory\xml\old\XMLParser.java |
22 |
public final class XMLParser
{
/** Utility class. */
private XMLParser()
{
// do not instantiate
}
/**
* @param nodeList NodeList; the list of nodes to process
* @param tag String; the tag to look for, e.g., LINK
* @return the nodes (which can contain nodeLists themselves) with the given tag
*/
public static List<Node> getNodes(final NodeList nodeList, final String tag)
{
List<Node> result = new ArrayList<>();
for (int i = 0; i < nodeList.getLength(); i++)
{
Node node = nodeList.item(i);
if (node instanceof Element)
{
if (tag.equals(node.getNodeName()))
{
result.add(node);
}
}
}
return result;
}
/**
* Returns nodes sorted by attributes and/or value. Nodes are sorted according to the given attribute order. In this order
* the node value can used by providing {@code null}.
* @param nodeList NodeList; the list of nodes to process
* @param tag String; the tag to look for, e.g., LINK
* @param sortAttributes String...; list of attributes, which may contain {@code null} to use the node value
* @return sorted nodes by attributes and/or value
*/
public static List<Node> getNodesSorted(final NodeList nodeList, final String tag, final String... sortAttributes)
{
List<Node> result = getNodes(nodeList, tag);
Collections.sort(result, new Comparator<Node>()
{
/** {@inheritDoc} */
@Override
public int compare(final Node o1, final Node o2)
{
for (String attribute : sortAttributes)
{
if (attribute == null)
{
Throw.when(o1.getNodeValue() == null || o2.getNodeValue() == null, RuntimeException.class,
"Tag %s cannot be sorted using it's value as tags without value are encountered.", tag);
return o1.getNodeValue().compareTo(o2.getNodeValue());
}
Node n1 = o1.getAttributes().getNamedItem(attribute);
Node n2 = o2.getAttributes().getNamedItem(attribute);
int order = 0;
if (n1 != null && n2 != null)
{
String attr1 = n1.getNodeValue();
String attr2 = n2.getNodeValue();
if (attr1 == null && attr2 != null)
{
order = -1;
}
else if (attr1 == null)
{
order = 0;
}
else if (attr2 == null)
{
order = 1;
}
else
{
order = attr1.compareTo(attr2);
}
if (order != 0)
{
return order;
}
}
}
return 0;
}
});
return result;
}
} |
File |
Line |
org\opentrafficsim\road\network\factory\xml\network\LinkParser.java |
474 |
org\opentrafficsim\road\network\factory\xml\old\LaneAttributes.java |
61 |
private static OvertakingConditions parseOvertakingConditions(String ocStr) throws NetworkException
{
if (ocStr.equals("LEFTONLY"))
{
return new OvertakingConditions.LeftOnly();
}
else if (ocStr.equals("RIGHTONLY"))
{
return new OvertakingConditions.RightOnly();
}
else if (ocStr.equals("LEFTANDRIGHT"))
{
return new OvertakingConditions.LeftAndRight();
}
else if (ocStr.equals("NONE"))
{
return new OvertakingConditions.None();
}
else if (ocStr.equals("SAMELANERIGHT"))
{
return new OvertakingConditions.SameLaneRight();
}
else if (ocStr.equals("SAMELANELEFT"))
{
return new OvertakingConditions.SameLaneLeft();
}
else if (ocStr.equals("SAMELANEBOTH"))
{
return new OvertakingConditions.SameLaneBoth();
}
else if (ocStr.startsWith("LEFTALWAYS RIGHTSPEED"))
{
int lb = ocStr.indexOf('(');
int rb = ocStr.indexOf(')');
if (lb == -1 || rb == -1 || rb - lb < 3)
{
throw new NetworkException("Speed in overtaking conditions string: '" + ocStr + "' not coded right");
}
Speed speed = SpeedUnits.parseSpeed(ocStr.substring(lb + 1, rb));
return new OvertakingConditions.LeftAlwaysRightSpeed(speed);
}
else if (ocStr.startsWith("RIGHTALWAYS LEFTSPEED"))
{
int lb = ocStr.indexOf('(');
int rb = ocStr.indexOf(')');
if (lb == -1 || rb == -1 || rb - lb < 3)
{
throw new NetworkException("Speed in overtaking conditions string: '" + ocStr + "' not coded right");
}
Speed speed = SpeedUnits.parseSpeed(ocStr.substring(lb + 1, rb));
return new OvertakingConditions.RightAlwaysLeftSpeed(speed);
} |
File |
Line |
org\opentrafficsim\road\network\factory\xml\old\LaneAttributes.java |
114 |
org\opentrafficsim\road\network\factory\xml\old\LaneAttributes.java |
140 |
else if (ocStr.startsWith("LEFTSET"))
{
int lset1 = ocStr.indexOf('[') + 1;
int rset1 = ocStr.indexOf(']', lset1);
int lset2 = ocStr.indexOf('[', ocStr.indexOf("OVERTAKE")) + 1;
int rset2 = ocStr.indexOf(']', lset2);
if (lset1 == -1 || rset1 == -1 || rset1 - lset1 < 3 || lset2 == -1 || rset2 == -1 || rset2 - lset2 < 3)
{
throw new NetworkException("Sets in overtaking conditions string: '" + ocStr + "' not coded right");
}
Set<GTUType> overtakingGTUs = parseGTUTypeSet(ocStr.substring(lset1, rset1), parser);
Set<GTUType> overtakenGTUs = parseGTUTypeSet(ocStr.substring(lset2, rset2), parser);
if (ocStr.contains("RIGHTSPEED")) |