public static Map < String , Map < String , String > > merge ( final Map < String , Map < String , String > > targetContext , final Map < String , Map < String , String > > newContext ) { final HashMap < String , Map < String , String > > result = deepCopy ( targetContext ) ; for ( final Map . Entry < String , Map < String , String > > entry : newContext . entrySet ( ) ) { if ( ! targetContext . containsKey ( entry . getKey ( ) ) ) { result . put ( entry . getKey ( ) , new HashMap <> ( ) ) ; } else { result . put ( entry . getKey ( ) , new HashMap <> ( targetContext . get ( entry . getKey ( ) ) ) ) ; } result . get ( entry . getKey ( ) ) . putAll ( entry . getValue ( ) ) ; } return result ; }
Merge one context onto another by adding or replacing values in a new map