Skip to content

Commit

Permalink
Eliminate cyclic replacements to help PurityChecker accuracy
Browse files Browse the repository at this point in the history
Case study of cyclic replacement
sb.append(entry.getKey()) -> sb.append(entry.getKey()).append('=')
sb.append(entry.getKey()).append('=') -> sb.append(entry.getKey())

apache/hive@f664789
  • Loading branch information
tsantalis committed Dec 5, 2024
1 parent 80ec53a commit 4879d80
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,27 @@ public CompositeReplacement containsCompositeReplacement() {
}

public void addReplacement(Replacement replacement) {
this.replacements.add(replacement);
//eliminate cyclic replacements
Replacement toRemove = null;
for(Replacement r : replacements) {
if(r.getBefore().equals(replacement.getAfter()) && r.getAfter().equals(replacement.getBefore())) {
toRemove = r;
break;
}
}
if(toRemove != null) {
this.replacements.remove(toRemove);
}
else {
this.replacements.add(replacement);
}
}

public void addReplacements(Set<Replacement> replacements) {
if(replacements != null) {
this.replacements.addAll(replacements);
for(Replacement r : replacements) {
addReplacement(r);
}
}
else {
matchedWithNullReplacements = true;
Expand Down

0 comments on commit 4879d80

Please sign in to comment.