public final class KeyValueFormat extends Object
Formats and parses key/value pairs with the text representation : "key1=value1;key2=value2". Field typing is supported, to make conversion from/to primitive types easier for example.
Since version 4.5.1, text keys and values are escaped if they contain the separator characters '=' or ';'. Parsing examplesMap<String,String> mapOfStrings = KeyValueFormat.parse("hello=world;foo=bar"); Map<String,Integer> mapOfStringInts = KeyValueFormat.parseStringInt("one=1;two=2"); Map<Integer,String> mapOfIntStrings = KeyValueFormat.parseIntString("1=one;2=two"); Map<String,Date> mapOfStringDates = KeyValueFormat.parseStringDate("d1=2014-01-14;d2=2015-07-28"); // custom conversion Map<String,MyClass> mapOfStringMyClass = KeyValueFormat.parse("foo=xxx;bar=yyy", KeyValueFormat.newStringConverter(), new MyClassConverter());Formatting examples
String output = KeyValueFormat.format(map); Map<Integer,String> mapIntString; KeyValueFormat.formatIntString(mapIntString);
Modifier and Type | Class and Description |
---|---|
static class |
KeyValueFormat.Converter<T> |
static class |
KeyValueFormat.DateConverter |
static class |
KeyValueFormat.DoubleConverter |
static class |
KeyValueFormat.IntegerConverter |
static class |
KeyValueFormat.PriorityConverter |
static class |
KeyValueFormat.StringConverter |
static class |
KeyValueFormat.ToStringConverter |
Modifier and Type | Field and Description |
---|---|
static String |
FIELD_SEPARATOR |
static String |
PAIR_SEPARATOR |
public static final String PAIR_SEPARATOR
public static final String FIELD_SEPARATOR
public static KeyValueFormat.StringConverter newStringConverter()
public static KeyValueFormat.ToStringConverter newToStringConverter()
public static KeyValueFormat.IntegerConverter newIntegerConverter()
public static KeyValueFormat.PriorityConverter newPriorityConverter()
public static KeyValueFormat.DoubleConverter newDoubleConverter()
public static KeyValueFormat.DateConverter newDateConverter()
public static KeyValueFormat.DateConverter newDateTimeConverter()
public static KeyValueFormat.DateConverter newDateConverter(String format)
public static <K,V> Map<K,V> parse(@Nullable String input, KeyValueFormat.Converter<K> keyConverter, KeyValueFormat.Converter<V> valueConverter)
public static Map<String,Double> parseStringDouble(@Nullable String data)
public static <K,V> String format(Map<K,V> map, KeyValueFormat.Converter<K> keyConverter, KeyValueFormat.Converter<V> valueConverter)
public static String formatIntString(Map<Integer,String> map)
public static String formatIntDouble(Map<Integer,Double> map)
public static String formatIntDate(Map<Integer,Date> map)
public static String formatIntDateTime(Map<Integer,Date> map)
public static String formatStringInt(Map<String,Integer> map)
@Deprecated public static String format(org.apache.commons.collections.Bag bag, int var)
Copyright © 2009–2015 SonarSource. All rights reserved.