aboutsummaryrefslogtreecommitdiff
path: root/Practical1/src/nl/camilstaps/cs/graphs/Node.java
diff options
context:
space:
mode:
Diffstat (limited to 'Practical1/src/nl/camilstaps/cs/graphs/Node.java')
-rw-r--r--Practical1/src/nl/camilstaps/cs/graphs/Node.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/Practical1/src/nl/camilstaps/cs/graphs/Node.java b/Practical1/src/nl/camilstaps/cs/graphs/Node.java
index b9d078e..ccdbd4a 100644
--- a/Practical1/src/nl/camilstaps/cs/graphs/Node.java
+++ b/Practical1/src/nl/camilstaps/cs/graphs/Node.java
@@ -10,11 +10,11 @@ import java.util.stream.Collectors;
*
* @author Camil Staps
*/
-public class Node implements Comparable<Node> {
- private final int content;
- private final List<Node> neighbours = new ArrayList<>();
+public class Node<T> implements Comparable<Node<T>> {
+ private final T content;
+ private final List<Node<T>> neighbours = new ArrayList<>();
- public Node(int content) {
+ public Node(T content) {
this.content = content;
}
@@ -28,15 +28,15 @@ public class Node implements Comparable<Node> {
/**
* @return the neighbours
*/
- public List<Node> getNeighbourhood() {
+ public List<Node<T>> getNeighbourhood() {
return neighbours;
}
/**
* @return the neighbours with the Node itself
*/
- public List<Node> getInclusiveNeighbourhood() {
- List<Node> nb = new ArrayList<>();
+ public List<Node<T>> getInclusiveNeighbourhood() {
+ List<Node<T>> nb = new ArrayList<>();
nb.add(this);
nb.addAll(neighbours);
return nb;
@@ -45,10 +45,12 @@ public class Node implements Comparable<Node> {
/**
* @return the neighbours of the neighbours, without this Node itself
*/
- public List<Node> getSecondNeighbourhood() {
- List<Node> nb = new ArrayList<>();
- for (Node n : getNeighbourhood())
- n.getNeighbourhood().stream().filter(n2 -> !nb.contains(n2)).forEach(nb::add);
+ public List<Node<T>> getSecondNeighbourhood() {
+ List<Node<T>> nb = new ArrayList<>();
+ for (Node<T> n : getNeighbourhood())
+ for (Node<T> n2 : n.getNeighbourhood())
+ if (!nb.contains(n2))
+ nb.add(n2);
nb.remove(this);
return nb;
}
@@ -58,8 +60,8 @@ public class Node implements Comparable<Node> {
* @param b the Node to compare to
* @return true iff this Node dominates Node b
*/
- public boolean dominates(Node b) {
- for (Node nb : getInclusiveNeighbourhood())
+ public boolean dominates(Node<T> b) {
+ for (Node<T> nb : getInclusiveNeighbourhood())
if (!b.getInclusiveNeighbourhood().contains(nb))
return false;
return true;
@@ -69,7 +71,7 @@ public class Node implements Comparable<Node> {
* @param b the Node to compare to
* @return true iff the neighbourhood of this Node is disjoint with the neighbourhood of Node b
*/
- public boolean neighbourhoodsDisjoint(Node b) {
+ public boolean neighbourhoodsDisjoint(Node<T> b) {
return neighbourhoodIntersection(b).isEmpty();
}
@@ -77,7 +79,7 @@ public class Node implements Comparable<Node> {
* @param b another Node
* @return the intersection of the neighbourhood of this Node and the neighbourhood of Node b
*/
- public List<Node> neighbourhoodIntersection(Node b) {
+ public List<Node<T>> neighbourhoodIntersection(Node<T> b) {
return neighbours.stream().filter(n -> b.getNeighbourhood().contains(n)).collect(Collectors.toList());
}
@@ -105,7 +107,7 @@ public class Node implements Comparable<Node> {
*/
@Override
@SuppressWarnings("NullableProblems")
- public int compareTo(Node b) {
+ public int compareTo(Node<T> b) {
return Integer.compare(neighbours.size(), b.neighbours.size());
}
}