// Exercise 1: List basics — ArrayList operations and safe iteration/removal
//
// Implement the three methods below.

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class java_collections_framework_exercise_1 {

    /**
     * Return a new List containing only the EVEN numbers from `input`,
     * preserving order. Do not mutate `input`.
     */
    static List<Integer> filterEven(List<Integer> input) {
        // TODO: implement
        return null;
    }

    /**
     * Remove all occurrences of `target` from `list` IN PLACE, using an
     * Iterator (not list.remove() inside a for-each, which would throw
     * ConcurrentModificationException). Return the same list reference.
     */
    static List<Integer> removeAllInPlace(List<Integer> list, int target) {
        // TODO: implement using Iterator.remove()
        return list;
    }

    /**
     * Insert `value` at `index` in `list`, shifting subsequent elements
     * right. Return the same list reference.
     */
    static List<Integer> insertAt(List<Integer> list, int index, int value) {
        // TODO: implement
        return list;
    }

    // --- self-check: do not modify below this line ---
    public static void main(String[] args) {
        boolean ok = true;

        List<Integer> nums = new ArrayList<>(List.of(1, 2, 3, 4, 5, 6));
        List<Integer> evens = filterEven(nums);
        ok &= evens.equals(List.of(2, 4, 6));
        ok &= nums.size() == 6; // original untouched

        List<Integer> toClean = new ArrayList<>(List.of(1, 2, 3, 2, 4, 2));
        removeAllInPlace(toClean, 2);
        ok &= toClean.equals(List.of(1, 3, 4));

        List<Integer> toInsert = new ArrayList<>(List.of(1, 2, 4, 5));
        insertAt(toInsert, 2, 3);
        ok &= toInsert.equals(List.of(1, 2, 3, 4, 5));

        System.out.println(ok ? "PASS" : "FAIL");
    }
}
