diff --git a/src/main/java/com/datastructures/DisjointSet.java b/src/main/java/com/datastructures/DisjointSet.java index 0e3118f1..281bbf16 100644 --- a/src/main/java/com/datastructures/DisjointSet.java +++ b/src/main/java/com/datastructures/DisjointSet.java @@ -18,14 +18,15 @@ import java.util.*; */ public class DisjointSet implements Serializable { private static final long serialVersionUID = 3134700471905625636L; + private static final String elementKey = "element"; - private Map> nodeMap = new HashMap<>(); + private final Map> nodeMap = new HashMap<>(); /** * Add an element to the disjoint-set forests as a set. */ public void makeSet(T element) { - checkNotNull(element, "element"); + checkNotNull(element, elementKey); nodeMap.putIfAbsent(element, new Node<>()); } @@ -36,8 +37,8 @@ public class DisjointSet implements Serializable { * Rank is an upper bound on the height of node. */ public void union(T left, T right) { - checkNotNull(left, "element"); - checkNotNull(right, "element"); + checkNotNull(left, elementKey); + checkNotNull(right, elementKey); Node leftNode = nodeMap.get(left), rightNode = nodeMap.get(right);