-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
76 lines (60 loc) · 1.82 KB
/
Node.java
File metadata and controls
76 lines (60 loc) · 1.82 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.ArrayList;
import java.util.List;
public class Node implements Comparable<Node>{
// fields for a nodes name, list of hallways attached, whether it has been visited, the previous node and its distance
private String name;
private List<Hall> adjacentList;
private boolean visited;
private Node predecessor;
private Integer distance = Integer.MAX_VALUE;
// constructor
public Node(String name) {
this.name = name;
this.adjacentList = new ArrayList<>();
}
// method to add a hallway to the node
public void addNeighbour(Hall hall) {
this.adjacentList.add(hall);
}
// getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Hall> getAdjacentList() {
return adjacentList;
}
public void setAdjacentList(List<Hall> adjacentList) {
this.adjacentList = adjacentList;
}
public boolean isVisited() {
return visited;
}
public void setVisited(boolean visited) {
this.visited = visited;
}
public Node getPredecessor() {
return predecessor;
}
public void setPredecessor(Node predecessor) {
this.predecessor = predecessor;
}
public Integer getDistance() {
return distance;
}
public void setDistance(Integer distance) {
this.distance = distance;
}
// method to get the name of the string
@Override
public String toString() {
return this.name;
}
// compares wethers this node or another is less than, equal to, or more than
@Override
public int compareTo(Node otherNode) {
return Integer.compare(this.distance, otherNode.getDistance());
}
}