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 bc323754fb8a2d182011f3dc29610a6910d698d9..deb58bcbda3b27455f62dd31bdf0aa9d29f7c3c7 100644 --- a/src/main/java/it/unibz/inf/isochrone/algorithm/Isochrone.java +++ b/src/main/java/it/unibz/inf/isochrone/algorithm/Isochrone.java @@ -149,6 +149,10 @@ public abstract class Isochrone { node.close(); final Collection<Link> adjacents = mapEntry.getValue(); + if (adjacents == null) { + throw new NullPointerException("Unexpected null value!"); + } + for (final Link link : adjacents) { if (link.isContinuous()) { updateQueue(expandContinuousLink(node, link)); @@ -315,9 +319,8 @@ public abstract class Isochrone { */ protected Map<Integer, Collection<Link>> calcAdjLinks(final Collection<Integer> nodes) { final Map<Integer, Collection<Link>> resultMap = new HashMap<>(); - for (Integer id : nodes) { - final Collection<Link> adjLinks = getNode(id).getAdjLinks(); - resultMap.put(id, adjLinks); + for (final Integer id : nodes) { + resultMap.put(id, getNode(id).getAdjLinks()); } return resultMap; diff --git a/src/main/java/it/unibz/inf/isochrone/algorithm/MineX.java b/src/main/java/it/unibz/inf/isochrone/algorithm/MineX.java index da4cf1827bcb025b7bc93c44237db2d89951e847..2786605806afd671a73a99129e06dd1b45a8cd58 100644 --- a/src/main/java/it/unibz/inf/isochrone/algorithm/MineX.java +++ b/src/main/java/it/unibz/inf/isochrone/algorithm/MineX.java @@ -71,7 +71,7 @@ public class MineX extends Isochrone { final Collection<Integer> c = new ArrayList<>(1); c.add(nodeId); - return database.getAdjLinks(c, nodes).get(nodeId); + return calcAdjLinks(c).get(nodeId); } @Override diff --git a/src/main/java/it/unibz/inf/isochrone/algorithm/MrneX.java b/src/main/java/it/unibz/inf/isochrone/algorithm/MrneX.java index 5055cdd6b3c307b94824bf39634745d4847fc881..a6d0635324b8b32e1c16fe120256776b4e0183be 100644 --- a/src/main/java/it/unibz/inf/isochrone/algorithm/MrneX.java +++ b/src/main/java/it/unibz/inf/isochrone/algorithm/MrneX.java @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -23,7 +22,7 @@ import java.util.Set; * Loads the data in circles surrounding the currently explored node. */ public class MrneX extends Isochrone { - private final Map<Integer, List<Link>> adjList; + private final Map<Integer, Collection<Link>> adjList; private final Map<Integer, Node> loadedIERNodes; private final Map<Integer, Node> nodes; private final int maxDuration; @@ -43,9 +42,9 @@ public class MrneX extends Isochrone { public MrneX(final ConfigDataset config, final Database db, final Query query, final int maxMemorySize) throws AlgorithmException { super(config, db, query); - adjList = new HashMap<Integer, List<Link>>(); - loadedIERNodes = new HashMap<Integer, Node>(); - nodes = new HashMap<Integer, Node>(); + adjList = new HashMap<>(); + loadedIERNodes = new HashMap<>(); + nodes = new HashMap<>(); maxDuration = query.getDuration().intValue(); maxMemory = maxMemorySize; walkingSpeed = query.getWalkingSpeed(); @@ -93,16 +92,19 @@ public class MrneX extends Isochrone { } } - final Map<Integer, Node> nullNodeMap = database.getNode(nullNodes); - final Set<Entry<Integer, Node>> nullNodeCheckList = nullNodeMap.entrySet(); - for (Entry<Integer, Node> e : nullNodeCheckList) { - final Integer nodeId = e.getKey(); - final Node node = e.getValue(); - if (node == null) { - throw new RuntimeException("NodeId not present: " + nodeId); - } + if (!nullNodes.isEmpty()) { + final Map<Integer, Node> nullNodeMap = database.getNode(nullNodes); + final Set<Entry<Integer, Node>> nullNodeCheckList = nullNodeMap.entrySet(); + for (Entry<Integer, Node> e : nullNodeCheckList) { + final Integer nodeId = e.getKey(); + final Node node = e.getValue(); + if (node == null) { + throw new RuntimeException("NodeId not present: " + nodeId); + } - result.put(nodeId, node); + nodes.put(nodeId, node); + result.put(nodeId, node); + } } return result; @@ -140,7 +142,7 @@ public class MrneX extends Isochrone { final Collection<Integer> nonCoordinateNodeIds = new ArrayList<>(maxNodeCount); for (Integer nodeId : nodeIds) { - final List<Link> adjNodeLinks = adjList.get(nodeId); + final Collection<Link> adjNodeLinks = adjList.get(nodeId); if (adjNodeLinks != null) { /* * Check if adjacent continuous links are empty @@ -170,10 +172,12 @@ public class MrneX extends Isochrone { } // fill coordinates of remaining nodes - final Map<Integer, Point> coordinates = database.getCoordinates(nonCoordinateNodeIds); - final Set<Entry<Integer, Point>> coordinatEntrySet = coordinates.entrySet(); - for (Entry<Integer, Point> e : coordinatEntrySet) { - nodeMap.get(e.getKey()).setCoordinates(e.getValue()); + if (!nonCoordinateNodeIds.isEmpty()) { + final Map<Integer, Point> coordinates = database.getCoordinates(nonCoordinateNodeIds); + final Set<Entry<Integer, Point>> coordinatEntrySet = coordinates.entrySet(); + for (Entry<Integer, Point> e : coordinatEntrySet) { + nodeMap.get(e.getKey()).setCoordinates(e.getValue()); + } } // prepare radius of remaining nodes 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 6711e5cb959aece9c82d9a488e00fbd1f04c0de5..2cb10bd42f0583d23cf250a23f1c1e50cd1683c5 100644 --- a/src/main/java/it/unibz/inf/isochrone/db/Database.java +++ b/src/main/java/it/unibz/inf/isochrone/db/Database.java @@ -18,7 +18,6 @@ import java.util.Calendar; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; @@ -157,7 +156,7 @@ public class Database { // Public methods - public void addLink(final Link link, final short degree, final Map<Integer, Node> nodes, final Map<Integer, List<Link>> adjList) { + public void addLink(final Link link, final short degree, final Map<Integer, Node> nodes, final Map<Integer, Collection<Link>> adjList) { int n1, n2; if (isIncoming) { n1 = link.getStartNode(); @@ -518,10 +517,12 @@ public class Database { /** * Loads the links in a circle from the database (for better explanation see the MrneX algorithm). */ - public void loadLinksFromIER(final Node node, final Collection<Node> intersections, final Map<Integer, Node> nodes, final Map<Integer, List<Link>> adjList) { + public void loadLinksFromIER(final Node node, final Collection<Node> intersections, final Map<Integer, Node> nodes, final Map<Integer, Collection<Link>> adjList) { PreparedStatement stmt = null; ResultSet rs = null; + final int serverSRID = config.getServerSRID(); + final double r = node.getRadius(); final Point g = node.getCoordinates(); final String pointString = "POINT( " + g.getX() + " " + g.getY() + ")"; try { @@ -529,13 +530,13 @@ public class Database { stmt = getPstmt(queryLoadLinksFromIER); // CHECKSTYLE:OFF MagicNumber stmt.setString(1, pointString); - stmt.setInt(2, config.getServerSRID()); - stmt.setDouble(3, node.getRadius()); + stmt.setInt(2, serverSRID); + stmt.setDouble(3, r); // CHECKSTYLE:ON MagicNumber } else { final Node[] loadedAreas = intersections.toArray(new Node[0]); final String disjunctAreaString = "st_difference(st_buffer(st_pointfromtext('" + pointString + "'," - + config.getServerSRID() + ")," + node.getRadius() + ")," + subQuery(loadedAreas, loadedAreas.length - 1, config.getServerSRID()) + ")"; + + config.getServerSRID() + ")," + r + ")," + subQuery(loadedAreas, loadedAreas.length - 1, serverSRID) + ")"; stmt = getPstmt(String.format(queryGetLinksInRange, disjunctAreaString)); } rs = stmt.executeQuery(); diff --git a/src/main/java/it/unibz/inf/isochrone/network/Node.java b/src/main/java/it/unibz/inf/isochrone/network/Node.java index f1d30d437f2998ff238c8dc90592cd235b1bdd71..4483565dd017bde9b4f333189e8a6771db0f239e 100644 --- a/src/main/java/it/unibz/inf/isochrone/network/Node.java +++ b/src/main/java/it/unibz/inf/isochrone/network/Node.java @@ -3,6 +3,7 @@ package it.unibz.inf.isochrone.network; import it.unibz.inf.isochrone.util.Point; import java.util.ArrayList; +import java.util.Collection; import java.util.Hashtable; import java.util.List; @@ -101,7 +102,7 @@ public class Node implements Comparable<Node> { return true; } - public List<Link> getAdjLinks() { + public Collection<Link> getAdjLinks() { return adjLinks; }