Skip to content
Snippets Groups Projects
Commit 9ef41c63 authored by User expired's avatar User expired
Browse files

added toString method (for debugging purpose9

sorting methods
parent e8e4759a
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
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