diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-10 17:11:32 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-10 17:11:40 +0200 |
commit | 18fbb41d409fa4b58e298de2d30581d8e1f4a3a8 (patch) | |
tree | 8da95c31da78c25c76e8cf2fc3fb60d11ef71dd9 /sonar-core | |
parent | 0714ae86a68f3230d1819ff02f2e26eb31e114fe (diff) | |
download | sonarqube-18fbb41d409fa4b58e298de2d30581d8e1f4a3a8.tar.gz sonarqube-18fbb41d409fa4b58e298de2d30581d8e1f4a3a8.zip |
Fix quality flaws
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java b/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java index a64d43af0c8..819d271350a 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java +++ b/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java @@ -19,16 +19,15 @@ */ package org.sonar.core.qualitygate.db; +import com.google.common.collect.ImmutableMap; + import com.google.common.collect.ImmutableList; import org.sonar.api.measures.Metric.ValueType; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; +import java.util.*; /** * @since 4.3 @@ -63,6 +62,18 @@ public class QualityGateConditionDto { OPERATOR_EQUALS ); + private static final Map<ValueType, List<String>> OPERATORS_BY_TYPE = ImmutableMap.<ValueType, List<String>>builder() + .put(ValueType.BOOL, BOOLEAN_OPERATORS) + .put(ValueType.LEVEL, LEVEL_OPERATORS) + .put(ValueType.STRING, STRING_OPERATORS) + .put(ValueType.INT, NUMERIC_OPERATORS) + .put(ValueType.FLOAT, NUMERIC_OPERATORS) + .put(ValueType.PERCENT, NUMERIC_OPERATORS) + .put(ValueType.MILLISEC, NUMERIC_OPERATORS) + .put(ValueType.RATING, NUMERIC_OPERATORS) + .put(ValueType.WORK_DUR, NUMERIC_OPERATORS) + .build(); + private long id; private long qualityGateId; @@ -180,30 +191,10 @@ public class QualityGateConditionDto { } public static Collection<String> getOperatorsForType(ValueType metricType) { - Collection<String> operators = Collections.emptySet(); - if (metricType != null) { - switch(metricType) { - case BOOL: - operators = BOOLEAN_OPERATORS; - break; - case LEVEL: - operators = LEVEL_OPERATORS; - break; - case STRING: - operators = STRING_OPERATORS; - break; - case INT: - case FLOAT: - case PERCENT: - case MILLISEC: - case RATING: - case WORK_DUR: - operators = NUMERIC_OPERATORS; - break; - default: - operators = Collections.emptySet(); - } + if (OPERATORS_BY_TYPE.containsKey(metricType)) { + return OPERATORS_BY_TYPE.get(metricType); + } else { + return Collections.emptySet(); } - return operators; } } |