Skip to content

Commit

Permalink
Java8 stream (eugenp#3585)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rockoder authored and pivovarit committed Feb 24, 2018
1 parent bfdc171 commit 0094a87
Show file tree
Hide file tree
Showing 5 changed files with 541 additions and 0 deletions.
19 changes: 19 additions & 0 deletions guest/core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${org.hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${org.hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${org.hamcrest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -32,5 +50,6 @@
</build>
<properties>
<log4j2.version>2.8.2</log4j2.version>
<org.hamcrest.version>1.3</org.hamcrest.version>
</properties>
</project>
46 changes: 46 additions & 0 deletions guest/core-java/src/main/java/com/stackify/stream/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.stackify.stream;

public class Employee {
private Integer id;
private String name;
private Double salary;

public Employee(Integer id, String name, Double salary) {
this.id = id;
this.name = name;
this.salary = salary;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Double getSalary() {
return salary;
}

public void setSalary(Double salary) {
this.salary = salary;
}

public void salaryIncrement(Double percentage) {
Double newSalary = salary + percentage * salary / 100;
setSalary(newSalary);
}

public String toString() {
return "Id: " + id + " Name:" + name + " Price:" + salary;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.stackify.stream;

import java.util.List;

public class EmployeeRepository {
private List<Employee> empList;

public EmployeeRepository(List<Employee> empList) {
this.empList = empList;

}
public Employee findById(Integer id) {
for (Employee emp : empList) {
if (emp.getId() == id) {
return emp;
}
}

return null;
}
}
Loading

0 comments on commit 0094a87

Please sign in to comment.