I have a list of items that have an action. Currently, action property is set to null. What I want to do is copy the items in the list, change its action property to delete string and add it to a new list. I want to do it again with add. So the idea is to have list of same items but one with action delete and another with action add.
So have a list with items like this:
{
"someNumber": "123456",
"projectName": "Foo Bar",
"action": "delete"
},
{
"someNumber": "454546",
"projectName": "Foo Bar",
"action": "delete"
},
{
"someNumber": "123456",
"projectName": "Foo Bar",
"action": "add"
},
{
"someNumber": "454546",
"projectName": "Foo Bar",
"action": "add"
}
Where I duplicated the 2 items above that initially had action = null but now there's one for delete and add.
I have this code snippet here:
List<Leader> leadersToDeleteForUpdating = newLeaders.stream().filter(l-> !"add".equals(l.getAction()) && l.getEndDate() == null).collect(toList());
leadersToDeleteForUpdating.forEach(l->l.setAction("delete"));
List<Leader> leadersToAddForUpdating = newLeaders.stream().filter(l-> !"add".equals(l.getAction()) && l.getEndDate() == null).collect(toList());
leadersToAddForUpdating.forEach(l->l.setAction("add"));
List<Leader> leadersToDeleteAndAddForUpdating = new ArrayList<>(leadersToDeleteForUpdating);
leadersToDeleteAndAddForUpdating.addAll(leadersToAddForUpdating);
Right now, it's overriding the item values with action = add and the action = delete items are not copied over. What am I doing wrong in this case?