RuleBase: Streamline reading rules from config files
Inline one-time variables and extract some methods to improve code
readability.
Change-Id: I4887f21bc0b937a065f9a90a97f3d90032fee825
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
index 8dd0016..e1f6220 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
@@ -85,22 +85,14 @@
return;
}
- Collection<String> subsections = cfg.getSubsections(RULE_SECTION);
- for (String subsection : subsections) {
+ for (String subsection : cfg.getSubsections(RULE_SECTION)) {
Rule rule = ruleFactory.create(subsection);
- Collection<String> keys = cfg.getNames(RULE_SECTION, subsection);
- for (String key : keys) {
+ for (String key : cfg.getNames(RULE_SECTION, subsection)) {
String[] values = cfg.getStringList(RULE_SECTION, subsection, key);
if (ACTION_KEY.equals(key)) {
- for (String value : values) {
- ActionRequest actionRequest = actionRequestFactory.create(value);
- rule.addActionRequest(actionRequest);
- }
+ addActions(rule, values);
} else {
- for (String value : values) {
- Condition condition = conditionFactory.create(key, value);
- rule.addCondition(condition);
- }
+ addConditions(rule, key, values);
}
}
rules.add(rule);
@@ -108,6 +100,18 @@
}
}
+ private void addActions(Rule rule, String[] values) {
+ for (String value : values) {
+ rule.addActionRequest(actionRequestFactory.create(value));
+ }
+ }
+
+ private void addConditions(Rule rule, String key, String[] values) {
+ for (String value : values) {
+ rule.addCondition(conditionFactory.create(key, value));
+ }
+ }
+
/** Loads the rules for the RuleBase. */
private void reloadRules() {
rules = Lists.newArrayList();