Не знаю где я неправильно делаю, подскажите пожалуйста
package com.javarush.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
/*
Нам повторы не нужны
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> people = new HashMap<String, String>();
people.put("lastName1", "firstName1");
people.put("lastName2", "firstName1");
people.put("lastName3", "firstName3");
people.put("lastName4", "firstName4");
people.put("lastName5", "firstName5");
people.put("lastName6", "firstName7");
people.put("lastName7", "firstName7");
people.put("lastName8", "firstName8");
people.put("lastName9", "firstName9");
people.put("lastName0", "firstName0");
return people;
}
public static void removeTheFirstNameDuplicates(Map<String, String> map) {
// HashMap<String, Integer> valueCounter = new HashMap<String, Integer>();
for (Map.Entry<String, String> pair : map.entrySet()) {
String key = pair.getKey();
String value = pair.getValue();
int count = 0;
if (pair.getValue().equals(value)) {
count++;
}
if(count > 1){
removeItemFromMapByValue(map,value);
}
// valueCounter.put(value, count);
}
// for(HashMap.Entry<String, Integer> remove : valueCounter.entrySet()){
// if(remove.getValue() > 1){
// removeItemFromMapByValue(map, remove.getKey());
// }
//
// }
}
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) {
removeTheFirstNameDuplicates(createMap());
}
}