This seems like something that should have a standard solution, but I can't find what I'm looking for. It's not difficult to implement by hand, but perhaps I'm just missing a tool in my toolbox?
In pseudo-code, I want a set-like collection that, given existing entries
{id_1, v_1}, {id_2, v_2}
on calling addAll()
with
{id_1, v_2}, {id_2, v_1}
will be left with
{id_1, v_2}, {id_2, v_2}
i.e. original id_1 gets replaced with more recent version; original id_2 remains because it is more recent than the incoming one.
I had a look through Guava, but nothing jumped out at me. I'm not very familiar with Apache collections, perhaps something can be built out of that?
Thanks all