io.snice.functional.Maps Maven / Gradle / Ivy
package io.snice.functional;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Maps {
/**
* Quite specialized helper function whose sole purpose is to deal with maps that has the following
* structure (and perhaps was created using Lightbends Configuration objects):
*
*
* {
* "whatever" = {
* "hello" = "world"
* "one" = "two"
* }
* "something" = {
* "yes" = "no"
* }
* }
*
*
* And what you want to do is to take the "whatever", which is the name for the subsequent map (the
* ones that contain the keys "hello" and "one) and flatten it down into the same map like so:
*
* {
* "name" = "whatever
* "hello" = "world"
* "one" = "two"
* }
*
*
* Read https://github.com/lightbend/config and HOCON and it probably will make more sense.
*
* @param keyName the name of the new key we will insert into the flattened map
* @param map the map of maps to flatten.
* @return a list of flattened maps where the original outer map and it's single key has been merged
* as an entry into the original sub-map under the key name of
*/
public static List