-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWareHouse.java
More file actions
70 lines (61 loc) · 1.91 KB
/
Copy pathWareHouse.java
File metadata and controls
70 lines (61 loc) · 1.91 KB
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
import java.util.*;
public class WareHouse {
private Location location;
private Set<Order> orders;
private Map<Order, DeliveryPerson> deliveredOrders;
/**
* Constructor for objects of class WareHouse
*/
public WareHouse() {
this.location = new Location(5, 5);
this.orders = new TreeSet<>(new ComparadorUrgenciaOrder());
this.deliveredOrders = new TreeMap<>(new ComparadorDeliveredOrders());
}
/**
* @return The location of the warehouse.
*/
public Location getLocation() {
return location;
}
/**
* @return The set of orders in the warehouse.
*/
public Set<Order> getOrders() {
return orders;
}
/**
* Add an order to the warehouse.
* The orders are automatically sorted by urgency, delivery time, and destination name.
* @param order The order to be added.
*/
public void addOrder(Order order) {
orders.add(order);
}
/**
* Retrieve and remove the first order in the warehouse.
* @return The first order if it exists, null otherwise.
*/
public Order retrieveFirstOrder() {
Iterator<Order> iterator = orders.iterator();
if (iterator.hasNext()) {
Order firstOrder = iterator.next();
orders.remove(firstOrder);
return firstOrder;
}
return null;
}
/**
* Add a delivered order and its delivery person to the delivered orders collection.
* @param order The delivered order.
* @param deliveryPerson The delivery person who delivered the order.
*/
public void addDeliveredOrder(Order order, DeliveryPerson deliveryPerson) {
deliveredOrders.put(order, deliveryPerson);
}
/**
* @return A map of delivered orders and their associated delivery persons.
*/
public Map<Order, DeliveryPerson> getDeliveredOrders() {
return deliveredOrders;
}
}