Skip to content

Commit 0094a87

Browse files
rockoderpivovarit
authored andcommitted
Java8 stream (eugenp#3585)
* java 8 stream code so far * more examples * code change * fix test names * fix unit test * move code to correct location * more unit tests * more tests
1 parent bfdc171 commit 0094a87

5 files changed

Lines changed: 541 additions & 0 deletions

File tree

guest/core-java/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@
1616
<artifactId>log4j-core</artifactId>
1717
<version>${log4j2.version}</version>
1818
</dependency>
19+
<dependency>
20+
<groupId>org.hamcrest</groupId>
21+
<artifactId>hamcrest-core</artifactId>
22+
<version>${org.hamcrest.version}</version>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.hamcrest</groupId>
27+
<artifactId>hamcrest-library</artifactId>
28+
<version>${org.hamcrest.version}</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.hamcrest</groupId>
33+
<artifactId>hamcrest-all</artifactId>
34+
<version>${org.hamcrest.version}</version>
35+
<scope>test</scope>
36+
</dependency>
1937
</dependencies>
2038

2139
<build>
@@ -32,5 +50,6 @@
3250
</build>
3351
<properties>
3452
<log4j2.version>2.8.2</log4j2.version>
53+
<org.hamcrest.version>1.3</org.hamcrest.version>
3554
</properties>
3655
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.stackify.stream;
2+
3+
public class Employee {
4+
private Integer id;
5+
private String name;
6+
private Double salary;
7+
8+
public Employee(Integer id, String name, Double salary) {
9+
this.id = id;
10+
this.name = name;
11+
this.salary = salary;
12+
}
13+
14+
public Integer getId() {
15+
return id;
16+
}
17+
18+
public void setId(Integer id) {
19+
this.id = id;
20+
}
21+
22+
public String getName() {
23+
return name;
24+
}
25+
26+
public void setName(String name) {
27+
this.name = name;
28+
}
29+
30+
public Double getSalary() {
31+
return salary;
32+
}
33+
34+
public void setSalary(Double salary) {
35+
this.salary = salary;
36+
}
37+
38+
public void salaryIncrement(Double percentage) {
39+
Double newSalary = salary + percentage * salary / 100;
40+
setSalary(newSalary);
41+
}
42+
43+
public String toString() {
44+
return "Id: " + id + " Name:" + name + " Price:" + salary;
45+
}
46+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.stackify.stream;
2+
3+
import java.util.List;
4+
5+
public class EmployeeRepository {
6+
private List<Employee> empList;
7+
8+
public EmployeeRepository(List<Employee> empList) {
9+
this.empList = empList;
10+
11+
}
12+
public Employee findById(Integer id) {
13+
for (Employee emp : empList) {
14+
if (emp.getId() == id) {
15+
return emp;
16+
}
17+
}
18+
19+
return null;
20+
}
21+
}

0 commit comments

Comments
 (0)