Skip to content

Commit 57c1967

Browse files
committed
Added constant for string literal - code smell
String literals should not be duplicated https://rules.sonarsource.com/java/RSPEC-1192
1 parent 7fbf8f2 commit 57c1967

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/com/datastructures/DisjointSet.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
*/
1919
public 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);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy