From f09252799644be3b7bb3a852b926386df0c24936 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 6 Dec 2012 16:15:10 +0100 Subject: [PATCH] Fix some quality flaws --- .../sonar/plugins/core/sensors/AlertUtils.java | 15 +++++++++------ .../java/org/sonar/core/timemachine/Periods.java | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java index 5d5e6c89a2c..95951013333 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java @@ -52,16 +52,19 @@ public final class AlertUtils { Comparable criteriaValue = getValueForComparison(alert.getMetric(), valueToEval); Comparable measureValue = getMeasureValue(alert, measure); if (measureValue != null) { - int comparison = measureValue.compareTo(criteriaValue); - return !(// NOSONAR complexity of this boolean expression is under control - (alert.isNotEqualsOperator() && comparison == 0) - || (alert.isGreaterOperator() && comparison != 1) - || (alert.isSmallerOperator() && comparison != -1) - || (alert.isEqualsOperator() && comparison != 0)); + return doesReachThresholds(measureValue, criteriaValue, alert); } return false; } + private static boolean doesReachThresholds(Comparable measureValue, Comparable criteriaValue, Alert alert){ + int comparison = measureValue.compareTo(criteriaValue); + return !((alert.isNotEqualsOperator() && comparison == 0) + || (alert.isGreaterOperator() && comparison != 1) + || (alert.isSmallerOperator() && comparison != -1) + || (alert.isEqualsOperator() && comparison != 0)); + } + private static String getValueToEval(Alert alert, Metric.Level alertLevel) { if (alertLevel.equals(Metric.Level.ERROR)) { return alert.getValueError(); diff --git a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java index 4d1c34ace3a..5c244bef19d 100644 --- a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java @@ -100,7 +100,7 @@ public class Periods implements BatchExtension { return Locale.ENGLISH; } - private class PeriodParameters { + private static class PeriodParameters { private String mode; private String param; -- 2.39.5