How to use stream functions to collapse objects with same atributte name?

Viewed 34

Trying to learning how to use stream reduce() filter().

I have a list of Tag objects:

Public class Tag {
    Private String name;
    Private list<Occurrence> occurences;
    ...
}


Public class Occurrence{
    Private int number;
    Private LocalDateTime timestamp;
    ...
}

Then, I want to collapse occurrences from Tags with the same name, like:

{
"name" : "Delivered",
[
"number" : 1,
"timestamp" "",
...
]
[
"number" : 2,
"timestamp" "",
...
]
}
{
"name" : "Delivered",
[
"number" : 3,
"timestamp" "",
...
]
}
{
"name" : "bounced",
[
"number" : 1,
"timestamp" "",
...
]
}

When I read the json I get duplicate Tags "Delivered".

How can I use stream functions to get this List and collapse occurrences with the same tag name?

0 Answers
Related