-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomers.java
47 lines (37 loc) · 1.25 KB
/
Customers.java
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 com.smartstore.customer;
import com.smartstore.util.CustomList;
import java.util.Arrays;
import java.util.Optional;
public class Customers {
private static Customers instance;
private Customers() {
}
public static Customers getInstance(){
if(instance == null){
instance = new Customers();
}
return instance;
}
private final CustomList<Customer> customerList = new CustomList();
public CustomList<Customer> getCustomerList() {
return customerList;
}
public Customer getCustomerById(String id){
if(customerList.size() == 0){
return null;
}
Optional<Customer> customerOptional = Arrays.stream(customerList.toArray(new Customer[customerList.size()]))
.filter(customer -> id.equals(customer.getCustomerId()))
.findFirst();
return customerOptional.orElse(null);
}
public void updateMembership(){
if(customerList.size() == 0){
return;
}
Customer[] customerArray = customerList.toArray(new Customer[customerList.size()]);
for(Customer customer : customerArray){
customer.setMembership(customer.getUsageTime(), customer.getPaymentAmount());
}
}
}