@Test public void targetCannotBeNullInCopy() { expected.expect(IllegalArgumentException.class); MapUtil.copy(new HashMap<String, String>(), null); }
public static <Value> void copy(Map<String, Value> source, Map<String, Value> target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } if (source == null || source.isEmpty()) { return; } for (Map.Entry<String,Value> entry : source.entrySet()) { String key = entry.getKey(); if (Strings.isNullOrEmpty(key)) { continue; } if (!target.containsKey(key)) { if (target instanceof ConcurrentHashMap && entry.getValue() == null) { continue; } else { target.put(key, entry.getValue()); } } } }
MapUtil { public static <Value> void copy(Map<String, Value> source, Map<String, Value> target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } if (source == null || source.isEmpty()) { return; } for (Map.Entry<String,Value> entry : source.entrySet()) { String key = entry.getKey(); if (Strings.isNullOrEmpty(key)) { continue; } if (!target.containsKey(key)) { if (target instanceof ConcurrentHashMap && entry.getValue() == null) { continue; } else { target.put(key, entry.getValue()); } } } } }
MapUtil { public static <Value> void copy(Map<String, Value> source, Map<String, Value> target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } if (source == null || source.isEmpty()) { return; } for (Map.Entry<String,Value> entry : source.entrySet()) { String key = entry.getKey(); if (Strings.isNullOrEmpty(key)) { continue; } if (!target.containsKey(key)) { if (target instanceof ConcurrentHashMap && entry.getValue() == null) { continue; } else { target.put(key, entry.getValue()); } } } }  }
MapUtil { public static <Value> void copy(Map<String, Value> source, Map<String, Value> target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } if (source == null || source.isEmpty()) { return; } for (Map.Entry<String,Value> entry : source.entrySet()) { String key = entry.getKey(); if (Strings.isNullOrEmpty(key)) { continue; } if (!target.containsKey(key)) { if (target instanceof ConcurrentHashMap && entry.getValue() == null) { continue; } else { target.put(key, entry.getValue()); } } } }  static void copy(Map<String, Value> source, Map<String, Value> target); static Value getValueOrNull(Map<Key, Value> map, Key key); static Boolean getBoolValueOrNull(Map<String, String> map, String key); static Date getDateValueOrNull(Map<String, String> map, String key); static void setStringValueOrRemove(Map<String, String> map, String key, String value); static void setBoolValueOrRemove(Map<String, String> map, String key, Boolean value); static void setDateValueOrRemove(Map<String, String> map, String key, Date value); }
MapUtil { public static <Value> void copy(Map<String, Value> source, Map<String, Value> target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } if (source == null || source.isEmpty()) { return; } for (Map.Entry<String,Value> entry : source.entrySet()) { String key = entry.getKey(); if (Strings.isNullOrEmpty(key)) { continue; } if (!target.containsKey(key)) { if (target instanceof ConcurrentHashMap && entry.getValue() == null) { continue; } else { target.put(key, entry.getValue()); } } } }  static void copy(Map<String, Value> source, Map<String, Value> target); static Value getValueOrNull(Map<Key, Value> map, Key key); static Boolean getBoolValueOrNull(Map<String, String> map, String key); static Date getDateValueOrNull(Map<String, String> map, String key); static void setStringValueOrRemove(Map<String, String> map, String key, String value); static void setBoolValueOrRemove(Map<String, String> map, String key, Boolean value); static void setDateValueOrRemove(Map<String, String> map, String key, Date value);  }