diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-28 10:42:31 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-28 10:42:31 -0500 |
| commit | 6a710c3943f2350f4575f8cb1898129ef3c7dfdd (patch) | |
| tree | dc20bc0480e77a74f2176e5f0fed02ad2251a2cd /src/main/java/derms/replica/replica2/Hosts.java | |
| parent | 0cae203edc71b0285d2971f9124f24cb543b8e39 (diff) | |
| download | soen423-6a710c3943f2350f4575f8cb1898129ef3c7dfdd.zip | |
rename assignment code replica package
Diffstat (limited to 'src/main/java/derms/replica/replica2/Hosts.java')
| -rw-r--r-- | src/main/java/derms/replica/replica2/Hosts.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/derms/replica/replica2/Hosts.java b/src/main/java/derms/replica/replica2/Hosts.java new file mode 100644 index 0000000..16eba3d --- /dev/null +++ b/src/main/java/derms/replica/replica2/Hosts.java @@ -0,0 +1,26 @@ +package derms.replica.replica2; + +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; + +public class Hosts { + private static Map<City, String> hosts = null; + + public static String get(City city) throws UnknownHostException { + if (hosts == null) + init(); + + String host = hosts.get(city); + if (host == null) + throw new UnknownHostException("unknown host: "+city); + return host; + } + + private static void init() { + hosts = new HashMap<City, String>(); + hosts.put(new City("MTL"), "alpine1"); + hosts.put(new City("QUE"), "alpine2"); + hosts.put(new City("SHE"), "alpine3"); + } +} |