Skip to content
Snippets Groups Projects
Commit d94a8b65 authored by Nikolaus Krismer's avatar Nikolaus Krismer
Browse files

fixing even more dinfbugs issues

parent 805f38f1
No related branches found
No related tags found
No related merge requests found
......@@ -26,9 +26,11 @@ import java.util.Set;
* algorithms which define the loading of the data from the database.
*/
public abstract class Isochrone {
private static final double COMPARE_PRECISION = 0.0000001d;
private final Query query;
private final PriorityQueue<Node> queue;
private Set<Integer> codes;
protected Database db;
/**
......@@ -126,7 +128,7 @@ public abstract class Isochrone {
for (final Link link : adjacents) {
if (link.isContinuous()) {
updateQueue(expandContinuousLink(node, link));
if (link.getStartOffset() != Double.MIN_VALUE) {
if (Math.abs(link.getStartOffset() - Double.MIN_VALUE) < COMPARE_PRECISION) {
output.output(link);
}
} else {
......
......@@ -81,11 +81,6 @@ public class Link {
throw new RuntimeException("There is no route for a continuous link");
}
@Override
public int hashCode() {
return getID();
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Link)) {
......@@ -107,6 +102,29 @@ public class Link {
return (getRoute() == l.getRoute());
}
@Override
public int hashCode() {
final int prime = 31;
long temp;
int result = 1;
// CHECKSTYLE:OFF MagicNumber
result = prime * result + (continuous ? 1231 : 1237);
result = prime * result + endNode;
temp = Double.doubleToLongBits(endOffset);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + id;
temp = Double.doubleToLongBits(length);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + route;
result = prime * result + startNode;
temp = Double.doubleToLongBits(startOffset);
result = prime * result + (int) (temp ^ (temp >>> 32));
// CHECKSTYLE:ON MagicNumber
return result;
}
public boolean isContinuous() {
return continuous;
}
......
......@@ -18,12 +18,12 @@ public class Node implements Comparable<Node> {
private boolean closed;
private Point coordinates = null; // For MrneX
private double radius = Double.NEGATIVE_INFINITY; // MrneX
private List<Link> adjLinks = null;
private Hashtable<Integer, Schedule> routes;
private int cheapestReachedRouteId = Integer.MIN_VALUE;
// Constructors
public Node(final int nodeId) {
id = nodeId;
distance = Double.POSITIVE_INFINITY;
......@@ -38,52 +38,24 @@ public class Node implements Comparable<Node> {
closed = false;
}
public int getID() {
return id;
}
public double getDistance() {
return distance;
}
public void setDistance(final double distance) {
this.distance = distance;
}
public void setCoordinates(final Point coordinates) {
this.coordinates = coordinates;
}
// Public methods
public Point getCoordinates() {
return coordinates;
}
public void setRadius(final double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setNrAdjacentLinks(final short nr) {
nrAdjacentLinks = nr;
}
public short getNrAdjacentLinks() {
return nrAdjacentLinks;
}
public void addAdjLink(final Link link) {
if (adjLinks == null) {
adjLinks = new ArrayList<Link>();
}
public void visitNrAdjacentLinks(final int links) {
nrAdjacentLinks -= links;
adjLinks.add(link);
}
public boolean isExpired() {
return (getNrAdjacentLinks() == 0);
}
public void addRoute(final int routeId) {
if (routes == null) {
routes = new Hashtable<Integer, Schedule>();
}
public boolean isClosed() {
return closed;
if (!routes.containsKey(routeId)) {
routes.put(routeId, new Schedule());
}
}
public void close() {
......@@ -102,55 +74,56 @@ public class Node implements Comparable<Node> {
return 1;
}
return 0;
return id - other.id;
}
public void setAdjLinks(final List<Link> adjLinks) {
this.adjLinks = adjLinks;
public boolean containsRoutes() {
return routes != null && !routes.isEmpty();
}
public List<Link> getAdjLinks() {
return adjLinks;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
public void addAdjLink(final Link link) {
if (adjLinks == null) {
adjLinks = new ArrayList<Link>();
Node other = (Node) obj;
if (Double.doubleToLongBits(distance) != Double.doubleToLongBits(other.distance) || id != other.id) {
return false;
}
adjLinks.add(link);
return true;
}
public void addRoute(final int routeId) {
if (routes == null) {
routes = new Hashtable<Integer, Schedule>();
}
public List<Link> getAdjLinks() {
return adjLinks;
}
if (!routes.containsKey(routeId)) {
routes.put(routeId, new Schedule());
}
public int getCheapestReachedRouteId() {
return cheapestReachedRouteId;
}
public void setArrivalTime(final int routeId, final long arrivalTime) {
addRoute(routeId);
routes.get(routeId).setArrivalTime(arrivalTime);
public Point getCoordinates() {
return coordinates;
}
public void setDepartureTime(final int routeId, final long departureTime) {
addRoute(routeId);
routes.get(routeId).setDepartureTime(departureTime);
public double getDistance() {
return distance;
}
public void setCheapestReachedRouteId(final int cheapestReachedRouteId) {
this.cheapestReachedRouteId = cheapestReachedRouteId;
public int getID() {
return id;
}
public int getCheapestReachedRouteId() {
return cheapestReachedRouteId;
public short getNrAdjacentLinks() {
return nrAdjacentLinks;
}
public boolean containsRoutes() {
return routes != null && !routes.isEmpty();
public double getRadius() {
return radius;
}
public Hashtable<Integer, Schedule> getRouteSchedules() {
......@@ -167,4 +140,64 @@ public class Node implements Comparable<Node> {
return "OPEN";
}
@Override
public int hashCode() {
int result = 1;
final int prime = 31;
final long temp = Double.doubleToLongBits(distance);
// CHECKSTYLE:OFF MagicNumber
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + id;
// CHECKSTYLE:ON MagicNumber
return result;
}
public boolean isClosed() {
return closed;
}
public boolean isExpired() {
return (getNrAdjacentLinks() == 0);
}
public void setAdjLinks(final List<Link> adjLinks) {
this.adjLinks = adjLinks;
}
public void setArrivalTime(final int routeId, final long arrivalTime) {
addRoute(routeId);
routes.get(routeId).setArrivalTime(arrivalTime);
}
public void setCheapestReachedRouteId(final int cheapestReachedRouteId) {
this.cheapestReachedRouteId = cheapestReachedRouteId;
}
public void setCoordinates(final Point coordinates) {
this.coordinates = coordinates;
}
public void setDepartureTime(final int routeId, final long departureTime) {
addRoute(routeId);
routes.get(routeId).setDepartureTime(departureTime);
}
public void setDistance(final double distance) {
this.distance = distance;
}
public void setNrAdjacentLinks(final short nr) {
nrAdjacentLinks = nr;
}
public void setRadius(final double radius) {
this.radius = radius;
}
public void visitNrAdjacentLinks(final int links) {
nrAdjacentLinks -= links;
}
}
......@@ -134,8 +134,9 @@ public class Config {
internalProperties.loadFromXML(inputStream);
internalProperties.putAll(System.getProperties());
if (densityLimit == Short.MIN_VALUE && getProperty("limit.density") != null) {
densityLimit = Short.parseShort(getProperty("limit.density"));
final String density = getProperty("limit.density");
if (densityLimit == Short.MIN_VALUE && density != null) {
densityLimit = Short.parseShort(density);
}
} catch (final InvalidPropertiesFormatException e) {
......
......@@ -32,19 +32,19 @@ public class MemoryBBoxOutput extends MemoryOutput {
+ "(SELECT st_transform(ST_SetSRID(st_extent(\"GEOMETRY\"),?),?) GEO FROM "
+ config.getDestinationEdgeTableEntry().getTableName() + ") mbr";
PreparedStatement statement = null;
long minX, minY, maxX, maxY;
minX = Long.MAX_VALUE;
minY = minX;
maxX = Long.MIN_VALUE;
maxY = maxX;
long minX = Long.MAX_VALUE;
long minY = minX;
long maxX = Long.MIN_VALUE;
long maxY = maxX;
final Connection connection = config.getConnection();
PreparedStatement statement = null;
ResultSet rSet = null;
try {
final Connection connection = config.getConnection();
statement = connection.prepareStatement(q);
statement.setInt(1, config.getServerSRID());
statement.setInt(2, config.getClientSRID());
final ResultSet rSet = statement.executeQuery();
rSet = statement.executeQuery();
if (rSet.next()) {
minX = Math.round(rSet.getDouble("min_x"));
minY = Math.round(rSet.getDouble("min_y"));
......@@ -55,8 +55,10 @@ public class MemoryBBoxOutput extends MemoryOutput {
} catch (final SQLException e) {
e.printStackTrace();
} finally {
DbUtils.closeQuietly(rSet);
DbUtils.closeQuietly(statement);
}
return null;
}
......
......@@ -15,10 +15,11 @@ import it.unibz.inf.isoga.datastructure.QueryPoint;
import it.unibz.inf.isoga.db.DBUtility;
import it.unibz.inf.isoga.db.IsogaDatabase;
import it.unibz.inf.isoga.network.MemoryBBoxOutput;
import it.unibz.inf.isoga.util.IsogaConfig;
import it.unibz.inf.isoga.util.DSetConfig;
import it.unibz.inf.isoga.util.IsogaConfig;
import it.unibz.inf.isoga.util.JSONConstants;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.text.DateFormat;
......@@ -111,14 +112,9 @@ public class ServiceIsochrone extends AbstractService {
cfgFile += "config_bz.xml";
}
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
InputStream resourceAsStream = contextClassLoader.getResourceAsStream(cfgFile);
if (resourceAsStream == null) {
resourceAsStream = session.getClass().getResourceAsStream(cfgFile);
}
final IsogaConfig config = socketConfig.getClientConfig(clientId);
config.appendPropertyFile(resourceAsStream);
appendProperties(config, cfgFile, session);
final DSetConfig dSetConfig = socketConfig.getClientDataset(clientId).get(dataset);
if (!dSetConfig.isRegistered()) {
final Connection connection = config.getConnection();
......@@ -213,6 +209,26 @@ public class ServiceIsochrone extends AbstractService {
// t.start();
}
private void appendProperties(final IsogaConfig config, final String cfgFile, final Session session) {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
InputStream resourceAsStream = null;
try {
resourceAsStream = contextClassLoader.getResourceAsStream(cfgFile);
if (resourceAsStream == null) {
// TODO: Test me: Does this really work with websockets (did this really work with cometd?)
resourceAsStream = session.getClass().getResourceAsStream(cfgFile);
}
config.appendPropertyFile(resourceAsStream);
} finally {
try {
resourceAsStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// Private methods
private Set<Location> locationsFromQueryPoints(final String qPoints, final IsogaConfig config) {
......
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