Skip to content

Commit 6460e73

Browse files
committed
BAEL-2197: Initial Commit
1 parent 05e1700 commit 6460e73

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package findItems;
2+
3+
import static org.junit.Assert.*;
4+
import java.text.ParseException;
5+
import java.text.SimpleDateFormat;
6+
import java.util.ArrayList;
7+
import java.util.Collections;
8+
import java.util.Date;
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
import org.junit.Test;
12+
13+
public class FindItemsBasedOnValues {
14+
15+
static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");
16+
17+
public static void main(String[] args) throws ParseException {
18+
FindItemsBasedOnValues findItems = new FindItemsBasedOnValues();
19+
findItems.findItemsImpl();
20+
}
21+
22+
@Test
23+
public void findItemsImpl() throws ParseException {
24+
List<Client> expectedList = new ArrayList<Client>();
25+
Client expectedClient = new Client(1001, DATE_FORMAT.parse("01-02-2018"));
26+
expectedList.add(expectedClient);
27+
28+
List<Company> listOfCompanies = new ArrayList<Company>();
29+
List<Client> listOfClients = new ArrayList<Client>();
30+
populate(listOfCompanies, listOfClients);
31+
32+
List<Client> filteredList = listOfClients.stream()
33+
.filter(client -> listOfCompanies.stream()
34+
.anyMatch(company -> company.getType()
35+
.equals("eMart") && company.getProjectId()
36+
.equals(client.getProjectId()) && company.getStart()
37+
.after(client.getDate()) && company.getEnd()
38+
.before(client.getDate())))
39+
.collect(Collectors.toList());
40+
41+
assertEquals(expectedClient.getProjectId(), filteredList.get(0)
42+
.getProjectId());
43+
assertEquals(expectedClient.getDate(), filteredList.get(0)
44+
.getDate());
45+
}
46+
47+
private void populate(List<Company> companyList, List<Client> clientList) throws ParseException {
48+
Company company1 = new Company(1001, DATE_FORMAT.parse("01-03-2018"), DATE_FORMAT.parse("01-01-2018"), "eMart");
49+
Company company2 = new Company(1002, DATE_FORMAT.parse("01-02-2018"), DATE_FORMAT.parse("01-04-2018"), "commerce");
50+
Company company3 = new Company(1003, DATE_FORMAT.parse("01-06-2018"), DATE_FORMAT.parse("01-02-2018"), "eMart");
51+
Company company4 = new Company(1004, DATE_FORMAT.parse("01-03-2018"), DATE_FORMAT.parse("01-06-2018"), "blog");
52+
53+
Collections.addAll(companyList, company1, company2, company3, company4);
54+
55+
Client client1 = new Client(1001, DATE_FORMAT.parse("01-02-2018"));
56+
Client client2 = new Client(1003, DATE_FORMAT.parse("01-04-2018"));
57+
Client client3 = new Client(1005, DATE_FORMAT.parse("01-07-2018"));
58+
Client client4 = new Client(1007, DATE_FORMAT.parse("01-08-2018"));
59+
60+
Collections.addAll(clientList, client1, client2, client3, client4);
61+
}
62+
}
63+
64+
class Company {
65+
Long projectId;
66+
Date start;
67+
Date end;
68+
String type;
69+
70+
public Company(long projectId, Date start, Date end, String type) {
71+
super();
72+
this.projectId = projectId;
73+
this.start = start;
74+
this.end = end;
75+
this.type = type;
76+
}
77+
78+
public Long getProjectId() {
79+
return projectId;
80+
}
81+
82+
public Date getStart() {
83+
return start;
84+
}
85+
86+
public Date getEnd() {
87+
return end;
88+
}
89+
90+
public String getType() {
91+
return type;
92+
}
93+
94+
}
95+
96+
class Client {
97+
Long projectId;
98+
Date date;
99+
100+
public Client(long projectId, Date date) {
101+
super();
102+
this.projectId = projectId;
103+
this.date = date;
104+
}
105+
106+
public Long getProjectId() {
107+
return projectId;
108+
}
109+
110+
public Date getDate() {
111+
return date;
112+
}
113+
114+
}

0 commit comments

Comments
 (0)