MCPcopy Create free account
hub / github.com/InterviewReady/Low-Level-Design / InventorySystem

Class InventorySystem

InventorySystem.java:6–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import java.util.Map;
5
6public class InventorySystem {
7
8 static Map<String, Product> productMap = new HashMap<>();
9 static Map<Location, Unit> locationMap = new HashMap<>();
10
11 public static void addProduct(Product product) {
12 productMap.put(product.id, product);
13 }
14
15 public static Product getProduct(String product) {
16 return productMap.get(product);
17 }
18
19 public static void placeUnit(Unit unit) {
20 for (Map.Entry<Location, Unit> entry: locationMap.entrySet()){
21 // if (SimpleStrategy.works())
22 //get lock on entry.getKey()
23 if(entry.getValue()==null){
24 unit.locationId = entry.getKey().id;
25 }
26 //release lock
27 }
28 }
29
30 public static void removeUnit(Product product) {
31 for (Map.Entry<Location, Unit> entry: locationMap.entrySet()){
32 // if (SimpleStrategy.works())
33 //get lock on entry.getKey()
34 if(entry.getValue()!=null && product.id.equals(entry.getValue().productId)){
35 locationMap.remove(entry.getKey());
36 }
37 //release lock
38 }
39 }
40
41 public static Map<Location, Unit> getShelvesStatus(){
42 return locationMap;
43 }
44
45 public static void updateStatus(Unit unit, Status status){
46 unit.status = status;
47 }
48}
49
50class SimpleStrategy {
51

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected