From fd4c9476100151a6411d20ca16ac1a475cdda726 Mon Sep 17 00:00:00 2001
From: Nikolaus Krismer <nikolaus.krismer@uibk.ac.at>
Date: Wed, 13 Aug 2014 16:54:34 +0200
Subject: [PATCH] fixed problem with unmodifieable collections

---
 .../inf/isochrone/algorithm/Isochrone.java    | 19 +++++++++++--------
 .../it/unibz/inf/isochrone/db/Database.java   | 12 ++++++------
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/main/java/it/unibz/inf/isochrone/algorithm/Isochrone.java b/src/main/java/it/unibz/inf/isochrone/algorithm/Isochrone.java
index c4c80756..6dda87a6 100644
--- a/src/main/java/it/unibz/inf/isochrone/algorithm/Isochrone.java
+++ b/src/main/java/it/unibz/inf/isochrone/algorithm/Isochrone.java
@@ -12,6 +12,7 @@ import it.unibz.inf.isochrone.network.NodeConnection;
 import it.unibz.inf.isochrone.util.EnumContainer.Direction;
 import it.unibz.inf.isochrone.util.Query;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
@@ -214,6 +215,8 @@ public abstract class Isochrone {
 	}
 
 	private Collection<Node> expandLinks(final Node node, final Collection<Link> links) {
+		final Collection<Node> resultNodes = new ArrayList<>();
+
 		final NodeConnection nConnections = new NodeConnection(node);
 		for (final Link link : links) {
 			final Node adjacentNode = getNode(link.getOppositeOf(node));
@@ -242,7 +245,7 @@ public abstract class Isochrone {
 			}
 		}
 
-		final Collection<Node> resultNodes = expandContinuousLinks(nConnections);
+		resultNodes.addAll(expandContinuousLinks(nConnections));
 		resultNodes.addAll(expandDiscreteLinks(nConnections));
 
 		return resultNodes;
@@ -263,8 +266,8 @@ public abstract class Isochrone {
 
 		final Set<Node> resultCollection = new HashSet<>();
 		final Node sourceNode = nConnection.getSourceNode();
-
-		for (final Entry<Node, Collection<Link>> e : nConnection.getContinuousTargets().entrySet()) {
+		final Set<Entry<Node, Collection<Link>>> entrySet = nConnection.getContinuousTargets().entrySet();
+		for (final Entry<Node, Collection<Link>> e : entrySet) {
 			final Node adjacentNode = e.getKey();
 			final Collection<Link> linkCollection = e.getValue();
 			for (final Link link : linkCollection) {
@@ -293,10 +296,10 @@ public abstract class Isochrone {
 			return Collections.emptyList();
 		}
 
-		final Set<Node> resultCollection = new HashSet<>();
-		final Map<Integer, Double> newDistances = getAdjNodeCost(nConnection);
-		for (final Entry<Integer, Double> e : newDistances.entrySet()) {
-			final Node adjacentNode = nConnection.getDiscreteTargetNode(e.getKey());
+		final Map<Node, Double> newDistances = getAdjNodeCost(nConnection);
+		final Set<Node> resultCollection = new HashSet<>(newDistances.size());
+		for (final Entry<Node, Double> e : newDistances.entrySet()) {
+			final Node adjacentNode = e.getKey();
 			final double newDistance = e.getValue();
 			if (newDistance <= qDuration && newDistance < adjacentNode.getDistance()) {
 				adjacentNode.setDistance(newDistance);
@@ -323,7 +326,7 @@ public abstract class Isochrone {
 	 * @param nConnection information about to where start the calculation, where to travel to and which routes are considered
 	 * @return the cost of traveling from the node to adjNode
 	 */
-	private Map<Integer, Double> getAdjNodeCost(final NodeConnection nConnection) {
+	private Map<Node, Double> getAdjNodeCost(final NodeConnection nConnection) {
 		return database.getAdjNodeCost(nConnection, dateCodes, qFromTime, qToTime);
 	}
 
diff --git a/src/main/java/it/unibz/inf/isochrone/db/Database.java b/src/main/java/it/unibz/inf/isochrone/db/Database.java
index efd2e3c8..61d5560b 100644
--- a/src/main/java/it/unibz/inf/isochrone/db/Database.java
+++ b/src/main/java/it/unibz/inf/isochrone/db/Database.java
@@ -224,8 +224,8 @@ public class Database {
 	 * @param toTime the latest time for which we want to calculate the departure time
 	 * @return the cost of for traveling from the start node to the end node
 	 */
-	public Map<Integer, Double> getAdjNodeCost(final NodeConnection nConnection, final Collection<Integer> dateCodes, final long fromTime, final long toTime) {
-		final Map<Integer, Double> resultMap = new HashMap<>();
+	public Map<Node, Double> getAdjNodeCost(final NodeConnection nConnection, final Collection<Integer> dateCodes, final long fromTime, final long toTime) {
+		final Map<Node, Double> resultMap = new HashMap<>();
 		final Node node = nConnection.getSourceNode();
 
 		ResultSet rs = null;
@@ -241,14 +241,14 @@ public class Database {
 					adjNode.setDepartureTime(routeId, departureTime);
 					node.setArrivalTime(routeId, arrivalTime);
 
-					Double minDistance = resultMap.get(adjNodeId);
+					Double minDistance = resultMap.get(adjNode);
 					if (minDistance == null) {
 						minDistance = Double.POSITIVE_INFINITY;
 					}
 
 					final double distance = toTime - departureTime;
 					if (distance < minDistance) {
-						resultMap.put(adjNodeId, distance);
+						resultMap.put(adjNode, distance);
 						adjNode.setCheapestReachedRouteId(routeId);
 					}
 				}
@@ -263,14 +263,14 @@ public class Database {
 					node.setDepartureTime(routeId, departureTime);
 					adjNode.setArrivalTime(routeId, arrivalTime);
 
-					Double minDistance = resultMap.get(adjNodeId);
+					Double minDistance = resultMap.get(adjNode);
 					if (minDistance == null) {
 						minDistance = Double.POSITIVE_INFINITY;
 					}
 
 					final double distance = arrivalTime > 0 ? arrivalTime - fromTime : Double.POSITIVE_INFINITY;
 					if (distance < minDistance) {
-						resultMap.put(adjNodeId, distance);
+						resultMap.put(adjNode, distance);
 						adjNode.setCheapestReachedRouteId(routeId);
 					}
 				}
-- 
GitLab