Simplify logic leaving a subrule in ElementFrequenciesVisitor

This commit is contained in:
Sam Harwell 2017-01-04 11:46:47 -06:00
parent eb53e70e39
commit 9009a1b989
1 changed files with 10 additions and 8 deletions

View File

@ -183,11 +183,12 @@ public class ElementFrequenciesVisitor extends GrammarTreeVisitor {
for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) {
entry.getValue().v = 2;
}
}
int multiplier = tree.getType() == POSITIVE_CLOSURE ? 1 : 0;
for (Map.Entry<String, MutableInt> entry : minFrequencies.peek().entrySet()) {
entry.getValue().v *= multiplier;
}
if (tree.getType() == CLOSURE) {
// Everything inside a closure is optional, so the minimum
// number of occurrences for all elements is 0.
minFrequencies.peek().clear();
}
}
@ -225,11 +226,12 @@ public class ElementFrequenciesVisitor extends GrammarTreeVisitor {
for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) {
entry.getValue().v = 2;
}
}
int multiplier = tree.getType() == POSITIVE_CLOSURE ? 1 : 0;
for (Map.Entry<String, MutableInt> entry : minFrequencies.peek().entrySet()) {
entry.getValue().v *= multiplier;
}
if (tree.getType() == CLOSURE) {
// Everything inside a closure is optional, so the minimum
// number of occurrences for all elements is 0.
minFrequencies.peek().clear();
}
}
}