org.javers.common.collections.Maps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
package org.javers.common.collections;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @author bartosz walacik
*/
public class Maps {
public static Map wrapNull(Object map){
if (map == null){
return Collections.emptyMap();
}
return (Map)map;
}
/**
* null args are allowed
*/
public static Set commonKeys(Map left, Map right) {
if (left == null || right == null) {
return Collections.emptySet();
}
return Sets.intersection(left.keySet(),right.keySet());
}
/**
* null args are allowed
*/
public static Set keysDifference(Map left, Map right) {
if (left == null){
return Collections.emptySet();
}
if (right == null){
return left.keySet();
}
return Sets.difference(left.keySet(), right.keySet());
}
public static Map of(Object key, Object val) {
Map m = new HashMap();
m.put(key, val);
return Collections.unmodifiableMap(m);
}
public static Map merge(Map a, Map b) {
if (a == null || a.isEmpty()) {
return b;
}
if (b == null || b.isEmpty()) {
return a;
}
Map m = new HashMap(b);
m.putAll(a);
return Collections.unmodifiableMap(m);
}
}