-
Notifications
You must be signed in to change notification settings - Fork 1
/
Warehouse.java
119 lines (112 loc) · 2.29 KB
/
Warehouse.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
111
112
113
114
115
116
117
118
119
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;
/**
*
* @author akshyta, anushika
*
*class representing a warehouse containing a list of stores linked to it and its administrator as attributes.
*/
public class Warehouse implements Serializable
{
private String name;
private int id;
private WarehouseAdmin admin=null;
private Inventory i;
public ArrayList<Store> ListOfStores=new ArrayList<Store>();
public int city;
/**
* constructor.
*/
public Warehouse(String a,int b,Inventory d)
{
name=a;
id=b;
i=d;
}
/**
* getter function
* @return name of the warehouse
*/
public String getName()
{
return name;
}
/**
* sets the name of the warehouse
* @param s
*/
public void setName(String s)
{
name=s;
}
/**
* getter function
* @return id of the warehouse
*/
public int getId()
{
return id;
}
/**
* sets the id of the warehouse
* @param a
*/
public void setId(int a)
{
id=a;
}
/**
* getter function
* @return inventory
*/
public Inventory getInventory()
{
return i;
}
public WarehouseAdmin getAdmin() {
return admin;
}
/**
* setter function
* sets the administrator for the warehouse.
*/
public void setAdmin(WarehouseAdmin admin) {
this.admin = admin;
}
/**
* function to order an item from other warehouses when the current warehouse doesn't contain the item in its inventory.
* @param warray
* @param item
* @param quantity
*/
public void OrderFromOthers(ArrayList<Warehouse> warray,Item item,int quantity)
{
int min=Integer.MAX_VALUE;
Warehouse desired=null;
Item req=null;
for(int i=0;i<warray.size();i++)
{
if(Math.abs(this.city-warray.get(i).city)<min)
{
for (Map.Entry<Item,Integer> entry : warray.get(i).getInventory().AllItems.entrySet())
{
if(entry.getKey().getName().equals(item.getName()) && entry.getValue()>=quantity)
{
min=Math.abs(this.city-warray.get(i).city);
desired=warray.get(i);
req=entry.getKey();
}
}
}
}
if(desired!=null)
{
desired.i.AllItems.put(req, desired.i.AllItems.get(req)-quantity);
}
else
{
System.out.println("no warehouses have item ");
}
}
}