From: Simon Brandhof Date: Mon, 20 Oct 2014 20:55:41 +0000 (+0200) Subject: Add missing @Nullable to KeyValueFormat X-Git-Tag: 4.5.1-RC1~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ae047d2a0e77c09a1f183ae052588ed0cf7cfe3b;p=sonarqube.git Add missing @Nullable to KeyValueFormat --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java index 6319effa84d..0a90ae1c53f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java @@ -28,6 +28,8 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.sonar.api.rules.RulePriority; +import javax.annotation.Nullable; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collection; @@ -56,6 +58,10 @@ public final class KeyValueFormat { abstract String format(T type); abstract T parse(String s); + + boolean requiresEscaping() { + return false; + } } public static final class StringConverter extends Converter { @@ -73,6 +79,33 @@ public final class KeyValueFormat { String parse(String s) { return s; } + + @Override + boolean requiresEscaping() { + return true; + } + } + + public static final class UnescapedStringConverter extends Converter { + private static final UnescapedStringConverter INSTANCE = new UnescapedStringConverter(); + + private UnescapedStringConverter() { + } + + @Override + String format(String s) { + return s; + } + + @Override + String parse(String s) { + return s; + } + + @Override + boolean requiresEscaping() { + return false; + } } public static StringConverter newStringConverter() { @@ -94,6 +127,11 @@ public final class KeyValueFormat { String parse(String s) { throw new IllegalStateException("Can not parse with ToStringConverter: " + s); } + + @Override + boolean requiresEscaping() { + return true; + } } public static ToStringConverter newToStringConverter() { @@ -205,7 +243,7 @@ public final class KeyValueFormat { return new DateConverter(format); } - public static Map parse(String data, Converter keyConverter, Converter valueConverter) { + public static Map parse(@Nullable String data, Converter keyConverter, Converter valueConverter) { Map map = Maps.newLinkedHashMap(); if (data != null) { String[] pairs = StringUtils.split(data, PAIR_SEPARATOR); @@ -219,56 +257,56 @@ public final class KeyValueFormat { return map; } - public static Map parse(String data) { + public static Map parse(@Nullable String data) { return parse(data, newStringConverter(), newStringConverter()); } /** * @since 2.7 */ - public static Map parseStringInt(String data) { + public static Map parseStringInt(@Nullable String data) { return parse(data, newStringConverter(), newIntegerConverter()); } /** * @since 2.7 */ - public static Map parseStringDouble(String data) { + public static Map parseStringDouble(@Nullable String data) { return parse(data, newStringConverter(), newDoubleConverter()); } /** * @since 2.7 */ - public static Map parseIntString(String data) { + public static Map parseIntString(@Nullable String data) { return parse(data, newIntegerConverter(), newStringConverter()); } /** * @since 2.7 */ - public static Map parseIntDouble(String data) { + public static Map parseIntDouble(@Nullable String data) { return parse(data, newIntegerConverter(), newDoubleConverter()); } /** * @since 2.7 */ - public static Map parseIntDate(String data) { + public static Map parseIntDate(@Nullable String data) { return parse(data, newIntegerConverter(), newDateConverter()); } /** * @since 2.7 */ - public static Map parseIntInt(String data) { + public static Map parseIntInt(@Nullable String data) { return parse(data, newIntegerConverter(), newIntegerConverter()); } /** * @since 2.7 */ - public static Map parseIntDateTime(String data) { + public static Map parseIntDateTime(@Nullable String data) { return parse(data, newIntegerConverter(), newDateTimeConverter()); } @@ -279,7 +317,7 @@ public final class KeyValueFormat { /** * @since 2.7 */ - public static Multiset parseMultiset(String data, Converter keyConverter) { + public static Multiset parseMultiset(@Nullable String data, Converter keyConverter) { // to keep the same order Multiset multiset = LinkedHashMultiset.create(); if (data != null) { @@ -298,14 +336,14 @@ public final class KeyValueFormat { /** * @since 2.7 */ - public static Multiset parseIntegerMultiset(String data) { + public static Multiset parseIntegerMultiset(@Nullable String data) { return parseMultiset(data, newIntegerConverter()); } /** * @since 2.7 */ - public static Multiset parseMultiset(String data) { + public static Multiset parseMultiset(@Nullable String data) { return parseMultiset(data, newStringConverter()); }