]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6370 remove support of KeyValueFormat#format(Multiset)
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 1 Jun 2015 20:39:15 +0000 (22:39 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 5 Jun 2015 07:54:04 +0000 (09:54 +0200)
guava is not exposed in API

sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java

index c2a619e2108e9cc7264c76344eff2d723b5cd60a..2d8e71f54915fc16ab9db452440b3f1da4264d71 100644 (file)
  */
 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
    */
@@ -459,17 +440,6 @@ public final class KeyValueFormat {
     return format(map, newStringConverter(), newIntegerConverter());
   }
 
-  /**
-   * @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
index 87ef606ba0fa3edd8f428673fce00ad16b021025..c6421e53069b169b49e03df1a780469f10cabad9 100644 (file)
 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);
@@ -220,18 +215,9 @@ public class KeyValueFormatTest {
     assertThat(KeyValueFormat.newPriorityConverter().parse("")).isNull();
   }
 
-  @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");
   }
 
 }