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; package it.unibz.inf.isochrone.network;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
public class NodeConnection { public class NodeConnection {
private final Node sourceNode; private final Node sourceNode;
private final Map<Node, Link> continuousTargetConnections; private final Map<Node, Collection<Link>> continuousTargetConnections;
private final Map<Node, Link> discreteTargetConnections; private final Map<Node, Collection<Link>> discreteTargetConnections;
// Collections // Collections
...@@ -26,10 +26,14 @@ public class NodeConnection { ...@@ -26,10 +26,14 @@ public class NodeConnection {
return sourceNode; return sourceNode;
} }
public Map<Node, Link> getContinuousTargets() { public Map<Node, Collection<Link>> getContinuousTargets() {
return continuousTargetConnections; return continuousTargetConnections;
} }
public Collection<Integer> getContinuousRouteToTargetNode(final int nodeId) {
return getRoutesToTargetNode(continuousTargetConnections, nodeId);
}
public Node getContinuousTargetNode(final int nodeId) { public Node getContinuousTargetNode(final int nodeId) {
return getNodeById(continuousTargetConnections, nodeId); return getNodeById(continuousTargetConnections, nodeId);
} }
...@@ -42,11 +46,7 @@ public class NodeConnection { ...@@ -42,11 +46,7 @@ public class NodeConnection {
return getIdsForTargetNodes(continuousTargetConnections); return getIdsForTargetNodes(continuousTargetConnections);
} }
public Collection<Integer> getContiunousRouteIds() { public Map<Node, Collection<Link>> getDiscreteTargets() {
return getIdsForRoutes(continuousTargetConnections);
}
public Map<Node, Link> getDiscreteTargets() {
return discreteTargetConnections; return discreteTargetConnections;
} }
...@@ -62,8 +62,16 @@ public class NodeConnection { ...@@ -62,8 +62,16 @@ public class NodeConnection {
return getIdsForRoutes(discreteTargetConnections); return getIdsForRoutes(discreteTargetConnections);
} }
public Map<Node, Link> getTargets() { public Collection<Integer> getDiscreteRouteToTargetNode(final int nodeId) {
final Map<Node, Link> allTargets = new HashMap<>(); 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(continuousTargetConnections);
allTargets.putAll(discreteTargetConnections); allTargets.putAll(discreteTargetConnections);
...@@ -82,9 +90,9 @@ public class NodeConnection { ...@@ -82,9 +90,9 @@ public class NodeConnection {
public void addTargetLink(final Node targetNode, final Link link) { public void addTargetLink(final Node targetNode, final Link link) {
if (link.isContinuous()) { if (link.isContinuous()) {
continuousTargetConnections.put(targetNode, link); addLinkForNode(continuousTargetConnections, targetNode, link);
} else { } else {
discreteTargetConnections.put(targetNode, link); addLinkForNode(discreteTargetConnections, targetNode, link);
} }
} }
...@@ -100,30 +108,56 @@ public class NodeConnection { ...@@ -100,30 +108,56 @@ public class NodeConnection {
return !discreteTargetConnections.isEmpty(); return !discreteTargetConnections.isEmpty();
} }
@Override
public String toString() {
return "NodeConnection [sourceNode=" + sourceNode + "]";
}
// Private static methods // Private static methods
private static Node getNodeById(final Map<Node, Link> map, final int nodeId) { private static void addLinkForNode(final Map<Node, Collection<Link>> m, final Node node, final Link link) {
final Set<Entry<Node, Link>> entries = map.entrySet(); Collection<Link> c = m.get(node);
for (final Entry<Node, Link> entry : entries) { if (c == null) {
if (nodeId == entry.getKey().getId()) { c = new ArrayList<>();
return entry.getKey(); }
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; return null;
} }
private static Collection<Integer> getIdsForRoutes(final Map<Node, Link> m) { private static Collection<Integer> getIdsForRoutes(final Map<Node, Collection<Link>> m) {
final Collection<Link> linkSet = m.values(); 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()); final Set<Integer> resultSet = new HashSet<>(linkSet.size());
for (final Link l : linkSet) { for (final Link l : linkSet) {
resultSet.add(l.getRoute()); resultSet.add(l.getRoute());
} }
return resultSet; 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<Node> nodeSet = m.keySet();
final Set<Integer> resultSet = new HashSet<>(nodeSet.size()); final Set<Integer> resultSet = new HashSet<>(nodeSet.size());
for (final Node n : nodeSet) { 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