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
import java.util.Objects; | |
public class Address { | |
private final String firstLine; | |
private final String secondLine; | |
private final String postCode; | |
public Address(String firstLine, String secondLine, String postCode) { | |
this.firstLine = firstLine; | |
this.secondLine = secondLine; |
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
package com.theboreddev.java14; | |
import java.util.Objects; | |
public class Employee { | |
private final String firstName; | |
private final String surname; | |
private final int age; | |
private final Address address; | |
private final double salary; |
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
final Collection<Employee> employees = List.of( | |
new Employee("Karen Smith", 51200.0, 29, Employee.Sex.FEMALE), | |
new Employee("John Smith", 24000.0, 32, Employee.Sex.MALE), | |
new Employee("Anthony Jackson", 44000.0, 33, Employee.Sex.MALE), | |
new Employee("Alyson Palmer", 34320.0, 36, Employee.Sex.FEMALE), | |
new Employee("Jessica Sanders", 64320.0, 34, Employee.Sex.FEMALE) | |
); | |
final Map<Employee.Sex, List<Employee>> existingMap = new HashMap<>() { | |
{ |
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
final Map<Employee.Sex, List<Employee>> employeesOverThirtyBySex = employees.stream() | |
.collect(groupingBy(Employee::getSex, filtering(employee -> employee.getAge() > 30, toList()))); |
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
final Map<Employee.Sex, Optional<Employee>> youngestEmployeeBySex = employees.stream() | |
.collect(groupingBy(Employee::getSex, minBy(comparing(Employee::getAge)))); |
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
final Map<Employee.Sex, Map<Integer, List<Employee>>> groupBySexAndAge = employees.stream() | |
.collect(groupingBy(Employee::getSex, groupingBy(Employee::getAge))); |
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
final Map<Employee.Sex, Double> averageAgeBySex = employees.stream() | |
.collect(groupingBy(Employee::getSex, averagingInt(Employee::getAge))); |
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
final Map<Employee.Sex, Set<Employee>> employeesBySex = employees.stream() | |
.collect(groupingBy(Employee::getSex, toSet())); |
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
final Collection<Employee> employees = List.of( | |
new Employee("Karen Smith", 51200.0, 29, Employee.Sex.FEMALE), | |
new Employee("John Smith", 24000.0, 32, Employee.Sex.MALE), | |
new Employee("Anthony Jackson", 44000.0, 33, Employee.Sex.MALE), | |
new Employee("Alyson Palmer", 34320.0, 36, Employee.Sex.FEMALE), | |
new Employee("Jessica Sanders", 64320.0, 34, Employee.Sex.FEMALE) | |
); | |
final Map<Employee.Sex, List<Employee>> employeesBySex = employees.stream() | |
.collect(groupingBy(Employee::getSex)); |
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
package com.theboreddev.examples.forkjoin; | |
import java.util.concurrent.ForkJoinPool; | |
import java.util.concurrent.ForkJoinTask; | |
import java.util.concurrent.RecursiveTask; | |
public class ForkJoinExample { | |
public static void main(String[] args) { |