-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomers.java
More file actions
52 lines (39 loc) · 1.38 KB
/
Customers.java
File metadata and controls
52 lines (39 loc) · 1.38 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
package jyjang.smartstore.customer;
import jyjang.smartstore.arrays.DArray;
import jyjang.smartstore.group.Group;
import jyjang.smartstore.group.GroupType;
import jyjang.smartstore.group.Groups;
public class Customers extends DArray<Customer> {
// singleton
private static Customers allCustomers;
private final Groups allGroups;
public static Customers getInstance() {
if (allCustomers == null) {
allCustomers = new Customers();
}
return allCustomers;
}
private Customers() {
this.allGroups = Groups.getInstance();
}
// refresh 함수가 호출되는 경우
// 1. 분류기준 바뀔 때
// 2. 새로운 고객이 들어올 때
public void refresh() {
for (int i = 0; i < allCustomers.size(); i++) {
Customer customer = allCustomers.get(i);
customer.setGroup(findGroupByCustomer(customer));
}
}
public Group findGroupByCustomer(Customer customer) {
int totalPay = customer.getTotalPay();
int totalTime = customer.getTotalTime();
for (int i = allGroups.size() - 1; i >= 0; i--) {
Group group = allGroups.get(i);
if (totalPay >= group.getParameter().getMinimumTotalPay() && totalTime >= group.getParameter().getMinimumSpentTime()) {
return group;
}
}
return null;
}
}