package organization; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.function.Predicate; import java.util.stream.Stream; import util.Gender; /** * This class represents an employee in a supervisory role. This means that this * employee supervises at least one other employee */ public class Supervisor extends GenericEmployee { private List supervisee; public Supervisor(String name, double pay, Gender gender) { super(name, pay, gender); supervisee = new LinkedList(); } @Override public Employee addSupervisee(String supervisorName, Employee supervisee) { if (this.name.equals(supervisorName)) { this.supervisee.add(supervisee); return this; } for (int i = 0; i < this.supervisee.size(); i++) { this.supervisee.set( i, this.supervisee.get(i).addSupervisee(supervisorName, supervisee)); } return this; } @Override public int count(Predicate condition) { Stream stream = this.supervisee.stream(); return this.supervisee.stream() .mapToInt(b -> b.count(condition)) .sum() + super.count(condition); } @Override public List toList() { List result = new ArrayList(); result.add(this); for (Employee e : supervisee) { result.addAll(e.toList()); } return result; } }