aboutsummaryrefslogtreecommitdiff
path: root/Practical1/src/nl/camilstaps/cs/graphs/Node.java
diff options
context:
space:
mode:
authorCamil Staps2015-10-20 14:14:52 +0200
committerCamil Staps2015-10-20 14:14:52 +0200
commitda0e70ef00819bc847b44fc99ea84b935a09799c (patch)
tree4da0755be58039e5391f3b730c4f5bb559484691 /Practical1/src/nl/camilstaps/cs/graphs/Node.java
parentFinish assignment 7 (diff)
First version practical 1 (garbage collection)
Diffstat (limited to 'Practical1/src/nl/camilstaps/cs/graphs/Node.java')
-rw-r--r--Practical1/src/nl/camilstaps/cs/graphs/Node.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/Practical1/src/nl/camilstaps/cs/graphs/Node.java b/Practical1/src/nl/camilstaps/cs/graphs/Node.java
new file mode 100644
index 0000000..87471e8
--- /dev/null
+++ b/Practical1/src/nl/camilstaps/cs/graphs/Node.java
@@ -0,0 +1,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);
+ }
+}