Decoupled normalize() from fromConfig()
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java
index 798912e..3fec0c5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java
@@ -122,6 +122,7 @@
} else {
Sections.fromConfig(section, cfg);
}
+ Sections.normalize(section);
}
return true;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java
index f5aef6c..263f8ba 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java
@@ -104,20 +104,6 @@
f.set(section, new Boolean(config.getBoolean(getName(section), null, f.getName(), false)));
}
}
- if (f.getType() == Integer.class && f.isAnnotationPresent(Limit.class)) {
- Object obj = f.get(section);
- if (obj != null) {
- Integer val = Integer.class.cast(obj);
- Limit a = f.getAnnotation(Limit.class);
- if (a.min() != -1 && val < a.min()) {
- val = a.min();
- }
- if (a.max() != -1 && val > a.max()) {
- val = a.max();
- }
- f.set(section, val);
- }
- }
} catch (Exception ex) {
LOGGER.warn("Exception during fromConfig: {}", f.getName());
}
@@ -126,4 +112,30 @@
}
return section;
}
+
+ public static final <T extends Section> T normalize(T section) {
+ Field[] fs = section.getClass().getFields();
+ for (Field f : fs) {
+ try {
+ if (f.getType() == Integer.class && f.isAnnotationPresent(Limit.class)) {
+ Object obj = f.get(section);
+ if (obj != null) {
+ Integer val = Integer.class.cast(obj);
+ Limit a = f.getAnnotation(Limit.class);
+ if (a.min() != -1 && val < a.min()) {
+ val = a.min();
+ }
+ if (a.max() != -1 && val > a.max()) {
+ val = a.max();
+ }
+ f.set(section, val);
+ }
+ }
+ } catch (Exception ex) {
+ LOGGER.warn("Exception during normalize: {}", f.getName());
+ LOGGER.info("{}", ex.getMessage());
+ }
+ }
+ return section;
+ }
}