I have Map<String,List<Object>>
and for each key
i need to filter the List<Object>
. When performing the filter, I need to remove items from the List<Object>
.
I can iterate over the map and remove the elements that I want however, I also need to keep track of the elements that I have removed. I want the filter function to be simple and only filter, in which case you would always get a Map<String,List<Object>>
with the filtered values. The problem is, how can I know which records have been removed?.
I can write another function to return the items which are discarded but this would mean that I would iterate twice over the same data structure. Or I can have variables inside the filter which would store the values (and then I can retrieve) but this looks messy. (i could also use the collectionUtils disjunction function - another option)
Are there other ways/design patterns that i can use for implementation?