diff --git a/solutions/java/international-calling-connoisseur/1/src/main/java/DialingCodes.java b/solutions/java/international-calling-connoisseur/1/src/main/java/DialingCodes.java new file mode 100644 index 00000000..d913e950 --- /dev/null +++ b/solutions/java/international-calling-connoisseur/1/src/main/java/DialingCodes.java @@ -0,0 +1,41 @@ +import java.util.Map; +import java.util.HashMap; + +public class DialingCodes { + + Map map = new HashMap<>(); + + public Map getCodes() { + return map; + } + + public void setDialingCode(Integer code, String country) { + map.put(code, country); + } + + public String getCountry(Integer code) { + return map.get(code); + } + + public void addNewDialingCode(Integer code, String country) { + if (map.containsKey(code) || map.containsValue(country)) { + return; + } + map.put(code, country); + } + + public Integer findDialingCode(String country) { + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().equals(country)) { + return entry.getKey(); // Gefunden! + } + } + return null; + } + public void updateCountryDialingCode(Integer code, String country) { + if (map.containsValue(country)) { + map.remove(findDialingCode(country)); + map.put(code, country); + } + } +}