From: Simon Brandhof Date: Mon, 1 Jun 2015 20:39:15 +0000 (+0200) Subject: SONAR-6370 remove support of KeyValueFormat#format(Multiset) X-Git-Tag: 5.2-RC1~1619 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b68a5b1d5d3abd578f4efccbcc57620247a83f2f;p=sonarqube.git SONAR-6370 remove support of KeyValueFormat#format(Multiset) guava is not exposed in API --- 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; /** *

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 Map parse(@Nullable String input, Converter keyConverter, Converter valueConverter) { - Map map = Maps.newLinkedHashMap(); + Map 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 String formatEntries(Set> entries, Converter keyConverter) { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Multiset.Entry 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 */ @@ -459,17 +440,6 @@ public final class KeyValueFormat { return format(map, newStringConverter(), newIntegerConverter()); } - /** - * @since 2.7 - */ - public static String format(Multiset multiset, Converter 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 map = Maps.newLinkedHashMap(); + Map 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 map = Maps.newLinkedHashMap(); + Map 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 map = Maps.newLinkedHashMap(); + Map 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 map = Maps.newLinkedHashMap(); + Map 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 map = Maps.newTreeMap(); + Map map = new TreeMap<>(); String s = KeyValueFormat.formatIntString(map); assertThat(s).isEqualTo(""); } @Test public void shouldFormatDate() throws ParseException { - Map map = Maps.newLinkedHashMap(); + Map 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); @@ -220,18 +215,9 @@ public class KeyValueFormatTest { assertThat(KeyValueFormat.newPriorityConverter().parse("")).isNull(); } - @Test - public void format_multiset() { - Multiset 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 input = Maps.newLinkedHashMap(); + Map 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 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"); } }