-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCustomerManager.java
More file actions
50 lines (33 loc) · 1.1 KB
/
CustomerManager.java
File metadata and controls
50 lines (33 loc) · 1.1 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
package legacy.model;
import legacy.enums.CustomerStatus;
import java.util.ArrayList;
public class CustomerManager {
private final ArrayList<Customer> customers = new ArrayList<>();
public Customer createCustomer(String id, String name, CustomerStatus status) {
Customer customer = new Customer(id, name, status);
customers.add(customer);
return customer;
}
public Customer updateCustomer(String id, String newName) {
Customer customer = getCustomer(id);
customer.setName(newName);
return customer;
}
public void deleteCustomer(String id) {
customers.remove(getCustomer(id));
}
public String getOldName(String id) {
return getCustomer(id).getName();
}
private Customer getCustomer(String id) {
for (Customer customer : customers) {
if (customer.getId().equals(id)) {
return customer;
}
}
throw new IllegalArgumentException("존재하지 않는 ID : " + id);
}
public ArrayList<Customer> getCustomers() {
return customers;
}
}