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 Item item = new Item(1L, new BigDecimal("12.99")); | |
| System.out.println("Delivery price is " + Plan.BASIC.deliveryPrice.apply(item)); | |
| System.out.println("Delivery price is " + Plan.PREMIUM.deliveryPrice.apply(item)); | |
| System.out.println("Delivery price is " + Plan.BUSINESS.deliveryPrice.apply(item)); |
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 Car car = new Car(); | |
| final CarWashStep chain = new InitialWashStep(); | |
| chain.andThen(new SoapStep()) | |
| .andThen(new RinseStep()) | |
| .andThen(new PolishStep()) | |
| .andThen(new DryStep()); | |
| final Car finalCar = chain.applyTo(car); |
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) { |
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
| 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 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, 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, 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, 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 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<>() { | |
| { |