org.sonar.api.utils
Class KeyValueFormat

java.lang.Object
  extended by org.sonar.api.utils.KeyValueFormat

public final class KeyValueFormat
extends Object

Formats and parses key/value pairs with the string representation : "key1=value1;key2=value2". Conversion of fields is supported and can be extended.

This format can easily be parsed with Ruby code: hash=Hash[*(my_string.split(';').map { |elt| elt.split('=') }.flatten)]

Since:
1.10

Nested Class Summary
static class KeyValueFormat.Converter<T>
           
static class KeyValueFormat.DateConverter
           
static class KeyValueFormat.DateTimeConverter
          Deprecated. in version 2.13. Replaced by newDateTimeConverter()
static class KeyValueFormat.DoubleConverter
           
static class KeyValueFormat.DoubleNumbersPairTransformer
          Deprecated. since 2.7. Replaced by Converter
static class KeyValueFormat.IntegerConverter
           
static class KeyValueFormat.IntegerNumbersPairTransformer
          Deprecated. since 2.7. Replaced by Converter
static class KeyValueFormat.PriorityConverter
           
static class KeyValueFormat.RulePriorityNumbersPairTransformer
          Deprecated. since 2.7. Replaced by Converter
static class KeyValueFormat.StringConverter
           
static class KeyValueFormat.StringNumberPairTransformer
          Deprecated. since 2.7 replaced by Converter
static class KeyValueFormat.ToStringConverter
           
static interface KeyValueFormat.Transformer<K,V>
          Deprecated. since 2.7. Replaced by Converter
 
Field Summary
static String FIELD_SEPARATOR
           
static String PAIR_SEPARATOR
           
 
Method Summary
static String format(org.apache.commons.collections.Bag bag)
          Deprecated. use Multiset from google collections instead of commons-collections bags
static String format(org.apache.commons.collections.Bag bag, int var)
          Deprecated. use Multiset from google collections instead of commons-collections bags
static String format(Map map)
           
static
<K,V> String
format(Map<K,V> map, KeyValueFormat.Converter<K> keyConverter, KeyValueFormat.Converter<V> valueConverter)
           
static
<K,V> String
format(com.google.common.collect.Multimap<K,V> map, KeyValueFormat.Converter<K> keyConverter, KeyValueFormat.Converter<V> valueConverter)
          Limitation: there's currently no methods to parse into Multimap.
static String format(com.google.common.collect.Multiset multiset)
           
static
<K> String
format(com.google.common.collect.Multiset<K> multiset, KeyValueFormat.Converter<K> keyConverter)
           
static String formatIntDate(Map<Integer,Date> map)
           
static String formatIntDateTime(Map<Integer,Date> map)
           
static String formatIntDouble(Map<Integer,Double> map)
           
static String formatIntString(Map<Integer,String> map)
           
static String formatStringInt(Map<String,Integer> map)
           
static KeyValueFormat.DateConverter newDateConverter()
           
static KeyValueFormat.DateConverter newDateConverter(String format)
           
static KeyValueFormat.DateConverter newDateTimeConverter()
           
static KeyValueFormat.DoubleConverter newDoubleConverter()
           
static KeyValueFormat.IntegerConverter newIntegerConverter()
           
static KeyValueFormat.PriorityConverter newPriorityConverter()
           
static KeyValueFormat.StringConverter newStringConverter()
           
static KeyValueFormat.ToStringConverter newToStringConverter()
           
static Map<String,String> parse(String data)
           
static
<K,V> Map<K,V>
parse(String data, KeyValueFormat.Converter<K> keyConverter, KeyValueFormat.Converter<V> valueConverter)
           
static
<K,V> Map<K,V>
parse(String data, KeyValueFormat.Transformer<K,V> transformer)
          Deprecated. since 2.7
static Map<Integer,Date> parseIntDate(String data)
           
static Map<Integer,Date> parseIntDateTime(String data)
           
static Map<Integer,Double> parseIntDouble(String data)
           
static com.google.common.collect.Multiset<Integer> parseIntegerMultiset(String data)
           
static Map<Integer,Integer> parseIntInt(String data)
           
static Map<Integer,String> parseIntString(String data)
           
static com.google.common.collect.Multiset<String> parseMultiset(String data)
           
static
<K> com.google.common.collect.Multiset<K>
parseMultiset(String data, KeyValueFormat.Converter<K> keyConverter)
           
