Merge pull request #87 from Weltenbummler397/exercism-sync/ea0468383a318bf8

[Sync Iteration] java/international-calling-connoisseur/1
This commit is contained in:
Weltenbummler397 2026-05-04 09:19:46 +02:00 committed by GitHub
commit 924db519fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,41 @@
import java.util.Map;
import java.util.HashMap;
public class DialingCodes {
Map<Integer, String> map = new HashMap<>();
public Map<Integer, String> 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<Integer, String> 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);
}
}
}