package maps;

import java.util.*;

public class MapMore {

    public static void main(String[] args) {
        Map<Object, Object>m1 = new HashMap<Object, Object>();
        m1.put("hello","bob");
        m1.put(1000,"Dragons");
        m1.put("Happy","New Year");
        
        Map<Object, Object>m2 = new HashMap<Object, Object>();
        m2.put("hello","jim");
        m2.put(1000,"Miles");
        m2.put("Merry","Christmas");
        
        // Find the common keys
        Set<Object>commonKeys = new HashSet<Object>(m1.keySet());
        commonKeys.retainAll(m2.keySet());
        
        System.out.println(commonKeys);
    }
    
    static <K, V> boolean validate(Map<K, V> attrMap,
            Set<K> requiredAttrs, Set<K>permittedAttrs) {
        boolean valid = true;
        Set<K> attrs = attrMap.keySet();
        if(!attrs.containsAll(requiredAttrs)) {
            Set<K> missing = new HashSet<K>(requiredAttrs);
            missing.removeAll(attrs);
            System.out.println("Missing attributes: " + missing);
            valid = false;
        }
        if (!permittedAttrs.containsAll(attrs)) {
            Set<K> illegal = new HashSet<K>(attrs);
            illegal.removeAll(permittedAttrs);
            System.out.println("Illegal attributes: " + illegal);
            valid = false;
        }
        return valid;
    }
    
}
