package jp.ne.naokiur.design.pattern.iterator;

import java.util.Arrays;
import java.util.List;

public class App {

    public static void main(String[] args) {
        // These codes is wrong pattern according to OOP begin.
        // I think that the top of reason is if we need to modify the method,
        // we need to modify App class despite we should modify List<Employee>.
        List<Employee> employees = Arrays.asList(new Employee("john", "John", "Smith", 24), new Employee("jane", "Jane", "Smith", 22));

        // This is assumption of Requirement that We need to search first of target age employee.
        Employee matchedEmployee = searchTargetAgeEmployee(employees, 22);

        System.out.println(matchedEmployee.getFirstName() + " " + matchedEmployee.getLastName());
        // These codes is wrong pattern according to OOP end.

        // Try to Iterator pattern begin.
        EmployeeMember employeeMember = new EmployeeMember(Arrays.asList(new Employee("john", "John", "Smith", 24), new Employee("jane", "Jane", "Smith", 22)));
        
        
        // Try to Iterator pattern end.
    }

    /**
     * This is wrong method because App class should not have this responsibility.
     * List<Employee> should have this responsibility.
     *
     * @param employees
     * @param targetAge
     * @return
     */
    private static Employee searchTargetAgeEmployee(List<Employee> employees, int targetAge) {
        for (Employee employee : employees) {
            if (employee.getAge() == targetAge) {
                return employee;
            }
        }

        return new Employee("", "", "", 0);
    }
}

@@ -351,36 +351,42 @@
  we 
-sh
+w
 ould 
-modify List%3CEmployee%3E
+not like to modify App class
 .%0A  
@@ -508,24 +508,65 @@
 e%22, %22Smith%22,
+ 22), new Employee(%22bob%22, %22Bob%22, %22Smith%22,
  22));%0A%0A    
@@ -676,17 +676,206 @@
 mployee 
-m
+firstMatchedEmployee = searchTargetAgeEmployeeFirstly(employees, 22);%0A%0A        // This is assumption of Requirement that We need to search last of target age employee.%0A        Employee lastM
 atchedEm
@@ -906,16 +906,20 @@
 Employee
+Last
 (employe
@@ -955,17 +955,22 @@
 println(
-m
+firstM
 atchedEm
@@ -994,18 +994,43 @@
 me()
- + %22 %22 + m
+);%0A        System.out.println(lastM
 atch
@@ -1043,18 +1043,19 @@
 oyee.get
-La
+Fir
 stName()
@@ -1323,33 +1323,17 @@
  22)));%0A
-        %0A        
+%0A
 %0A       
@@ -1474,54 +1474,69 @@
   * 
-List%3CEmployee%3E should have this responsibility
+Reason of needing to create this method is Wrong class design
 .%0A  
@@ -1662,16 +1662,23 @@
 Employee
+Firstly
 (List%3CEm
@@ -1916,11 +1916,640 @@
 );%0A    %7D
+%0A%0A    /**%0A     * This is wrong method because App class should not have this responsibility.%0A     * Reason of needing to create this method is Wrong class design.%0A     *%0A     * @param employees%0A     * @param targetAge%0A     * @return Matched last employee. There is possibility of %3Cnull%3E.%0A     */%0A    private static Employee searchTargetAgeEmployeeLast(List%3CEmployee%3E employees, int targetAge) %7B%0A        Employee lastEmployee = null;%0A        for (Employee employee : employees) %7B%0A            if (employee.getAge() == targetAge) %7B%0A                lastEmployee = employee;%0A            %7D%0A        %7D%0A%0A        return lastEmployee;%0A    %7D
 %0A%7D%0A

Add wrong Exapmle for Iterator pattern.