-
Notifications
You must be signed in to change notification settings - Fork 103
Lesson 58 (collection lambda param) #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Binary-Cat-01
wants to merge
3
commits into
KFalcon2022:for-pr
Choose a base branch
from
Binary-Cat-01:lesson_58_collection_lambda_param
base: for-pr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/com/walking/lesson58_collection_lamda_param/model/Department.java
This file contains hidden or 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,33 @@ | ||
| package com.walking.lesson58_collection_lamda_param.model; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Department { | ||
| private String name; | ||
| private int vacancyAmount; | ||
| private List<Employee> employees; | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public int getVacancyAmount() { | ||
| return vacancyAmount; | ||
| } | ||
|
|
||
| public void setVacancyAmount(int vacancyAmount) { | ||
| this.vacancyAmount = vacancyAmount; | ||
| } | ||
|
|
||
| public List<Employee> getEmployees() { | ||
| return employees; | ||
| } | ||
|
|
||
| public void setEmployees(List<Employee> employees) { | ||
| this.employees = employees; | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
src/com/walking/lesson58_collection_lamda_param/model/Employee.java
This file contains hidden or 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,64 @@ | ||
| package com.walking.lesson58_collection_lamda_param.model; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Employee { | ||
| private String name; | ||
| private boolean isMale; | ||
| private String position; | ||
| private int age; | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public boolean isMale() { | ||
| return isMale; | ||
| } | ||
|
|
||
| public void setMale(boolean male) { | ||
| isMale = male; | ||
| } | ||
|
|
||
| public String getPosition() { | ||
| return position; | ||
| } | ||
|
|
||
| public void setPosition(String position) { | ||
| this.position = position; | ||
| } | ||
|
|
||
| public int getAge() { | ||
| return age; | ||
| } | ||
|
|
||
| public void setAge(int age) { | ||
| this.age = age; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| Employee employee = (Employee) o; | ||
| return isMale == employee.isMale && age == employee.age && Objects.equals(name, | ||
| employee.name); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| int result = Objects.hashCode(name); | ||
| result = 31 * result + Boolean.hashCode(isMale); | ||
| result = 31 * result + age; | ||
| return result; | ||
| } | ||
| } |
This file contains hidden or 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
16 changes: 16 additions & 0 deletions
16
src/com/walking/lesson58_collection_lamda_param/task2/Main.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,10 +1,26 @@ | ||
| package com.walking.lesson58_collection_lamda_param.task2; | ||
|
|
||
| import com.walking.lesson58_collection_lamda_param.model.Employee; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Используя классы из практики к уроку 57, реализуйте метод, | ||
| * принимающий на вход список сотрудников и возвращающий список обладателей каждого имени. | ||
| */ | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
| } | ||
|
|
||
| public static Map<String, List<Employee>> getAllEmployeesByName(List<Employee> employees) { | ||
| Map<String, List<Employee>> employeeMap = new HashMap<>(); | ||
|
|
||
| employees.forEach(e -> employeeMap.computeIfAbsent(e.getName(), k -> new ArrayList<>()) | ||
| .add(e)); | ||
|
|
||
| return employeeMap; | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
как будто через compute() проще