duplcate a hashmap with FunctionLibFunction's

@param funcs
@param deepCopy
@return cloned map
512428
private HashMap duplicate(HashMap funcs, boolean deepCopy) {
	if (deepCopy) throw new PageRuntimeException(new ExpressionException("deep copy not supported"));

	Iterator it = funcs.entrySet().iterator();
	Map.Entry entry;
	HashMap cm = new HashMap();
	while (it.hasNext()) {
	    entry = (Entry) it.next();
	    cm.put(entry.getKey(), deepCopy ? entry.getValue() : // TODO add support for deepcopy ((FunctionLibFunction)entry.getValue()).duplicate(deepCopy):
		    entry.getValue());
	}
	return cm;
    }
878104
public static <T1, T2, T3, R> Function3<T1, T2, T3, R> memoizeTriFunction(final Function3<T1, T2, T3, R> fn, final Cacheable<R> cache) {
      Function1<Tuple3<T1, T2, T3>, R> memoise2 = memoizeFunction((final Tuple3<T1, T2, T3> triple) -> fn.apply(triple._1(), triple._2(), triple._3()), cache);
        return (t1, t2, t3) -> memoise2.apply(tuple(t1, t2, t3));
    }
377074
function _shallowCopy(component) {
        var clone = {},
            property;

        for (property in component) {
            if (component.hasOwnProperty(property)) {
                clone[property] = component[property];
            }
        }

        return clone;
    }
857770
function clone(obj, deep) {

    if (!obj || typeof obj !== "object" || isFunction(obj)) {
        // null, undefined, any non-object, or function
        return obj;   // anything
    }
    if (obj instanceof Date) {
        // Date
        return new Date(obj.getTime());   // Date
    }
    var result, index, length, value;
    if (isArray(obj)) {
        // array
        result = [];
        if (deep) {
            for (index = 0, length = obj.length; index < length; index += 1) {
                if (index in obj) {
                    value = obj[index];
                    value = value.clone ? value.clone(true) : clone(value);
                    result.push(clone(value));
                }
            }
        } else {
            for (index = 0, length = obj.length; index < length; index += 1) {
                if (index in obj) {
                    result.push(value);
                }
            }
        }
        return result;
    }

    //Default implementation
    if (obj.clone) {
        return obj.clone(obj, deep);
    }

    // generic objects
    result = obj.constructor ? new obj.constructor() : {};

    for (index in obj) {
        if (true) {//jslint validation
            value = obj[index];
            if (
                !(index in result) ||
                (result[index] !== value && (!(index in EMPTY) || EMPTY[index] !== value))
            ) {
                result[index] = clone(value);
            }
        }
    }

    return result; // Object
}
1332775
public static <T, K, V> MutableMap<K, V> toMap(
            Iterable<T> iterable,
            Function<? super T, ? extends K> keyFunction,
            Function<? super T, ? extends V> valueFunction)
    {
        return Iterate.addToMap(iterable, keyFunction, valueFunction, UnifiedMap.<K, V>newMap());
    }
