From 6a710c3943f2350f4575f8cb1898129ef3c7dfdd Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 28 Nov 2024 10:42:31 -0500 Subject: rename assignment code replica package --- src/main/java/derms/replica/replica2/Servers.java | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/derms/replica/replica2/Servers.java (limited to 'src/main/java/derms/replica/replica2/Servers.java') diff --git a/src/main/java/derms/replica/replica2/Servers.java b/src/main/java/derms/replica/replica2/Servers.java new file mode 100644 index 0000000..4d24745 --- /dev/null +++ b/src/main/java/derms/replica/replica2/Servers.java @@ -0,0 +1,34 @@ +package derms.replica.replica2; + +import java.net.InetAddress; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class Servers { + private Map servers = new ConcurrentHashMap(); + + /** 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 all() { + return servers.values(); + } + + public int size() { + return servers.size(); + } +} -- cgit v1.2.3