-
Notifications
You must be signed in to change notification settings - Fork 0
/
DistrictProxyWarehouse.java
36 lines (31 loc) · 1.15 KB
/
DistrictProxyWarehouse.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
import java.util.HashMap;
import java.util.Map;
public class DistrictProxyWarehouse implements Warehouse {
public DistrictProxyWarehouse() {
productList = new HashMap<>();
}
private GlobalWarehouse globalWarehouse;
private Map<String,Integer> productList;
public void getFromGlobalWarehouse(String productName){
if (globalWarehouse == null){
globalWarehouse = new GlobalWarehouse();
}
globalWarehouse.deliverProduct(productName);
productList.put(productName,2);
}
@Override
public void deliverProduct(String productName) {
if (!productList.containsKey(productName)){
getFromGlobalWarehouse(productName);
}
else if(productList.get(productName)<1){
getFromGlobalWarehouse(productName);
}
else{
System.out.println("Product delivered from District (Proxy) Warehouse.");
int current_quantity = productList.get(productName);
productList.put(productName,current_quantity-1);
System.out.println(productList.get(productName) + " stock left of " + productName + "\n");
}
}
}