From da0e70ef00819bc847b44fc99ea84b935a09799c Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 20 Oct 2015 14:14:52 +0200 Subject: First version practical 1 (garbage collection) --- Practical1/src/nl/camilstaps/cs/graphs/Node.java | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Practical1/src/nl/camilstaps/cs/graphs/Node.java (limited to 'Practical1/src/nl/camilstaps/cs/graphs/Node.java') 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 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 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); + } +} -- cgit v1.2.3