blob: 87471e86dfb8f405d09822ca114b9e4186ffe3e9 (
plain) (
blame)
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
|
package nl.camilstaps.cs.graphs;
import java.util.ArrayList;
import java.util.List;
/**
* A Node is a simple point in a graph, with references to its neighbours. It holds an integer 'content' which can act
* as an identifier.
*
* @author Camil Staps
*/
public class Node {
private final int content;
private final List<Node> neighbours = new ArrayList<>();
public Node(int content) {
this.content = content;
}
/**
* Create a copy of another Node
* @param copy
*/
public Node(Node copy) {
this.content = copy.content;
this.neighbours.addAll(copy.neighbours);
}
public List<Node> getNeighbours() {
return neighbours;
}
public String toString() {
return "<" + content + ">";
}
/**
* Nodes are equal if their identifiers are equal
* @param another
* @return
*/
public boolean equals(Object another) {
return !(another == null || another.getClass() != this.getClass()) &&
content == (((Node) another).content);
}
}
|