-
Notifications
You must be signed in to change notification settings - Fork 162
/
InventorySystem.java
110 lines (88 loc) · 2.46 KB
/
InventorySystem.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//From: https://youtu.be/T-9s9U28KJM
import java.util.HashMap;
import java.util.Map;
public class InventorySystem {
static Map<String, Product> productMap = new HashMap<>();
static Map<Location, Unit> locationMap = new HashMap<>();
public static void addProduct(Product product) {
productMap.put(product.id, product);
}
public static Product getProduct(String product) {
return productMap.get(product);
}
public static void placeUnit(Unit unit) {
for (Map.Entry<Location, Unit> entry: locationMap.entrySet()){
// if (SimpleStrategy.works())
//get lock on entry.getKey()
if(entry.getValue()==null){
unit.locationId = entry.getKey().id;
}
//release lock
}
}
public static void removeUnit(Product product) {
for (Map.Entry<Location, Unit> entry: locationMap.entrySet()){
// if (SimpleStrategy.works())
//get lock on entry.getKey()
if(entry.getValue()!=null && product.id.equals(entry.getValue().productId)){
locationMap.remove(entry.getKey());
}
//release lock
}
}
public static Map<Location, Unit> getShelvesStatus(){
return locationMap;
}
public static void updateStatus(Unit unit, Status status){
unit.status = status;
}
}
class SimpleStrategy {
}
class SmartStrategy {
}
class Unit {
String id;
String productId;
String locationId;
Status status;
}
class Location {
String id;
Size size;
}
enum Status {
INVENTORY, TRANSIT, DELIVERY
}
class Product {
String id;
Double price;
String description;
double weight;
Size size;
public Product(String id, Double price, String description, double weight, Size size) {
this.id = id;
this.price = price;
this.description = description;
this.weight = weight;
this.size = size;
}
}
enum Size {
S,M,L
}
class User {
public void addProduct(){
InventorySystem.addProduct(new Product("", 0d,"",0,Size.L));
}
public void executeOrder(Order order){
for(Map.Entry<Product, Integer> item: order.productCount.entrySet()) {
for (int i = 0; i < item.getValue(); i++) {
InventorySystem.removeUnit(item.getKey());
}
}
}
}
class Order {
Map<Product, Integer> productCount = new HashMap<>();
}