From d267dd1dda606f0c56d8afaa7187485e60ebfd86 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 28 Nov 2024 17:32:28 -0500 Subject: move replica2 to top level --- src/main/java/derms/replica2/Hosts.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/derms/replica2/Hosts.java (limited to 'src/main/java/derms/replica2/Hosts.java') diff --git a/src/main/java/derms/replica2/Hosts.java b/src/main/java/derms/replica2/Hosts.java new file mode 100644 index 0000000..1392b15 --- /dev/null +++ b/src/main/java/derms/replica2/Hosts.java @@ -0,0 +1,26 @@ +package derms.replica2; + +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; + +class Hosts { + private static Map hosts = null; + + 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(); + hosts.put(new City("MTL"), "alpine1"); + hosts.put(new City("QUE"), "alpine2"); + hosts.put(new City("SHE"), "alpine3"); + } +} -- cgit v1.2.3