package com.codegym.task.task08.task0817;

import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;

/*
We don't need repeats

*/

public class Solution {
    public static HashMap<String, String> createMap() {
        //write your code here
        HashMap<String, String> map = new HashMap<String, String>();

        map.put("martin", "damien");
        map.put("luther", "king");
        map.put("sally", "king");
        map.put("pablo", "linde");
        map.put("wandy", "williams");
        map.put("mel", "linde");
        map.put("stacy", "luca");
        map.put("walter", "isac");
        map.put("molly", "isac");
        map.put("wober", "williams");

        return map;

    }

    public static void removeFirstNameDuplicates(Map<String, String> map) {
        //write your code here
        HashMap<String, String> copy = new HashMap<String, String>(map);
        for(Map.Entry<String, String> name : copy.entrySet())
        {
            String lastName = name.getKey();
            String firstName = name.getValue();
            removeItemFromMapByValue(map, firstName);
            map.put(lastName, firstName);
        }

    }

    public static void removeItemFromMapByValue(Map<String, String> map, String value) {
        HashMap<String, String> copy = new HashMap<String, String>(map);
        for (Map.Entry<String, String> pair : copy.entrySet()) {
            if (pair.getValue().equals(value))
                map.remove(pair.getKey());
        }
    }

    public static void main(String[] args) {

    }
}