Skip to content

Commit 264a53c

Browse files
committed
Add Employee model and utility classes for employee data processing
1 parent 97f656f commit 264a53c

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.superthirty;
2+
3+
import java.util.List;
4+
5+
public class AllEmployeesHavingEmailQ6 {
6+
public static void main(String[] args) {
7+
List<Employee> employees = EmployeeDTO.getEmployees();
8+
boolean isAllHaivngEmail = employees.stream().allMatch(x -> x.getEmail() != null);
9+
employees.stream().filter(x -> x.getEmail() == null).forEach(System.out::println);
10+
System.out.println(isAllHaivngEmail);
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.superthirty;
2+
3+
import java.util.List;
4+
5+
public class EmailActiveEmployeeQ7 {
6+
public static void main(String[] args) {
7+
List<Employee> employees = EmployeeDTO.getEmployees();
8+
employees.stream().filter(x -> x.isActive()).map(Employee::getName).forEach(System.out::println);
9+
}
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.superthirty;
2+
3+
import java.util.Comparator;
4+
import java.util.List;
5+
import java.util.Optional;
6+
7+
public class HighestSalary {
8+
public static void main(String[] args) {
9+
List<Employee> employees = EmployeeDTO.getEmployees();
10+
//First Approach Using sorted and findFirst
11+
String result = employees.stream()
12+
.sorted(Comparator.comparing(Employee::getSalary).reversed())
13+
.map(Employee::getName).toList().stream().findFirst().orElse(null);
14+
System.out.println(result);
15+
//Second Approach Using max
16+
17+
Optional<Employee> resultUsinngMax = employees.stream().max(Comparator.comparingDouble(Employee::getSalary));
18+
System.out.println(resultUsinngMax);
19+
}
20+
}

0 commit comments

Comments
 (0)