diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-11 12:08:54 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-11 12:08:54 +0200 |
commit | cbeacdfd2deca921a2f8c5b6663d2c701963faa7 (patch) | |
tree | e78a49a4b2d6db163650375adf21fd95f8b3790f /sonar-plugin-api/src/main/java/org/sonar/api/config | |
parent | 8f7d6c7378e522c643d1e6bc6cacaf078763c749 (diff) | |
download | sonarqube-cbeacdfd2deca921a2f8c5b6663d2c701963faa7.tar.gz sonarqube-cbeacdfd2deca921a2f8c5b6663d2c701963faa7.zip |
Fix quality flaws
Diffstat (limited to 'sonar-plugin-api/src/main/java/org/sonar/api/config')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index d1a7836d689..038c7182c20 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -32,6 +32,7 @@ import org.sonar.api.ServerExtension; import org.sonar.api.resources.Qualifiers; import javax.annotation.Nullable; + import java.util.Arrays; import java.util.List; @@ -144,28 +145,41 @@ public final class PropertyDefinition implements BatchExtension, ServerExtension public static Result validate(PropertyType type, @Nullable String value, List<String> options) { if (StringUtils.isNotBlank(value)) { if (type == PropertyType.BOOLEAN) { - if (!StringUtils.equalsIgnoreCase(value, "true") && !StringUtils.equalsIgnoreCase(value, "false")) { - return Result.newError("notBoolean"); - } + return validateBoolean(value); } else if (type == PropertyType.INTEGER) { - if (!NumberUtils.isDigits(value)) { - return Result.newError("notInteger"); - } + return validateInteger(value); } else if (type == PropertyType.FLOAT) { - try { - Double.parseDouble(value); - } catch (NumberFormatException e) { - return Result.newError("notFloat"); - } - } else if (type == PropertyType.SINGLE_SELECT_LIST) { - if (!options.contains(value)) { - return Result.newError("notInOptions"); - } + return validateFloat(value); + } else if (type == PropertyType.SINGLE_SELECT_LIST && !options.contains(value)) { + return Result.newError("notInOptions"); } } return Result.SUCCESS; } + private static Result validateBoolean(@Nullable String value) { + if (!StringUtils.equalsIgnoreCase(value, "true") && !StringUtils.equalsIgnoreCase(value, "false")) { + return Result.newError("notBoolean"); + } + return Result.SUCCESS; + } + + private static Result validateInteger(@Nullable String value) { + if (!NumberUtils.isDigits(value)) { + return Result.newError("notInteger"); + } + return Result.SUCCESS; + } + + private static Result validateFloat(@Nullable String value) { + try { + Double.parseDouble(value); + return Result.SUCCESS; + } catch (NumberFormatException e) { + return Result.newError("notFloat"); + } + } + public Result validate(@Nullable String value) { return validate(type, value, options); } |