// Exercise 2: Collectors.groupingBy and joining, method references (medium)
//
// Given a list of words, implement:
//   - groupByLength(words): Map<Integer, List<String>> — group words by
//     their length, using a method reference for the classifier.
//   - joinSorted(words, delimiter): sort words alphabetically, then join
//     them with `delimiter` into a single String, via Collectors.joining.

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class java_streams_and_lambdas_exercise_2 {

    static Map<Integer, List<String>> groupByLength(List<String> words) {
        // TODO: implement using .stream().collect(Collectors.groupingBy(String::length))
        return null;
    }

    static String joinSorted(List<String> words, String delimiter) {
        // TODO: implement using .stream().sorted().collect(Collectors.joining(delimiter))
        return null;
    }

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

        List<String> words = List.of("cat", "dog", "ant", "lion", "owl");
        Map<Integer, List<String>> byLength = groupByLength(words);
        ok &= byLength.get(3).equals(List.of("cat", "dog", "ant", "owl"));
        ok &= byLength.get(4).equals(List.of("lion"));
        ok &= byLength.get(3).size() == 4;

        ok &= joinSorted(List.of("banana", "apple", "cherry"), ", ").equals("apple, banana, cherry");
        ok &= joinSorted(List.of("z", "a", "m"), "-").equals("a-m-z");

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