Stream API Collectors.groupingBy(...) как сгруппировать

Мне нужно сгруппировать поток так, чтобы каждой категории соответствовали определенные объекты товаров. Но как без понятия(

public class Main {

    @ProductCategory(category = ClothesCategory.class)
    private Product hat = new Product("Texas hat", 5, 50);

    @ProductCategory(category = FoodCategory.class)
    private Product meat = new Product("Beef", 3, 10);

    @ProductCategory(category = ToyCategory.class)
    private Product toy = new Product("Teddy bear", 1, 20);

    private Product product = new Product("Product", 100, 0);


    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

        ClassFinder classFinder = new ClassFinderImpl();
        Catalog catalog = new Catalog();

        catalog.setCategories(new HashSet<>(classFinder.find("ccom.example")));


    }

    private static Map<Class<?>, List<Product>> getProducts() throws IllegalAccessException {

        Field[] fields = Main.class.getDeclaredFields();

        Map<Class<?>, List<Field>> fieldsList = Arrays.stream(fields)
                .filter(f -> f.isAnnotationPresent(ProductCategory.class))
                .collect(Collectors.groupingBy(f -> f.getAnnotation(ProductCategory.class).category()));


        return null;
    }
}

ClassFinder просто собирает все классы из определенного пакета. В моем приложении в пакете лежат категории, например:

public class FoodCategory {

    private final String title = "Food";

    @Override
    public int hashCode() {
        return Objects.hash(title);
    }

    public String getTitle() {
        return title;
    }

    @Override
    public String toString() {
        return "FoodCategory{" +
                "title='" + title + '\'' +
                '}';
    }
}

Ответы (0 шт):