Class KeyValueFormat


  • public final class KeyValueFormat
    extends java.lang.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 examples

       Map<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);
     
    Since:
    1.10
    • Method Detail

      • parse

        public static java.util.Map<java.lang.String,​java.lang.String> parse​(@Nullable
                                                                                   java.lang.String data)
      • parseStringInt

        public static java.util.Map<java.lang.String,​java.lang.Integer> parseStringInt​(@Nullable
                                                                                             java.lang.String data)
        Since:
        2.7
      • parseStringDouble

        public static java.util.Map<java.lang.String,​java.lang.Double> parseStringDouble​(@Nullable
                                                                                               java.lang.String data)
        Since:
        2.7
      • parseIntString

        public static java.util.Map<java.lang.Integer,​java.lang.String> parseIntString​(@Nullable
                                                                                             java.lang.String data)
        Since:
        2.7
      • parseIntDouble

        public static java.util.Map<java.lang.Integer,​java.lang.Double> parseIntDouble​(@Nullable
                                                                                             java.lang.String data)
        Since:
        2.7
      • parseIntDate

        public static java.util.Map<java.lang.Integer,​java.util.Date> parseIntDate​(@Nullable
                                                                                         java.lang.String data)
        Since:
        2.7
      • parseIntInt

        public static java.util.Map<java.lang.Integer,​java.lang.Integer> parseIntInt​(@Nullable
                                                                                           java.lang.String data)
        Since:
        2.7
      • parseIntDateTime

        public static java.util.Map<java.lang.Integer,​java.util.Date> parseIntDateTime​(@Nullable
                                                                                             java.lang.String data)
        Since:
        2.7
      • format

        public static java.lang.String format​(java.util.Map map)
        Since:
        2.7
      • formatIntString

        public static java.lang.String formatIntString​(java.util.Map<java.lang.Integer,​java.lang.String> map)
        Since:
        2.7
      • formatIntDouble

        public static java.lang.String formatIntDouble​(java.util.Map<java.lang.Integer,​java.lang.Double> map)
        Since:
        2.7
      • formatIntDate

        public static java.lang.String formatIntDate​(java.util.Map<java.lang.Integer,​java.util.Date> map)
        Since:
        2.7
      • formatIntDateTime

        public static java.lang.String formatIntDateTime​(java.util.Map<java.lang.Integer,​java.util.Date> map)
        Since:
        2.7
      • formatStringInt

        public static java.lang.String formatStringInt​(java.util.Map<java.lang.String,​java.lang.Integer> map)
        Since:
        2.7