forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
5 changed files
with
541 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
guest/core-java/src/main/java/com/stackify/stream/Employee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
guest/core-java/src/main/java/com/stackify/stream/EmployeeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.