static Map<String,Double> parseStringDouble(String data)
           
static Map<String,Integer> parseStringInt(String data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAIR_SEPARATOR

public static final String PAIR_SEPARATOR
See Also:
Constant Field Values

FIELD_SEPARATOR

public static final String FIELD_SEPARATOR
See Also:
Constant Field Values
Method Detail

newStringConverter

public static KeyValueFormat.StringConverter newStringConverter()

newToStringConverter

public static KeyValueFormat.ToStringConverter newToStringConverter()

newIntegerConverter

public static KeyValueFormat.IntegerConverter newIntegerConverter()

newPriorityConverter

public static KeyValueFormat.PriorityConverter newPriorityConverter()

newDoubleConverter

public static KeyValueFormat.DoubleConverter newDoubleConverter()

newDateConverter

public static KeyValueFormat.DateConverter newDateConverter()

newDateTimeConverter

public static KeyValueFormat.DateConverter newDateTimeConverter()

newDateConverter

public static KeyValueFormat.DateConverter newDateConverter(String format)

parse

public static <K,V> Map<K,V> parse(String data,
                                   KeyValueFormat.Converter<K> keyConverter,
                                   KeyValueFormat.Converter<V> valueConverter)

parse

public static Map<String,String> parse(String data)

parseStringInt

public static Map<String,Integer> parseStringInt(String data)
Since:
2.7

parseStringDouble

public static Map<String,Double> parseStringDouble(String data)
Since:
2.7

parseIntString

public static Map<Integer,String> parseIntString(String data)
Since:
2.7

parseIntDouble

public static Map<Integer,Double> parseIntDouble(String data)
Since:
2.7

parseIntDate

public static Map<Integer,Date> parseIntDate(String data)
Since:
2.7

parseIntInt

public static Map<Integer,Integer> parseIntInt(String data)
Since:
2.7

parseIntDateTime

public static Map<Integer,Date> parseIntDateTime(String data)
Since:
2.7

parseMultiset

public static <K> com.google.common.collect.Multiset<K> parseMultiset(String data,
                                                                      KeyValueFormat.Converter<K> keyConverter)
Since:
2.7

parseIntegerMultiset

public static com.google.common.collect.Multiset<Integer> parseIntegerMultiset(String data)
Since:
2.7

parseMultiset

public static com.google.common.collect.Multiset<String> parseMultiset(String data)
Since:
2.7

parse

@Deprecated
public static <K,V> Map<K,V> parse(String data,
                                              KeyValueFormat.Transformer<K,V> transformer)
Deprecated. since 2.7

Transforms a string with the following format: "key1=value1;key2=value2..." into a Map. Requires to implement the transform(key,value) method

Parameters:
data - the input string
transformer - the interface to implement
Returns:
a Map of

format

public static <K,V> String format(Map<K,V> map,
                                  KeyValueFormat.Converter<K> keyConverter,
                                  KeyValueFormat.Converter<V> valueConverter)
Since:
2.7

format

public static String format(Map map)
Since:
2.7

formatIntString

public static String formatIntString(Map<Integer,String> map)
Since:
2.7

formatIntDouble

public static String formatIntDouble(Map<Integer,Double> map)
Since:
2.7

formatIntDate

public static String formatIntDate(Map<Integer,Date> map)
Since:
2.7

formatIntDateTime

public static String formatIntDateTime(Map<Integer,Date> map)
Since:
2.7

formatStringInt

public static String formatStringInt(Map<String,Integer> map)
Since:
2.7

format

public static <K,V> String format(com.google.common.collect.Multimap<K,V> map,
                                  KeyValueFormat.Converter<K> keyConverter,
                                  KeyValueFormat.Converter<V> valueConverter)
Limitation: there's currently no methods to parse into Multimap.

Since:
2.7

format

public static <K> String format(com.google.common.collect.Multiset<K> multiset,
                                KeyValueFormat.Converter<K> keyConverter)
Since:
2.7

format

public static String format(com.google.common.collect.Multiset multiset)

format

@Deprecated
public static String format(org.apache.commons.collections.Bag bag)
Deprecated. use Multiset from google collections instead of commons-collections bags

Since:
1.11

format

@Deprecated
public static String format(org.apache.commons.collections.Bag bag,
                                       int var)
Deprecated. use Multiset from google collections instead of commons-collections bags

Since:
1.11


Copyright © 2009-2013 SonarSource. All Rights Reserved.