}
}
+ public static final class ToStringConverter extends Converter<Object> {
+ static final ToStringConverter INSTANCE = new ToStringConverter();
+
+ private ToStringConverter() {
+ }
+
+ @Override
+ String format(Object o) {
+ return o.toString();
+ }
+
+ @Override
+ String parse(String s) {
+ throw new IllegalStateException("Can not parse with ToStringConverter: " + s);
+ }
+ }
+
public static final class IntegerConverter extends Converter<Integer> {
static final IntegerConverter INSTANCE = new IntegerConverter();
return map;
}
- public static Map<String, String> parse(String data) {
+ public static Map parse(String data) {
return parse(data, StringConverter.INSTANCE, StringConverter.INSTANCE);
}
/**
* @since 2.7
*/
- public static String format(Map<String, String> map) {
- return format(map, StringConverter.INSTANCE, StringConverter.INSTANCE);
+ public static String format(Map map) {
+ return format(map, ToStringConverter.INSTANCE, ToStringConverter.INSTANCE);
}
/**
}
- /**
- * Transforms a Object... into a string with the format : "object1=object2;object3=object4..."
- *
- * @param objects the object list to transform
- * @return the formatted string
- * @deprecated since 2.7 because there's not the inverse method to parse.
- */
- @Deprecated
- public static String format(Object... objects) {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- if (objects != null) {
- for (int i = 0; i < objects.length; i++) {
- if (!first) {
- sb.append(PAIR_SEPARATOR);
- }
- sb.append(objects[i++].toString());
- sb.append(FIELD_SEPARATOR);
- sb.append(objects[i]);
- first = false;
- }
- }
- return sb.toString();
- }
-
@Deprecated
public interface Transformer<KEY, VALUE> {
KeyValue<KEY, VALUE> transform(String key, String value);
import com.google.common.collect.Multiset;
import com.google.common.collect.TreeMultiset;
-import static junit.framework.Assert.assertEquals;
import org.apache.commons.collections.bag.TreeBag;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.sonar.api.rules.RulePriority;
import java.util.Map;
import java.util.TreeMap;
+import static junit.framework.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class DeprecatedKeyValueFormatTest {
@Test
assertThat(KeyValueFormat.format(set), is("hello=1;key=3"));
}
- @Test
- public void formatVarargs() {
- assertThat(KeyValueFormat.format("hello", 1, "key", 3), is("hello=1;key=3"));
- }
-
@Test
public void parse() {
Map<String, String> map = KeyValueFormat.parse("hello=world;key1=val1;key2=;key3=val3");