все где повторяются имена удаляет, но по 4 му пункту не проходит
package com.javarush.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/*
Нам повторы не нужны
*/
public class Solution {
public static Map<String, String> createMap() {
//напишите тут ваш код
Map<String, String> map = new HashMap<String, String>();
map.put("Иванов", "Иван");
map.put("Петров", "Петр");
map.put("Ивановв", "Петр");
map.put("Петровв", "Иван");
map.put("Петраванов", "Иванпетр");
map.put("Ивапетров", "Петриван");
map.put("Сидоров", "Сидр");
map.put("Шварцнегер", "Шварц");
map.put("Сталоне", "Встоловой");
map.put("Пупкин", "Запупкин");
return map;
}
public static void removeTheFirstNameDuplicates(Map<String, String> map) {
//напишите тут ваш код
Map<String, String> copy = new HashMap<String, String>(map);
Iterator<Map.Entry<String, String>> iterator = copy.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> pair = iterator.next();
removeItemFromMapByValue(map, pair.getKey());
}
System.out.println(map);
}
public static void removeItemFromMapByValue(Map<String, String> map, String value) {
Map<String, String> copy = new HashMap<String, String>(map);
for (Map.Entry<String, String> pair : copy.entrySet()) {
if ((map.get(value) != null) && (map.get(pair.getKey()) != null) && (pair.getKey() != value) && (map.get(value).equals(pair.getValue()))) {
map.remove(pair.getKey());
}
}
}
public static void main(String[] args) {
removeTheFirstNameDuplicates(createMap());
}
}