Java Stream Issue

I have a problem about writing a java stream by filtering multiple conditions , groupby multiple condition (if possible) and calculating the sum value

I store the values as Map<String(pId),List<Person>>

Here is my Person class shown below
    public class Person{
    
        private String id;
        private Statement event; // STATUS1,STATUS2
        private LocalDate eventDate;
        private Object value;
    }

Here is the list
    ID,Info,Date,Value (All values are stored in Person object defined in the List)
    
    per1, STATUS1,  10-01-2022, 1
    per2, STATUS2, 10-01-2022, 2
    per3, STATUS3, 10-01-2022, 3 
    per1 STATUS1, 10-02-2022, 1
    per2, STATUS1, 10-03-2022, 1
    per3, STATUS2, 10-03-2022, 2
    ...
    ...

What I want to do is to get this result.
    Month |  Total Sum | Person Count
    1        6          3
    2        1          1
    3        3          2

Here is group dto shown below
    public class GroupDto {
            private int month;
    }

Here is my dto shown below.
    public class DTO {
        private int month;
        private int totalSum; 
        private int totalPersons;  
    }

Here is the code snippet but I cannot complete it.
    List<DTO > result = persons .values().stream()
                .flatMap(List::stream)
                .filter(person -> person .getInfo() == Value.STATUS1|| person .getInfo() == Value.STATUS2 || person .getInfo() == Value.STATUS3)
                .collect(Collectors.groupingBy(
                        p -> new GroupDto(p.getEventDate().getMonthValue())  // CANNOT COMPLETE
                ))
                .entrySet().stream()
                .map(entry -> new DTO(entry.getKey().getMonth(), ....) // CANNOT COMPLETE
                .sorted(Comparator.comparing(DTO::getMonth))
                .toList();

How can I do that?
Was this page helpful?