Here you can find the source of copyValueIfExist(Map
null
) from the source map.
Parameter | Description |
---|---|
K | the key type |
V | the value type |
source | the source |
sourceKey | the source key |
target | the target |
targetKey | the target key |
public static <K, V> boolean copyValueIfExist(Map<K, V> source, K sourceKey, Map<K, V> target, K targetKey)
//package com.java2s; //License from project: LGPL import java.util.Map; public class Main { /**//from w w w . j a v a2s. c om * Copy value from the source map to the target map only if the value exists in the source map. * * @param <K> * the key type * @param <V> * the value type * @param source * the source map * @param target * the target map * @param key * the key to copy * @return <code>true</code> if exists and copied */ public static <K, V> boolean copyValueIfExist(Map<K, V> source, Map<K, V> target, K key) { return copyValueIfExist(source, key, target, key); } /** * Copy value if it exists (is not <code>null</code>) from the source map. * * @param <K> * the key type * @param <V> * the value type * @param source * the source * @param sourceKey * the source key * @param target * the target * @param targetKey * the target key * @return true, if successful */ public static <K, V> boolean copyValueIfExist(Map<K, V> source, K sourceKey, Map<K, V> target, K targetKey) { V v = source.get(sourceKey); if (v != null) { target.put(targetKey, v); return true; } return false; } }