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

introduced superclass to node and link (new class networkEntity), since

both have an id
parent 695c869e
No related branches found
No related tags found
No related merge requests found
......@@ -5,9 +5,8 @@ package it.unibz.inf.isochrone.network;
* and either a linkCost or a routeId depending on whether the link is
* continuous or discrete.
*/
public class Link {
public class Link extends NetworkEntity {
private static final double LENGTH_RESOLUTION = 0.01d;
private final int id;
private final int startNode;
private final int endNode;
private final boolean continuous;
......@@ -25,7 +24,7 @@ public class Link {
* @param length the costs of the link (also called length)
*/
public Link(final int id, final int startNodeId, final int endNodeId, final double length) {
this.id = id;
super(id);
this.startNode = startNodeId;
this.endNode = endNodeId;
this.length = length;
......@@ -42,7 +41,7 @@ public class Link {
* @param routeId the id of the route this link belongs to
*/
public Link(final int id, final int startNodeId, final int endNodeId, final int routeId) {
this.id = id;
super(id);
this.startNode = startNodeId;
this.endNode = endNodeId;
this.route = routeId;
......@@ -60,10 +59,6 @@ public class Link {
return endOffset;
}
public int getId() {
return id;
}
public double getLength() {
return length;
}
......@@ -146,7 +141,7 @@ public class Link {
result = prime * result + endNode;
temp = Double.doubleToLongBits(endOffset);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + id;
result = prime * result + getId();
temp = Double.doubleToLongBits(length);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + route;
......@@ -160,7 +155,7 @@ public class Link {
@Override
public String toString() {
return "Link [id=" + id + ", continuous=" + continuous + ", length=" + length + "]";
return "Link [id=" + getId() + ", continuous=" + continuous + ", length=" + length + "]";
}
}
package it.unibz.inf.isochrone.network;
public class NetworkEntity implements Comparable<NetworkEntity> {
private final int id;
public NetworkEntity(final int id) {
this.id = id;
}
// Getter
public int getId() {
return id;
}
// Public method
@Override
public int compareTo(final NetworkEntity other) {
if (other == null) {
return -1;
}
return id - other.id;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final NetworkEntity other = (NetworkEntity) obj;
if (id != other.id) {
return false;
}
return true;
}
@Override
public int hashCode() {
final int prime = 31;
return prime + id;
}
@Override
public String toString() {
return "NetworkEntity [id=" + id + "]";
}
}
......@@ -11,8 +11,7 @@ import java.util.Map;
* Represent a node in a network. The number of adjacent links is
* used to track how many adjacent links have already been explored.
*/
public class Node implements Comparable<Node> {
private final int id;
public class Node extends NetworkEntity {
private final Map<Integer, Schedule> routes;
private double distance;
......@@ -34,7 +33,7 @@ public class Node implements Comparable<Node> {
}
public Node(final int nodeId, final short nrAdjacentLinks) {
id = nodeId;
super(nodeId);
distance = Double.POSITIVE_INFINITY;
this.nrAdjacentLinks = nrAdjacentLinks;
closed = false;
......@@ -59,10 +58,6 @@ public class Node implements Comparable<Node> {
return distance;
}
public int getId() {
return id;
}
public short getNrAdjacentLinks() {
return nrAdjacentLinks;
}
......@@ -152,18 +147,23 @@ public class Node implements Comparable<Node> {
}
@Override
public int compareTo(final Node other) {
public int compareTo(final NetworkEntity other) {
if (other == null) {
return -1;
}
if (distance < other.distance) {
if (!(other instanceof Node)) {
return super.compareTo(other);
}
final Node n = (Node) other;
if (distance < n.distance) {
return -1;
}
if (distance > other.distance) {
if (distance > n.distance) {
return 1;
}
return id - other.id;
return getId() - n.getId();
}
public boolean containsRoutes() {
......@@ -180,7 +180,7 @@ public class Node implements Comparable<Node> {
}
final Node other = (Node) obj;
if (id != other.id || Double.doubleToLongBits(distance) != Double.doubleToLongBits(other.distance)) {
if (getId() != other.getId() || Double.doubleToLongBits(distance) != Double.doubleToLongBits(other.distance)) {
return false;
}
......@@ -195,7 +195,7 @@ public class Node implements Comparable<Node> {
final long temp = Double.doubleToLongBits(distance);
// CHECKSTYLE:OFF MagicNumber
result = prime * result + (int) (temp ^ temp >>> 32);
result = prime * result + id;
result = prime * result + getId();
// CHECKSTYLE:ON MagicNumber
return result;
......@@ -203,7 +203,7 @@ public class Node implements Comparable<Node> {
@Override
public String toString() {
return "Node [id=" + id + ", distance=" + distance + "]";
return "Node [id=" + getId() + ", distance=" + distance + "]";
}
public void visitNrAdjacentLinks(final int 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