From 9ef41c6308cbe5154877f899e27de587dbdff153 Mon Sep 17 00:00:00 2001 From: Nikolaus Krismer <nikolaus.krismer@uibk.ac.at> Date: Wed, 13 Aug 2014 12:51:28 +0200 Subject: [PATCH] added toString method (for debugging purpose9 sorting methods --- .../it/unibz/inf/isochrone/network/Node.java | 146 ++++++++++-------- 1 file changed, 78 insertions(+), 68 deletions(-) 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 d3a828bc..5e593c26 100644 --- a/src/main/java/it/unibz/inf/isochrone/network/Node.java +++ b/src/main/java/it/unibz/inf/isochrone/network/Node.java @@ -41,61 +41,7 @@ public class Node implements Comparable<Node> { routes = new Hashtable<>(); } - // Public methods - - public void addAdjLink(final Link link) { - if (adjLinks == null) { - adjLinks = new ArrayList<>(); - } - - adjLinks.add(link); - } - - public void addRoute(final int routeId) { - if (!routes.containsKey(routeId)) { - routes.put(routeId, new Schedule()); - } - } - - public void close() { - closed = true; - } - - @Override - public int compareTo(final Node other) { - if (other == null) { - return -1; - } - if (distance < other.distance) { - return -1; - } - if (distance > other.distance) { - return 1; - } - - return id - other.id; - } - - public boolean containsRoutes() { - return !routes.isEmpty(); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - final Node other = (Node) obj; - if (id != other.id || Double.doubleToLongBits(distance) != Double.doubleToLongBits(other.distance)) { - return false; - } - - return true; - } + // Getter public Collection<Link> getAdjLinks() { return adjLinks; @@ -140,19 +86,6 @@ 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; @@ -162,6 +95,8 @@ public class Node implements Comparable<Node> { return getNrAdjacentLinks() == 0; } + // Setter + public void setAdjLinks(final Collection<Link> adjLinks) { this.adjLinks = adjLinks; } @@ -196,6 +131,81 @@ public class Node implements Comparable<Node> { this.radius = radius; } + // Public methods + + public void addAdjLink(final Link link) { + if (adjLinks == null) { + adjLinks = new ArrayList<>(); + } + + adjLinks.add(link); + } + + public void addRoute(final int routeId) { + if (!routes.containsKey(routeId)) { + routes.put(routeId, new Schedule()); + } + } + + public void close() { + closed = true; + } + + @Override + public int compareTo(final Node other) { + if (other == null) { + return -1; + } + if (distance < other.distance) { + return -1; + } + if (distance > other.distance) { + return 1; + } + + return id - other.id; + } + + public boolean containsRoutes() { + return !routes.isEmpty(); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + + final Node other = (Node) obj; + if (id != other.id || Double.doubleToLongBits(distance) != Double.doubleToLongBits(other.distance)) { + return false; + } + + return true; + } + + @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; + } + + @Override + public String toString() { + return "Node [id=" + id + ", distance=" + distance + "]"; + } + public void visitNrAdjacentLinks(final int links) { nrAdjacentLinks -= links; } -- GitLab