-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.java
More file actions
54 lines (45 loc) · 1.12 KB
/
Vertex.java
File metadata and controls
54 lines (45 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.LinkedList;
import java.util.List;
public class Vertex {
public String name;
public int x;
public int y;
public boolean known;
public double distance; // total distance from origin point
public Vertex prev;
public List<Edge> adjacentEdges;
public Vertex(String name, int x, int y) {
this.name = name;
this.x = x;
this.y = y;
// by default java sets uninitialized boolean to false and double to 0
// hence known == false and dist == 0.0
adjacentEdges = new LinkedList<Edge>();
prev = null;
}
@Override
public int hashCode() {
// we assume that each vertex has a unique name
return name.hashCode();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
if (!(o instanceof Vertex)) {
return false;
}
Vertex oVertex = (Vertex) o;
return name.equals(oVertex.name) && x == oVertex.x && y == oVertex.y;
}
public void addEdge(Edge edge) {
adjacentEdges.add(edge);
}
public String toString() {
return name + " (" + x + ", " + y + ")";
}
}