}
private static boolean isNotEquals(int comparison, ResolvedCondition condition) {
- return condition.operator().equals("NE") && comparison == 0;
+ return "NE".equals(condition.operator()) && comparison == 0;
}
private static boolean isGreater(int comparison, ResolvedCondition condition) {
- return condition.operator().equals("GT") && comparison != 1;
+ return "GT".equals(condition.operator()) && comparison != 1;
}
private static boolean isSmaller(int comparison, ResolvedCondition condition) {
- return condition.operator().equals("LT") && comparison != -1;
+ return "LT".equals(condition.operator()) && comparison != -1;
}
private static boolean isEquals(int comparison, ResolvedCondition condition) {
- return condition.operator().equals("EQ") && comparison != 0;
+ return "EQ".equals(condition.operator()) && comparison != 0;
}
private static String getValueToEval(ResolvedCondition condition, Metric.Level alertLevel) {
*/
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
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;
}
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;
}
}
}
@Override
- public Component<?> findByKey(String key) {
+ public Component findByKey(String key) {
return resourceDao.findByKey(key);
}
result.addTags(optionalVarargs(params.get(PARAM_TAGS)));
}
+ parseInheritance(params, errors, result);
+
+ parseParams(params, errors, result);
+
+ if (!errors.isEmpty()) {
+ throw BadRequestException.of("Incorrect rule search parameters", errors);
+ } else {
+ result.profileId = RubyUtils.toInteger(params.get(PARAM_PROFILE_ID));
+ }
+ return result;
+ }
+
+ private static void parseInheritance(Map<String, Object> params, List<BadRequestException.Message> errors, ProfileRuleQuery result) {
if (params.containsKey(PARAM_INHERITANCE)) {
String inheritance = (String) params.get(PARAM_INHERITANCE);
validateInheritance(inheritance, errors);
} else {
result.setAnyInheritance(true);
}
+ }
+ private static void parseParams(Map<String, Object> params, List<BadRequestException.Message> errors, ProfileRuleQuery result) {
if (params.get(PARAM_SORT) != null) {
String sort = (String) params.get(PARAM_SORT);
Boolean asc = RubyUtils.toBoolean(params.get(PARAM_ASC));
result.setAsc(asc);
}
}
-
- if (!errors.isEmpty()) {
- throw BadRequestException.of("Incorrect rule search parameters", errors);
- } else {
- result.profileId = RubyUtils.toInteger(params.get(PARAM_PROFILE_ID));
- }
- return result;
}
private static void validatePresenceOf(Map<String, Object> params, List<BadRequestException.Message> errors, String... paramNames) {
* Define a task that will be executed using the highest privileges available. The privileged section is restricted
* to the execution of the {@link #doPrivileged()} method.
*/
- public static abstract class Task {
+ public abstract static class Task {
/**
* Code placed in this method will be executed in a privileged environment.