Skip to content

Commit

Permalink
Merge pull request #22 from kniazkov/master
Browse files Browse the repository at this point in the history
Avoid suppressing the warning
  • Loading branch information
kniazkov authored Apr 10, 2024
2 parents ff96e33 + 47f5ca2 commit 5482f23
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/main/java/org/cqfn/astranaut/core/algorithms/Identical.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
*
* @since 1.1.5
*/
@SuppressWarnings("PMD.ConstructorShouldDoInitialization")
public class Identical {
/**
* The root of the tree to search in.
Expand All @@ -49,11 +48,6 @@ public class Identical {
*/
private final SimpleHash hashes;

/**
* The map of the calculated hashes and corresponding nodes.
*/
private final Map<Integer, Set<Node>> results = new HashMap<>();

/**
* Constructor.
*
Expand All @@ -70,8 +64,9 @@ public Identical(final Node root) {
* @return The set of sets with identical nodes.
*/
public Set<Set<Node>> get() {
this.search(this.root);
return this.results.values()
final Map<Integer, Set<Node>> result = new HashMap<>();
this.search(this.root, result);
return result.values()
.stream()
.filter(set -> set.size() >= 2)
.collect(Collectors.toSet());
Expand All @@ -82,16 +77,17 @@ public Set<Set<Node>> get() {
* adds entries to the resulting map.
*
* @param node The current node to process
* @param result Where to put the result
*/
private void search(final Node node) {
private void search(final Node node, final Map<Integer, Set<Node>> result) {
if (!node.getData().isEmpty()) {
this.results.computeIfAbsent(
result.computeIfAbsent(
this.hashes.calculate(node),
s -> new HashSet<>()
).add(node);
}
for (final Node child: node.getChildrenList()) {
this.search(child);
this.search(child, result);
}
}
}

0 comments on commit 5482f23

Please sign in to comment.