801371
function dedupeJSONStringify(jsonValue: mixed): string {
  // Clone the object to convert references to the same object instance into
  // copies. This is needed for the WeakMap/Map to recognize them as duplicates.
  // $FlowFixMe(>=0.95.0) JSON.stringify can return undefined
  jsonValue = JSON.parse(JSON.stringify(jsonValue));
  const metadataForHash = new Map();
  const metadataForVal = new WeakMap();
  const varDefs = [];
  collectMetadata(jsonValue);
  collectDuplicates(jsonValue);
  const code = printJSCode(false, '', jsonValue);
  return varDefs.length === 0
    ? code
    : `(function(){\nvar ${varDefs.join(',\n')};\nreturn ${code};\n})()`;

  // Collect common metadata for each object in the value tree, ensuring that
  // equivalent values have the *same reference* to the same metadata. Note that
  // the hashes generated are not exactly JSON, but still identify equivalent
  // values. Runs in linear time due to hashing in a bottom-up recursion.
  function collectMetadata(value) {
    if (value == null || typeof value !== 'object') {
      return JSON.stringify(value);
    }
    let hash;
    if (Array.isArray(value)) {
      hash = '[';
      for (let i = 0; i < value.length; i++) {
        hash += collectMetadata(value[i]) + ',';
      }
    } else {
      hash = '{';
      for (const k in value) {
        if (value.hasOwnProperty(k) && value[k] !== undefined) {
          hash += k + ':' + collectMetadata(value[k]) + ',';
        }
      }
    }
    let metadata = metadataForHash.get(hash);
    if (!metadata) {
      metadata = {value, hash, isDuplicate: false};
      metadataForHash.set(hash, metadata);
    }
    metadataForVal.set(value, metadata);
    return hash;
  }

  // Using top-down recursion, linearly scan the JSON tree to determine which
  // values should be deduplicated.
  function collectDuplicates(value) {
    if (value == null || typeof value !== 'object') {
      return;
    }
    const metadata = metadataForVal.get(value);
    // Only consider duplicates with hashes longer than 2 (excludes [] and {}).
    if (metadata && metadata.value !== value && metadata.hash.length > 2) {
      metadata.isDuplicate = true;
      return;
    }
    if (Array.isArray(value)) {
      for (let i = 0; i < value.length; i++) {
        collectDuplicates(value[i]);
      }
    } else {
      for (const k in value) {
        if (value.hasOwnProperty(k) && value[k] !== undefined) {
          collectDuplicates(value[k]);
        }
      }
    }
  }

  // Stringify JS, replacing duplicates with variable references.
  function printJSCode(isDupedVar, depth, value) {
    if (value == null || typeof value !== 'object') {
      return JSON.stringify(value);
    }
    // Only use variable references at depth beyond the top level.
    if (depth !== '') {
      const metadata = metadataForVal.get(value);
      if (metadata && metadata.isDuplicate) {
        if (!metadata.varName) {
          const refCode = printJSCode(true, '', value);
          metadata.varName = 'v' + varDefs.length;
          varDefs.push(metadata.varName + ' = ' + refCode);
        }
        return '(' + metadata.varName + '/*: any*/)';
      }
    }
    let str;
    let isEmpty = true;
    const depth2 = depth + '  ';
    if (Array.isArray(value)) {
      // Empty arrays can only have one inferred flow type and then conflict if
      // used in different places, this is unsound if we would write to them but
      // this whole module is based on the idea of a read only JSON tree.
      if (isDupedVar && value.length === 0) {
        return '([]/*: any*/)';
      }
      str = '[';
      for (let i = 0; i < value.length; i++) {
        str +=
          (isEmpty ? '\n' : ',\n') +
          depth2 +
          printJSCode(isDupedVar, depth2, value[i]);
        isEmpty = false;
      }
      str += isEmpty ? ']' : `\n${depth}]`;
    } else {
      str = '{';
      for (const k in value) {
        if (value.hasOwnProperty(k) && value[k] !== undefined) {
          str +=
            (isEmpty ? '\n' : ',\n') +
            depth2 +
            JSON.stringify(k) +
            ': ' +
            printJSCode(isDupedVar, depth2, value[k]);
          isEmpty = false;
        }
      }
      str += isEmpty ? '}' : `\n${depth}}`;
    }
    return str;
  }
}
613898
public static <K1, K2, V> ImmutableSetMultimap<K2, V> copyWithTransformedKeys(
      final SetMultimap<K1,V> setMultimap,
      final Function<? super K1, ? extends K2> function) {
    final ImmutableSetMultimap.Builder<K2,V> ret = ImmutableSetMultimap.builder();
    for (final Map.Entry<K1, V> entry : setMultimap.entries()) {
      // nulls banned by contract
      //noinspection ConstantConditions
      ret.put( function.apply(entry.getKey()), entry.getValue());
    }
    return ret.build();
  }
979682
function deepCopy(destination, source) {
    Object.keys(source).forEach(function (property) {
        if (destination[property] && isObject(destination[property])) {
            deepCopy(destination[property], source[property]);
        } else {
            destination[property] = source[property];
        }
    });
}
661463
public static <T1, T2, R> BiFunction<T1, T2, R> memoize(final BiFunction<T1, T2, R> biFunc) {
    final Function<T1, Function<T2, R>> transformed = Memoizer.memoize(x -> Memoizer.memoize(y -> biFunc.apply(x, y)));
    return Transformations
        .<T1, T2, R>unCurryBiFunction()
        .apply(transformed);
  }
