Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
starkda committed Apr 2, 2024
1 parent debef9d commit 39b8f2f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/org/jpeek/calculus/java/Ccm.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static Integer calculateComponents(final XML clazz, final Map<String, Ob
final String classpath = operation.nodes("name").get(0).node().getTextContent();
final List<String> splits = Arrays.asList(classpath.split("\\."));
if (parents.keySet().contains(splits.get(splits.size() - 1))) {
parents.put(name, splits.get(splits.size() - 1));
UnionFind.unite(name, splits.get(splits.size() - 1), parents);
}
} else {
final String var = operation.node().getTextContent();
Expand Down Expand Up @@ -239,9 +239,14 @@ private static Integer runUnionFind(final Map<String, String> parents,
*/
private static String getParent(final String node, final Map<String, String> parents) {
String ancestor = node;
if (!parents.get(ancestor).equals(ancestor)) {
ancestor = getParent(parents.get(ancestor), parents);
parents.put(node, ancestor);
while (!parents.get(ancestor).equals(ancestor)) {
ancestor = parents.get(ancestor);
}
String current = node;
while (!parents.get(current).equals(current)) {
final String temp = parents.get(current);
parents.put(current, ancestor);
current = temp;
}
return ancestor;
}
Expand Down

0 comments on commit 39b8f2f

Please sign in to comment.