Class MultiValuedToFlatMapConverter


  • public class MultiValuedToFlatMapConverter
    extends Object
    Converts between a flat map Map<String, V> with compound keys and a multivalued map Map<String, List<V>>.

    The flat map uses keys in the format "key.index" to represent lists, where "key" is the base key and "index" is the zero-based index of the value in the list.

    For example, the multivalued map:

         Map.of("key", List.of("value1", "value2", "value3"));
     
    corresponds to the flat map:
         Map.of("key.0", "value1", "key.1", "value2", "key.2", "value3");
     
    Since:
    8.5.0
    • Method Detail

      • fromFlatMap

        public static <V> Map<String,​List<V>> fromFlatMap​(Map<String,​V> flatMap)
        Converts a flat map with compound keys into a multivalued map.
        Type Parameters:
        V - the type of values in the map.
        Parameters:
        flatMap - The flat map to convert, where keys are in the format "key.index".
        Returns:
        A multivalued map where each key maps to a list of values.
      • toFlatMap

        public static <V> Map<String,​V> toFlatMap​(Map<String,​List<V>> multiValuedMap)
        Converts a multivalued map into a flat map with compound keys.
        Type Parameters:
        V - the type of values in the map.
        Parameters:
        multiValuedMap - The multivalued map to convert, where each key maps to a list of values.
        Returns:
        A flat map where keys are in the format "key.index".
      • toFlatMap

        public static <V> void toFlatMap​(Map<String,​List<V>> multiValuedMap,
                                         Map<String,​V> target)
        Converts a multivalued map into a flat map with compound keys, writing the result into the provided target map.
        Type Parameters:
        V - the type of values in the map.
        Parameters:
        multiValuedMap - The multivalued map to convert, where each key maps to a list of values.
        target - The target flat map where the result will be written.