File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
src/main/java/com/datastructures Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 1818 */
1919public class DisjointSet <T > implements Serializable {
2020 private static final long serialVersionUID = 3134700471905625636L ;
21+ private static final String elementKey = "element" ;
2122
22- private Map <T , Node <T >> nodeMap = new HashMap <>();
23+ private final Map <T , Node <T >> nodeMap = new HashMap <>();
2324
2425 /**
2526 * Add an element to the disjoint-set forests as a set.
2627 */
2728 public void makeSet (T element ) {
28- checkNotNull (element , "element" );
29+ checkNotNull (element , elementKey );
2930 nodeMap .putIfAbsent (element , new Node <>());
3031 }
3132
@@ -36,8 +37,8 @@ public void makeSet(T element) {
3637 * Rank is an upper bound on the height of node.
3738 */
3839 public void union (T left , T right ) {
39- checkNotNull (left , "element" );
40- checkNotNull (right , "element" );
40+ checkNotNull (left , elementKey );
41+ checkNotNull (right , elementKey );
4142
4243 Node <T > leftNode = nodeMap .get (left ),
4344 rightNode = nodeMap .get (right );
You can’t perform that action at this time.
0 commit comments