1114166
function deepCopy(obj) {
			var ret = {}, key, val;
			for (key in obj) {
				if (obj.hasOwnProperty(key)) {
					val = obj[key];
					if (typeof val === 'object' && val !== null) {
						ret[key] = deepCopy(val);
					} else {
						ret[key] = val;
					}
				}
			}
			return ret;
		}
1184385
public static FunctionMapper newFunctionMapper() {
        ServiceLoader<FunctionMapperSpi> loader = loadFunctionMapperSpi();

        // load FunctionMapperSpi instances
        ConcurrentMap<String, FunctionMapperSpi> functionMappers = new ConcurrentHashMap<>();
        for (FunctionMapperSpi functionMapperSpi : loader) {
            String prefixName = functionMapperSpi.getPrefixName();
            FunctionMapperSpi oldFunctionMapperSpi = functionMappers.putIfAbsent(prefixName, functionMapperSpi);
            if (oldFunctionMapperSpi != null) {
                throw new ELException(String.format("Duplicate prefix function mapper: %s", prefixName));
            }
        }

        return new FunctionMapper(functionMappers);
    }
739277
static public <T extends Iced> T deepCopy(T iced) {
    if (iced == null) return null;
    AutoBuffer ab = new AutoBuffer();
    iced.write(ab);
    ab.flipForReading();
    // Create a new instance
    return (T) TypeMap.newInstance(iced.frozenType()).read(ab);
  }
1361977
function deepClone(inputDict){

    if (!inputDict)
        return null;

    const clonedDict = {};

    for (let key in inputDict){

        if (typeof(inputDict[key]) == 'object'){

            clonedDict[key] = deepClone(inputDict[key]);
        
        }
        else{

            clonedDict[key] = inputDict[key];

        }

    }

    return clonedDict;

}
500361
function cloneMap$1(map, isDeep, cloneFunc) {
  var array = isDeep ? cloneFunc(mapToArray(map), CLONE_DEEP_FLAG$2) : mapToArray(map);
  return arrayReduce(array, addMapEntry, new map.constructor());
}
315523
function deepCopy(obj) {
  var cache = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

  // just return if obj is immutable value
  if (obj === null || (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') {
    return obj;
  }

  // if obj is hit, it is in circular structure
  var hit = find(cache, function (c) {
    return c.original === obj;
  });
  if (hit) {
    return hit.copy;
  }

  var copy = Array.isArray(obj) ? [] : {};
  // put the copy into cache at first
  // because we want to refer it in recursive deepCopy
  cache.push({
    original: obj,
    copy: copy
  });

  Object.keys(obj).forEach(function (key) {
    if (avalon.msie < 9 && /^\$\w+$/.test(key)) return;
    copy[key] = deepCopy(obj[key], cache);
  });

  return copy;
}
1356409
private static <K, V> Map<K, V> synchronizedCopyMap(Map<K, V> map) {

        if (map == null) {
            return new HashMap<K, V>();
        }

        synchronized (map) {

            return new HashMap<K, V>(map);
        }
    }
33872
public static Map duplicateMap(Map map, boolean doKeysLower, boolean deepCopy) throws PageException {
	if (doKeysLower) {
	    Map newMap;
	    try {
		newMap = (Map) ClassUtil.loadInstance(map.getClass());
	    }
	    catch (ClassException e) {
		newMap = new HashMap();
	    }
	    boolean inside = ThreadLocalDuplication.set(map, newMap);
	    try {
		Iterator it = map.keySet().iterator();
		while (it.hasNext()) {
		    Object key = it.next();
		    if (deepCopy) newMap.put(StringUtil.toLowerCase(Caster.toString(key)), duplicate(map.get(key), deepCopy));
		    else newMap.put(StringUtil.toLowerCase(Caster.toString(key)), map.get(key));
		}
	    }
	    finally {
		if (!inside) ThreadLocalDuplication.reset();
	    }
	    //
	    return newMap;
	}
	return duplicateMap(map, deepCopy);
    }