|
1 | 1 | package io.intercom.api; |
2 | 2 |
|
| 3 | +import com.google.common.collect.Lists; |
| 4 | + |
3 | 5 | import java.util.Iterator; |
4 | 6 | import java.util.List; |
5 | 7 |
|
6 | | -import com.google.common.collect.Lists; |
7 | | - |
8 | 8 | class CompanyUpdateBuilder { |
9 | 9 |
|
10 | | - /** |
11 | | - * Provide restrictions on the company data that can be sent via a user |
12 | | - * update |
13 | | - */ |
14 | | - static List<CompanyWithStringPlan> buildUserUpdateCompanies(CompanyCollection add, CompanyCollection remove) { |
| 10 | + /** |
| 11 | + * Provide restrictions on the company data that can be sent via a user update |
| 12 | + */ |
| 13 | + static List<CompanyWithStringPlan> buildUserUpdateCompanies(CompanyCollection add, CompanyCollection remove) { |
15 | 14 |
|
16 | | - final List<CompanyWithStringPlan> updatableCompanies = Lists.newArrayList(); |
17 | | - if (add != null) { |
18 | | - final List<Company> companies = add.getPage(); |
19 | | - for (Company company : companies) { |
20 | | - updatableCompanies.add(prepareUpdatableCompany(company)); |
21 | | - } |
22 | | - } |
| 15 | + final List<CompanyWithStringPlan> updatableCompanies = Lists.newArrayList(); |
| 16 | + if (add != null) { |
| 17 | + final List<Company> companies = add.getPage(); |
| 18 | + for (Company company : companies) { |
| 19 | + updatableCompanies.add(prepareUpdatableCompany(company)); |
| 20 | + } |
| 21 | + } |
23 | 22 |
|
24 | | - if (remove != null) { |
25 | | - final List<Company> companies = remove.getPage(); |
| 23 | + if (remove != null) { |
| 24 | + final List<Company> companies = remove.getPage(); |
26 | 25 |
|
27 | | - for (Company company : companies) { |
28 | | - removeCompanyFromAddedList(updatableCompanies, company); |
29 | | - updatableCompanies.add(prepareUpdatableCompany(company).setRemove(Boolean.TRUE)); |
30 | | - } |
31 | | - } |
| 26 | + for (Company company : companies) { |
| 27 | + removeCompanyFromAddedList(updatableCompanies, company); |
| 28 | + updatableCompanies.add(prepareUpdatableCompany(company).setRemove(Boolean.TRUE)); |
| 29 | + } |
| 30 | + } |
32 | 31 |
|
33 | | - return updatableCompanies; |
34 | | - } |
| 32 | + return updatableCompanies; |
| 33 | + } |
35 | 34 |
|
36 | | - private static void removeCompanyFromAddedList(List<CompanyWithStringPlan> companies, Company company) { |
37 | | - Iterator<CompanyWithStringPlan> companyIterator = companies.iterator(); |
| 35 | + private static void removeCompanyFromAddedList(List<CompanyWithStringPlan> companies, Company company) { |
| 36 | + Iterator<CompanyWithStringPlan> companyIterator = companies.iterator(); |
38 | 37 |
|
39 | | - while (companyIterator.hasNext()) { |
40 | | - CompanyWithStringPlan companyWithStringPlan = companyIterator.next(); |
41 | | - // TODO add equals and toHash methods to CompanyWithStringPlan and |
42 | | - // use it here |
43 | | - if (companyWithStringPlan.getId() != null && company.getId() != null && companyWithStringPlan.getId().equals(company.getId())) { |
44 | | - companyIterator.remove(); |
45 | | - break; |
46 | | - } |
| 38 | + while (companyIterator.hasNext()) { |
| 39 | + CompanyWithStringPlan companyWithStringPlan = companyIterator.next(); |
| 40 | + // TODO add equals and toHash methods to CompanyWithStringPlan and use it here |
| 41 | + if (companyWithStringPlan.getId() != null && company.getId() != null && companyWithStringPlan.getId().equals(company.getId())) { |
| 42 | + companyIterator.remove(); |
| 43 | + break; |
| 44 | + } |
47 | 45 |
|
48 | | - if (companyWithStringPlan.getCompanyID() != null && company.getCompanyID() != null && companyWithStringPlan.getCompanyID().equals(company.getCompanyID())) { |
49 | | - companyIterator.remove(); |
50 | | - break; |
51 | | - } |
52 | | - } |
53 | | - } |
| 46 | + if (companyWithStringPlan.getCompanyID() != null && company.getCompanyID() != null && companyWithStringPlan.getCompanyID().equals(company.getCompanyID())) { |
| 47 | + companyIterator.remove(); |
| 48 | + break; |
| 49 | + } |
| 50 | + } |
| 51 | + } |
54 | 52 |
|
55 | | - private static CompanyWithStringPlan prepareUpdatableCompany(Company company) { |
56 | | - final CompanyWithStringPlan updatableCompany = new CompanyWithStringPlan(); |
57 | | - updatableCompany.setId(company.getId()); |
58 | | - updatableCompany.setCompanyID(company.getCompanyID()); |
59 | | - updatableCompany.setName(company.getName()); |
60 | | - updatableCompany.setSessionCount(company.getSessionCount()); |
61 | | - updatableCompany.setMonthlySpend(company.getMonthlySpend()); |
62 | | - updatableCompany.setRemoteCreatedAt(company.getRemoteCreatedAt()); |
63 | | - if (company.getPlan() != null) { |
64 | | - updatableCompany.setPlan(company.getPlan().getName()); |
65 | | - } |
66 | | - return updatableCompany; |
67 | | - } |
| 53 | + private static CompanyWithStringPlan prepareUpdatableCompany(Company company) { |
| 54 | + final CompanyWithStringPlan updatableCompany = new CompanyWithStringPlan(); |
| 55 | + updatableCompany.setId(company.getId()); |
| 56 | + updatableCompany.setCompanyID(company.getCompanyID()); |
| 57 | + updatableCompany.setName(company.getName()); |
| 58 | + updatableCompany.setSessionCount(company.getSessionCount()); |
| 59 | + updatableCompany.setMonthlySpend(company.getMonthlySpend()); |
| 60 | + updatableCompany.setRemoteCreatedAt(company.getRemoteCreatedAt()); |
| 61 | + if (company.getPlan() != null) { |
| 62 | + updatableCompany.setPlan(company.getPlan().getName()); |
| 63 | + } |
| 64 | + return updatableCompany; |
| 65 | + } |
68 | 66 | } |
0 commit comments