-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathOrder.java
More file actions
60 lines (51 loc) · 1.56 KB
/
Order.java
File metadata and controls
60 lines (51 loc) · 1.56 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
package com.ironhack;
import java.math.BigDecimal;
import java.util.List;
public class Order {
private final String id;
private final String customerId;
private final BigDecimal total;
private final List<OrderItem> items;
public Order(String id, String customerId, BigDecimal total, List<OrderItem> items) {
validateOrder(id, customerId, total, items);
this.id = id;
this.customerId = customerId;
this.total = total;
this.items = items;
}
private void validateOrder(String id, String customerId, BigDecimal total, List<OrderItem> items) {
if (id == null) {
throw new IllegalArgumentException("ID cannot be null");
}
if (customerId == null) {
throw new IllegalArgumentException("Customer ID cannot be null");
}
if (total == null) {
throw new IllegalArgumentException("Total cannot be null");
}
if (items == null) {
throw new IllegalArgumentException("Order items must be specified");
}
}
public String getId() {
return id;
}
public String getCustomerId() {
return customerId;
}
public BigDecimal getTotal() {
return total;
}
public List<OrderItem> getItems() {
return items;
}
@Override
public String toString() {
return "Order{" +
"id='" + id + '\'' +
", customerId='" + customerId + '\'' +
", total=" + total +
", items=" + items +
'}';
}
}