/home/oracle/labs/06CollectionOperations/examples/EmployeeSearch06/src/com/example/lambda/A06StreamData.java
 1 package com.example.lambda;
 2 
 3 import java.util.Comparator;
 4 import java.util.List;
 5 import java.util.Optional;
 6 
 7 /**
 8  *
 9  * @author oracle
10  */
11 public class A06StreamData {
12 
13   public static void main(String[] args) {
14         
15     List<Employee> eList = Employee.createShortList();
16                             
17     System.out.println("\n== Executive Count ==");
18     long execCount = 
19         eList.stream()
20           .filter(e -> e.getRole().equals(Role.EXECUTIVE))
21           .count();
22        
23     System.out.println("Exec count: " + execCount);
24         
25     System.out.println("\n== Highest Paid Exec ==");
26     Optional highestExec =
27       eList.stream()
28         .filter(e -> e.getRole().equals(Role.EXECUTIVE))
29         .max(Employee::sortBySalary);
30         
31     if (highestExec.isPresent()){
32       Employee temp = (Employee) highestExec.get();
33       System.out.printf(
34           "Name: " + temp.getGivenName() + " " 
35           + temp.getSurName() + "   Salary: $%,6.2f %n ", 
36           temp.getSalary()); 
37     }
38         
39     System.out.println("\n== Lowest Paid Staff ==");
40     Optional lowestStaff =
41         eList.stream()
42          .filter(e -> e.getRole().equals(Role.STAFF))
43          .min(Comparator.comparingDouble(e -> e.getSalary()));
44         
45     if (lowestStaff.isPresent()){
46       Employee temp = (Employee) lowestStaff.get();
47       System.out.printf("Name: " + temp.getGivenName() 
48         + " " + temp.getSurName() + 
49         "   Salary: $%,6.2f %n ", temp.getSalary());  
50     }   
51   }
52 }
53