// Exercise 1: generic class and generic method basics (easy)
//
// Implement:
//   - Pair<A, B>: a generic class holding two values of independent types,
//     with a swapped() method that returns a NEW Pair<B, A> with the
//     elements swapped (does not mutate this Pair).
//   - static <T> T lastOf(List<T> list): a generic method returning the
//     last element of any list, regardless of element type.

import java.util.List;

public class java_generics_exercise_1 {

    static class Pair<A, B> {
        private final A first;
        private final B second;

        Pair(A first, B second) {
            this.first = first;
            this.second = second;
        }

        A getFirst() { return first; }
        B getSecond() { return second; }

        /** Return a NEW Pair<B, A> with first/second swapped. Do not mutate this Pair. */
        Pair<B, A> swapped() {
            // TODO: implement
            return null;
        }
    }

    /** Return the last element of `list`. Works for a List of any type T. */
    static <T> T lastOf(List<T> list) {
        // TODO: implement
        return null;
    }

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

        Pair<String, Integer> age = new Pair<>("age", 30);
        ok &= age.getFirst().equals("age");
        ok &= age.getSecond().equals(30);

        Pair<Integer, String> swapped = age.swapped();
        ok &= swapped.getFirst().equals(30);
        ok &= swapped.getSecond().equals("age");
        // original must be untouched
        ok &= age.getFirst().equals("age");
        ok &= age.getSecond().equals(30);

        ok &= lastOf(List.of("a", "b", "c")).equals("c");
        ok &= lastOf(List.of(1, 2, 3, 4)).equals(4);

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