Skip to content
Snippets Groups Projects
Commit e8e4759a authored by User expired's avatar User expired
Browse files

now allowing multimap of links in node (each node can have multiple

links to the same target node) -> fixes reachability problem with new
getLatestDepartureTime/getEarliestArrivalTime sql queries
parent 1bf5cd27
No related branches found
No related tags found
No related merge requests found
package it.unibz.inf.isochrone.network;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class NodeConnection {
private final Node sourceNode;
private final Map<Node, Link> continuousTargetConnections;
private final Map<Node, Link> discreteTargetConnections;
private final Map<Node, Collection<Link>> continuousTargetConnections;
private final Map<Node, Collection<Link>> discreteTargetConnections;
// Collections
......@@ -26,10 +26,14 @@ public class NodeConnection {
return sourceNode;
}
public Map<Node, Link> getContinuousTargets() {
public Map<Node, Collection<Link>> getContinuousTargets() {
return continuousTargetConnections;
}
public Collection<Integer> getContinuousRouteToTargetNode(final int nodeId) {
return getRoutesToTargetNode(continuousTargetConnections, nodeId);
}
public Node getContinuousTargetNode(final int nodeId) {
return getNodeById(continuousTargetConnections, nodeId);
}
......@@ -42,11 +46,7 @@ public class NodeConnection {
return getIdsForTargetNodes(continuousTargetConnections);
}
public Collection<Integer> getContiunousRouteIds() {
return getIdsForRoutes(continuousTargetConnections);
}
public Map<Node, Link> getDiscreteTargets() {
public Map<Node, Collection<Link>> getDiscreteTargets() {
return discreteTargetConnections;
}
......@@ -62,8 +62,16 @@ public class NodeConnection {
return getIdsForRoutes(discreteTargetConnections);
}
public Map<Node, Link> getTargets() {
final Map<Node, Link> allTargets = new HashMap<>();
public Collection<Integer> getDiscreteRouteToTargetNode(final int nodeId) {
return getRoutesToTargetNode(discreteTargetConnections, nodeId);
}
public Collection<Integer> getRoutesToTargetNode(final int nodeId) {
return getRoutesToTargetNode(getTargets(), nodeId);
}
public Map<Node, Collection<Link>> getTargets() {
final Map<Node, Collection<Link>> allTargets = new HashMap<>();
allTargets.putAll(continuousTargetConnections);
allTargets.putAll(discreteTargetConnections);
......@@ -82,9 +90,9 @@ public class NodeConnection {
public void addTargetLink(final Node targetNode, final Link link) {
if (link.isContinuous()) {
continuousTargetConnections.put(targetNode, link);
addLinkForNode(continuousTargetConnections, targetNode, link);
} else {
discreteTargetConnections.put(targetNode, link);
addLinkForNode(discreteTargetConnections, targetNode, link);
}
}
......@@ -100,30 +108,56 @@ public class NodeConnection {
return !discreteTargetConnections.isEmpty();
}
@Override
public String toString() {
return "NodeConnection [sourceNode=" + sourceNode + "]";
}
// Private static methods
private static Node getNodeById(final Map<Node, Link> map, final int nodeId) {
final Set<Entry<Node, Link>> entries = map.entrySet();
for (final Entry<Node, Link> entry : entries) {
if (nodeId == entry.getKey().getId()) {
return entry.getKey();
private static void addLinkForNode(final Map<Node, Collection<Link>> m, final Node node, final Link link) {
Collection<Link> c = m.get(node);
if (c == null) {
c = new ArrayList<>();
}
c.add(link);
m.put(node, c);
}
private static Node getNodeById(final Map<Node, Collection<Link>> map, final int nodeId) {
final Set<Node> entries = map.keySet();
for (final Node n : entries) {
if (nodeId == n.getId()) {
return n;
}
}
return null;
}
private static Collection<Integer> getIdsForRoutes(final Map<Node, Link> m) {
final Collection<Link> linkSet = m.values();
private static Collection<Integer> getIdsForRoutes(final Map<Node, Collection<Link>> m) {
final Collection<Collection<Link>> linkSet = m.values();
final Set<Integer> resultSet = new HashSet<>(linkSet.size());
for (final Collection<Link> lCollection : linkSet) {
for (final Link l : lCollection) {
resultSet.add(l.getRoute());
}
}
return resultSet;
}
private static Collection<Integer> getRoutesToTargetNode(final Map<Node, Collection<Link>> m, final int nodeId) {
final Collection<Link> linkSet = m.get(nodeId);
final Set<Integer> resultSet = new HashSet<>(linkSet.size());
for (final Link l : linkSet) {
resultSet.add(l.getRoute());
}
return resultSet;
}
private static Collection<Integer> getIdsForTargetNodes(final Map<Node, Link> m) {
private static Collection<Integer> getIdsForTargetNodes(final Map<Node, Collection<Link>> m) {
final Set<Node> nodeSet = m.keySet();
final Set<Integer> resultSet = new HashSet<>(nodeSet.size());
for (final Node n : nodeSet) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment