From a5bc59b03fa184656738be7e391da5f300c1bdee Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sat, 23 Jul 2022 10:41:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=D0=BE=D0=B2=20=D1=81=D0=BE=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D0=BC=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/debugger/seven/Employee.java | 89 +++++++++++++++++++ .../example/debugger/seven/StreamMain.java | 41 +++++++++ 2 files changed, 130 insertions(+) create mode 100644 src/main/java/dev/struchkov/example/debugger/seven/Employee.java create mode 100644 src/main/java/dev/struchkov/example/debugger/seven/StreamMain.java diff --git a/src/main/java/dev/struchkov/example/debugger/seven/Employee.java b/src/main/java/dev/struchkov/example/debugger/seven/Employee.java new file mode 100644 index 0000000..4c373c9 --- /dev/null +++ b/src/main/java/dev/struchkov/example/debugger/seven/Employee.java @@ -0,0 +1,89 @@ +package dev.struchkov.example.debugger.seven; + +public class Employee { + + private String firstName; + private String lastName; + private Integer age; + private Integer salary; + private Position position; + + public Employee(String firstName, String lastName, Integer age, Integer salary, Position position) { + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + this.salary = salary; + this.position = position; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public Position getPosition() { + return position; + } + + public void setPosition(Position position) { + this.position = position; + } + + public Integer getSalary() { + return salary; + } + + public void setSalary(Integer salary) { + this.salary = salary; + } + + @Override + public String toString() { + return position + " " + firstName + " " + lastName + " " + age + " лет, зарплата: " + salary; + } + + public static Employee of(String firstName, String lastName, Integer age, Integer salary, Position position) { + return new Employee(firstName, lastName, age, salary, position); + } + + public enum Position { + DEV("Разработчик"), + ACCOUNTANT("Бухгалтер"), + BOSS("Начальник отдела"); + + private final String title; + + Position(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + @Override + public String toString() { + return title; + } + } + +} \ No newline at end of file diff --git a/src/main/java/dev/struchkov/example/debugger/seven/StreamMain.java b/src/main/java/dev/struchkov/example/debugger/seven/StreamMain.java new file mode 100644 index 0000000..0ed3e92 --- /dev/null +++ b/src/main/java/dev/struchkov/example/debugger/seven/StreamMain.java @@ -0,0 +1,41 @@ +package dev.struchkov.example.debugger.seven; + +import dev.struchkov.example.debugger.seven.Employee.Position; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import static dev.struchkov.example.debugger.seven.Employee.Position.ACCOUNTANT; +import static dev.struchkov.example.debugger.seven.Employee.Position.BOSS; +import static dev.struchkov.example.debugger.seven.Employee.Position.DEV; + +public class StreamMain { + + public static void main(String[] args) { + + final List employees = List.of( + Employee.of("Екатерина", "Козлова", 28, 2_000_000, BOSS), + Employee.of("Алексей", "Кузнецов", 45, 90_000, ACCOUNTANT), + Employee.of("Юлия", "Козлова", 18, 35_000, ACCOUNTANT), + Employee.of("Никита", "Васильев", 22, 110_000, DEV), + Employee.of("Иван", "Иванов", 30, 300_000, DEV), + Employee.of("Анна", "Ермолова", 45, null, DEV), + Employee.of("Ирина", "Колесникова", 35, 200_000, DEV) + ); + + final Set devs = employees.stream() + .filter(employee -> DEV.equals(employee.getPosition())) + .filter(employee -> employee.getSalary() != null) + .filter(employee -> employee.getSalary() > 150_000) + .map(Employee::getLastName) + .collect(Collectors.toSet()); + + final Map> collect = employees.stream() + .filter(employee -> employee.getSalary() != null) + .collect(Collectors.groupingBy(Employee::getPosition)); + + } + +}