Skip to content

Instantly share code, notes, and snippets.

View theboreddev's full-sized avatar
💭
💻

The Bored Dev theboreddev

💭
💻
View GitHub Profile
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;
@theboreddev
theboreddev / Employee.java
Created July 24, 2020 06:28
employee_before_java_14
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;
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<>() {
{
@theboreddev
theboreddev / GroupByClassifier.java
Created July 18, 2020 20:49
employeesOverThirtyBySex
final Map<Employee.Sex, List<Employee>> employeesOverThirtyBySex = employees.stream()
.collect(groupingBy(Employee::getSex, filtering(employee -> employee.getAge() > 30, toList())));
@theboreddev
theboreddev / GroupByClassifier.java
Created July 18, 2020 20:35
youngestEmployeeBySex
final Map<Employee.Sex, Optional<Employee>> youngestEmployeeBySex = employees.stream()
.collect(groupingBy(Employee::getSex, minBy(comparing(Employee::getAge))));
@theboreddev
theboreddev / GroupByClassifier.java
Created July 18, 2020 20:31
groupBySexAndAge groupBySexAndAge
final Map<Employee.Sex, Map<Integer, List<Employee>>> groupBySexAndAge = employees.stream()
.collect(groupingBy(Employee::getSex, groupingBy(Employee::getAge)));
final Map<Employee.Sex, Double> averageAgeBySex = employees.stream()
.collect(groupingBy(Employee::getSex, averagingInt(Employee::getAge)));
final Map<Employee.Sex, Set<Employee>> employeesBySex = employees.stream()
.collect(groupingBy(Employee::getSex, toSet()));
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));
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) {