]> source.dussan.org Git - sonarqube.git/commitdiff
Decreased complexity
authorJulien Lancelot <julien.lancelot@gmail.com>
Mon, 10 Dec 2012 14:25:31 +0000 (15:25 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Mon, 10 Dec 2012 14:25:44 +0000 (15:25 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java

index 5fbd604e235ac1dd261db6695409087f7ab8358c..d56f275ffc4ef7396640248ed5c4eee1d70572a5 100644 (file)
@@ -96,7 +96,7 @@ public final class AlertUtils {
       return Double.parseDouble(value);
     }
     if (isAInteger(metric)) {
-      return value.contains(".") ? Integer.parseInt(value.substring(0, value.indexOf('.'))) : Integer.parseInt(value);
+      return parseInteger(value);
     }
     if (isAString(metric)) {
       return value;
@@ -107,14 +107,17 @@ public final class AlertUtils {
     throw new NotImplementedException(metric.getType().toString());
   }
 
+  private static Comparable<?> parseInteger(String value){
+    return value.contains(".") ? Integer.parseInt(value.substring(0, value.indexOf('.'))) : Integer.parseInt(value);
+  }
+
   private static Comparable<?> getMeasureValue(Alert alert, Measure measure) {
     Metric metric = alert.getMetric();
     if (isADouble(metric)) {
       return getValue(alert, measure);
     }
     if (isAInteger(metric)) {
-      Double value = getValue(alert, measure);
-      return value != null ? value.intValue() : null;
+      parseInteger(alert, measure);
     }
     if (alert.getPeriod() == null) {
       if (isAString(metric)) {
@@ -127,6 +130,11 @@ public final class AlertUtils {
     throw new NotImplementedException(metric.getType().toString());
   }
 
+  private static Comparable<?> parseInteger(Alert alert, Measure measure){
+    Double value = getValue(alert, measure);
+    return value != null ? value.intValue() : null;
+  }
+
   private static boolean isADouble(Metric metric){
     return metric.getType() == Metric.ValueType.FLOAT ||
         metric.getType() == Metric.ValueType.PERCENT ||