List<String> idList = new ArrayList<String>();
HashMap<String, List<String>> fromToNodes = new HashMap<String, List<String>>();
String id;
stringBuffer.append(XMLStart);
stringBuffer.append(TEXT_1);
EdgeModel edge;
int duplicates = 0;
int sameNodes = 0;
for (Iterator<EdgeModel> i = elementList.iterator(); i.hasNext();) {
edge = (EdgeModel) i.next();
id = edge.getInternalID();
// ignore duplicate ids
if (idList.contains(id)) {
// id = id + "I";
logger.info("Found duplicate edge! ID=" +
edge.getInternalID());
duplicates++;
continue;
}
// ignore edges with same from and to node
// Assumption: two edges with same to and from node are equal
List<String> toIDList = fromToNodes.get(
edge.getFromNode().getInternalID());
boolean sameFound = false;
if (toIDList == null) {
//can't be duplicate
//create new list and add 'to' node to it
List<String> list = new ArrayList<String>();
list.add(edge.getToNode().getInternalID());
fromToNodes.put(edge.getFromNode().getInternalID(), list);
} else {
for (String toID : toIDList) {
if (toID.equals(edge.getToNode().getInternalID())) {
logger.info("Found edge with same nodes as a previous edge! ID=" +
edge.getInternalID());
sameNodes++;
sameFound = true;
break;
}
}
if (sameFound) {
continue;
}
// no duplicate
// add 'to' node to the list belonging to 'from' node
fromToNodes.get(edge.getFromNode().getInternalID()).add(
edge.getToNode().getInternalID());
}
idList.add(id);
if (!((NodeModel) edge.getFromNode()).getInternalID().equals(
((NodeModel) edge.getToNode()).getInternalID())) {
stringBuffer.append(TEXT_2);
stringBuffer.append(id);
stringBuffer.append(TEXT_3);
stringBuffer
.append(((NodeModel) edge.getFromNode()).getInternalID());
stringBuffer.append(TEXT_4);
stringBuffer.append(((NodeModel) edge.getToNode()).getInternalID());
stringBuffer.append(TEXT_5);
stringBuffer.append(edge.getPriority());
stringBuffer.append(TEXT_6);
stringBuffer.append(edge.getNoOfLanes());
stringBuffer.append(TEXT_7);
stringBuffer.append(edge.getMaxspeed() * speedFactor);
stringBuffer.append(TEXT_8);
}
//stringBuffer.append(TEXT_9);
}
stringBuffer.append(TEXT_10);