summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/replica/replica1/Hosts.java
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-11-23 13:51:12 -0500
committerSam Anthony <sam@samanthony.xyz>2024-11-23 13:51:12 -0500
commit3c62b863509131e78c18ed13c6b83e4fc508848f (patch)
treecf246e91da283edf704af936b9cef7eb8e09a6f8 /src/main/java/derms/replica/replica1/Hosts.java
parente3b72053e8b04f2df013da0d7d49fe33927461a9 (diff)
downloadsoen423-3c62b863509131e78c18ed13c6b83e4fc508848f.zip
import replica code from assignment
Diffstat (limited to 'src/main/java/derms/replica/replica1/Hosts.java')
-rw-r--r--src/main/java/derms/replica/replica1/Hosts.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/derms/replica/replica1/Hosts.java b/src/main/java/derms/replica/replica1/Hosts.java
new file mode 100644
index 0000000..fed377e
--- /dev/null
+++ b/src/main/java/derms/replica/replica1/Hosts.java
@@ -0,0 +1,27 @@
+package derms.replica.replica1;
+
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+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");
+ }
+}