forked from careercup/ctci
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
29 lines (24 loc) · 791 Bytes
/
Server.java
File metadata and controls
29 lines (24 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package Question10_2;
import java.util.HashMap;
public class Server {
HashMap<Integer, Machine> machines = new HashMap<Integer, Machine>();
HashMap<Integer, Integer> personToMachineMap = new HashMap<Integer, Integer>();
public Machine getMachineWithId(int machineID) {
return machines.get(machineID);
}
public int getMachineIDForUser(int personID) {
Integer machineID = personToMachineMap.get(personID);
return machineID == null ? -1 : machineID;
}
public Person getPersonWithID(int personID) {
Integer machineID = personToMachineMap.get(personID);
if (machineID == null) {
return null;
}
Machine machine = getMachineWithId(machineID);
if (machine == null) {
return null;
}
return machine.getPersonWithID(personID);
}
}