summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/replica/replica1/Servers.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/Servers.java
parente3b72053e8b04f2df013da0d7d49fe33927461a9 (diff)
downloadsoen423-3c62b863509131e78c18ed13c6b83e4fc508848f.zip
import replica code from assignment
Diffstat (limited to 'src/main/java/derms/replica/replica1/Servers.java')
-rw-r--r--src/main/java/derms/replica/replica1/Servers.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/derms/replica/replica1/Servers.java b/src/main/java/derms/replica/replica1/Servers.java
new file mode 100644
index 0000000..dc084d7
--- /dev/null
+++ b/src/main/java/derms/replica/replica1/Servers.java
@@ -0,0 +1,34 @@
+package derms.replica.replica1;
+
+import java.net.InetAddress;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Map;
+
+public class Servers {
+ private Map<City, InetAddress> servers = new ConcurrentHashMap<City, InetAddress>();
+
+ /** Returns the address of the server located in the specified city, or null if there is no server in the city. */
+ public InetAddress get(City city) {
+ return servers.get(city);
+ }
+
+ /**
+ * Associates the specified server address with the specified city.
+ * If there was already a server associated with the city, the old value is replaced.
+ * @param city the city where the server is located
+ * @param addr the address of the server
+ * @return the previous server address, or null if there was no server associated with this city.
+ */
+ public InetAddress put(City city, InetAddress addr) {
+ return servers.put(city, addr);
+ }
+
+ public Collection<InetAddress> all() {
+ return servers.values();
+ }
+
+ public int size() {
+ return servers.size();
+ }
+}