forked from rampatra/Algorithms-and-Data-Structures-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphNode.java
37 lines (30 loc) · 979 Bytes
/
GraphNode.java
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
package com.rampatra.base;
import java.util.HashSet;
import java.util.Set;
/**
* The class for a node in a graph. Ideally, you should make member variable {@code private} and have
* getters, setters, etc. but to keep it simple, I have omitted all those boilerplate code.
*
* @author rampatra
* @since 2019-02-10
*/
public class GraphNode<E extends Comparable<E>> {
public E value;
public Set<GraphNode<E>> adjacentNodes = new HashSet<>();
public GraphNode(E value) {
this(value, null);
}
public GraphNode(E value, Set<GraphNode<E>> adjacentNodes) {
this.value = value;
if (adjacentNodes != null) {
this.adjacentNodes = adjacentNodes;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GraphNode<?> graphNode = (GraphNode<?>) o;
return value.equals(graphNode.value);
}
}