diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-06-01 22:39:15 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-06-05 09:54:04 +0200 |
commit | b68a5b1d5d3abd578f4efccbcc57620247a83f2f (patch) | |
tree | 376f25720037f042e403d7c5eebb1633b3f5ffd3 | |
parent | 0956511c8c9d6aa6639d4378f47d73877cdc18de (diff) | |
download | sonarqube-b68a5b1d5d3abd578f4efccbcc57620247a83f2f.tar.gz sonarqube-b68a5b1d5d3abd578f4efccbcc57620247a83f2f.zip |
SONAR-6370 remove support of KeyValueFormat#format(Multiset)
guava is not exposed in API
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java | 46 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java | 52 |
2 files changed, 23 insertions, 75 deletions
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 c2a619e2108..2d8e71f5491 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 @@ -19,22 +19,18 @@ */ package org.sonar.api.utils; -import com.google.common.collect.Maps; -import com.google.common.collect.Multiset; -import org.apache.commons.collections.Bag; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.math.NumberUtils; -import org.sonar.api.rules.RulePriority; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; +import java.util.LinkedHashMap; import java.util.Map; -import java.util.Set; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.apache.commons.collections.Bag; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.math.NumberUtils; +import org.sonar.api.rules.RulePriority; /** * <p>Formats and parses key/value pairs with the text representation : "key1=value1;key2=value2". Field typing @@ -308,7 +304,7 @@ public final class KeyValueFormat { * If input is null, then an empty map is returned. */ public static <K, V> Map<K, V> parse(@Nullable String input, Converter<K> keyConverter, Converter<V> valueConverter) { - Map<K, V> map = Maps.newLinkedHashMap(); + Map<K, V> map = new LinkedHashMap<>(); if (input != null) { FieldParser reader = new FieldParser(input); boolean end = false; @@ -395,21 +391,6 @@ public final class KeyValueFormat { return sb.toString(); } - private static <K> String formatEntries(Set<Multiset.Entry<K>> entries, Converter<K> keyConverter) { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Multiset.Entry<K> entry : entries) { - if (!first) { - sb.append(PAIR_SEPARATOR); - } - sb.append(keyConverter.format(entry.getElement())); - sb.append(FIELD_SEPARATOR); - sb.append(newIntegerConverter().format(entry.getCount())); - first = false; - } - return sb.toString(); - } - /** * @since 2.7 */ @@ -460,17 +441,6 @@ public final class KeyValueFormat { } /** - * @since 2.7 - */ - public static <K> String format(Multiset<K> multiset, Converter<K> keyConverter) { - return formatEntries(multiset.entrySet(), keyConverter); - } - - public static String format(Multiset multiset) { - return format(multiset, newToStringConverter()); - } - - /** * @since 1.11 * @deprecated use Multiset from google collections instead of commons-collections bags */ diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java index 87ef606ba0f..c6421e53069 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java @@ -20,24 +20,19 @@ package org.sonar.api.utils; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.LinkedHashMultiset; -import com.google.common.collect.Maps; -import com.google.common.collect.Multiset; -import com.google.common.collect.TreeMultiset; -import org.apache.commons.collections.bag.TreeBag; -import org.junit.Assert; -import org.junit.Test; -import org.sonar.api.rules.RulePriority; -import org.sonar.test.TestUtils; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.TreeMap; +import org.apache.commons.collections.bag.TreeBag; +import org.junit.Test; +import org.sonar.api.rules.RulePriority; +import org.sonar.test.TestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -import static org.hamcrest.Matchers.is; public class KeyValueFormatTest { @@ -107,7 +102,7 @@ public class KeyValueFormatTest { @Test public void keep_order_of_linked_map() { - Map<String, String> map = Maps.newLinkedHashMap(); + Map<String, String> map = new LinkedHashMap<>(); map.put("lucky", "luke"); map.put("aste", "rix"); String s = KeyValueFormat.format(map); @@ -116,7 +111,7 @@ public class KeyValueFormatTest { @Test public void shouldFormatMapOfIntegerString() { - Map<Integer, String> map = Maps.newLinkedHashMap(); + Map<Integer, String> map = new LinkedHashMap<>(); map.put(3, "three"); map.put(5, "five"); String s = KeyValueFormat.formatIntString(map); @@ -125,7 +120,7 @@ public class KeyValueFormatTest { @Test public void shouldFormatMapOfIntDouble() { - Map<Integer, Double> map = Maps.newLinkedHashMap(); + Map<Integer, Double> map = new LinkedHashMap<>(); map.put(13, 2.0); map.put(5, 5.75); String s = KeyValueFormat.formatIntDouble(map); @@ -134,7 +129,7 @@ public class KeyValueFormatTest { @Test public void shouldSetEmptyFieldWhenNullValue() { - Map<Integer, Double> map = Maps.newLinkedHashMap(); + Map<Integer, Double> map = new LinkedHashMap<>(); map.put(13, null); map.put(5, 5.75); String s = KeyValueFormat.formatIntDouble(map); @@ -143,14 +138,14 @@ public class KeyValueFormatTest { @Test public void shouldFormatBlank() { - Map<Integer, String> map = Maps.newTreeMap(); + Map<Integer, String> map = new TreeMap<>(); String s = KeyValueFormat.formatIntString(map); assertThat(s).isEqualTo(""); } @Test public void shouldFormatDate() throws ParseException { - Map<Integer, Date> map = Maps.newLinkedHashMap(); + Map<Integer, Date> map = new LinkedHashMap<>(); map.put(4, new SimpleDateFormat("yyyy-MM-dd").parse("2010-12-25")); map.put(20, new SimpleDateFormat("yyyy-MM-dd").parse("2009-05-28")); map.put(12, null); @@ -221,17 +216,8 @@ public class KeyValueFormatTest { } @Test - public void format_multiset() { - Multiset<String> set = LinkedHashMultiset.create(); - set.add("foo"); - set.add("foo"); - set.add("bar"); - assertThat(KeyValueFormat.format(set)).isEqualTo("foo=2;bar=1"); - } - - @Test public void escape_strings() { - Map<String, String> input = Maps.newLinkedHashMap(); + Map<String, String> input = new LinkedHashMap<>(); input.put("foo", "a=b=c"); input.put("bar", "a;b;c"); input.put("baz", "double\"quote"); @@ -255,7 +241,7 @@ public class KeyValueFormatTest { TreeBag bag = new TreeBag(); bag.add("hello", 1); bag.add("key", 3); - Assert.assertThat(KeyValueFormat.format(bag, 0), is("hello=1;key=3")); + assertThat(KeyValueFormat.format(bag, 0)).isEqualTo("hello=1;key=3"); } @Test @@ -263,15 +249,7 @@ public class KeyValueFormatTest { TreeBag bag = new TreeBag(); bag.add("hello", 1); bag.add("key", 3); - Assert.assertThat(KeyValueFormat.format(bag, -1), is("hello=0;key=2")); - } - - @Test - public void formatMultiset() { - Multiset<String> set = TreeMultiset.create(); - set.add("hello", 1); - set.add("key", 3); - Assert.assertThat(KeyValueFormat.format(set), is("hello=1;key=3")); + assertThat(KeyValueFormat.format(bag, -1)).isEqualTo("hello=0;key=2"); } } |