Java Map Merge mergePropertiesToMap(Properties properties, Map map, boolean overwrite)

Here you can find the source of mergePropertiesToMap(Properties properties, Map map, boolean overwrite)

Description

Returns new Map

License

Open Source License

Parameter

Parameter Description
properties a parameter
map a parameter
overwrite a parameter

Declaration

public static <K, V> Map<K, V> mergePropertiesToMap(Properties properties, Map<K, V> map, boolean overwrite) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import java.util.Map;

import java.util.Properties;

public class Main {
    /**//from  w ww .j  a  v a  2s  .c  o m
     * Returns new Map
     *
     * @param properties
     * @param map
     * @param overwrite
     * @return
     */
    public static <K, V> Map<K, V> mergePropertiesToMap(Properties properties, Map<K, V> map, boolean overwrite) {
        Map<K, V> resultMap = new HashMap<>();
        for (K mapKey : map.keySet()) {
            resultMap.put(mapKey, map.get(mapKey));
        }
        for (Object propertyKey : properties.keySet()) {
            if ((overwrite) || (false == resultMap.containsKey((K) propertyKey))) {
                resultMap.put((K) propertyKey, (V) properties.get((K) propertyKey));
            }
        }
        return resultMap;
    }
}

Related

  1. mergeMapWithAdd(Map target, Map source)
  2. mergeNestableMap(Map original, Map additional)
  3. mergeNsPrefixes(final Map prioritaryPrefixes, final Map additionalPrefixes)
  4. mergeOptions(Map> ssio, Map> allOptions)
  5. mergePermMap(Map> permMap, Map> subPermMap)
  6. mergeResourceBundle(final Map map, final String path)
  7. mergeTemplate(String template, Map segments)
  8. mergeValue(Map obj, String key, Object value)
  9. mergeValueInMap(Map map, String name, String value)