public virtual Dictionary <string, List <EmployeeComponent> > FindEmployeeWithSalaryHigherThan(int salary, Dictionary <string, List <EmployeeComponent> > withHighestSalaryList = null) { if (withHighestSalaryList == null) { withHighestSalaryList = new Dictionary <string, List <EmployeeComponent> >(); } if (Salary > salary) { if (!withHighestSalaryList.ContainsKey(Position)) { List <EmployeeComponent> employees = new List <EmployeeComponent> { this }; withHighestSalaryList.Add(Position, employees); } else { withHighestSalaryList[Position].Add(this); } } IEnumerator iterator = CreateIterator(); bool hasNext = iterator.MoveNext(); while (hasNext) { EmployeeComponent employee = (EmployeeComponent)iterator.Current; withHighestSalaryList = employee.FindEmployeeWithSalaryHigherThan(salary, withHighestSalaryList); hasNext = iterator.MoveNext(); } return(withHighestSalaryList); }
public void PrintAllWithHighestSalaryAndHigherThan(int salary) { _output.Print($"There are all employees with salary higher than {salary}:"); Dictionary <string, List <EmployeeComponent> > withHighestSalaryList = _root.FindEmployeeWithSalaryHigherThan(salary); foreach (KeyValuePair <string, List <EmployeeComponent> > keyValue in withHighestSalaryList) { IEnumerable <EmployeeComponent> withTheHighestSalaries = keyValue.Value.Where(x => x.Salary == keyValue.Value.Max(y => y.Salary)); _output.Print($"Position: {keyValue.Key}."); foreach (EmployeeComponent withTheHighestSalary in withTheHighestSalaries) { _output.Print($"\tName: {withTheHighestSalary.Name}. Salary: {withTheHighestSalary.Salary}"); } } }