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