0

I have two multimaps with Ids and names, one is filled with information that i get from a remote service and the second has information that i have in my local database. I need to compare and synchronize them.

Multimap<Long, String> remote
Multimap<Long, String> localDB

We can assume that ids are always the same but names can vary, e.g:

remote = {1 = [Tom], 2 = [Bob , Ron], 3 = [Philip]}
local = {1 = [Tom], 2 = [Johan, Robert], 3 = [Susan]}

And what i expect to get is:

local = {1 = [Tom], 2 = [Bob , Ron], 3 = [Philip]}

how can i get it?

1 Answers1

0

Extending the options from the comments above and assuming you'll just sync remote to local you have at least three different options:

  • set one list itself on another: local = remote;
  • remove all values from local which are not in remote and then do local.putAll(remote);
  • copy the contents from remote to local: local = ImmutableListMultimap.copyOf(remote);
mle
  • 2,466
  • 1
  • 19
  • 25