The question is largely in the title. I am looking for an algorithm that is more efficient than a complete search through collections.
I have two collections:
List<Map<TypeId, Object> > col1; List<Entity> col2;
Where
public enum TypeId{ PLAYER, PARTNER, PLATFORM, AMOUNT }
and
public class Entity{ private int player_id; private int platform_id private BigDecimal amount;
The col1 collection, which is of type List<Map<TypeId, Object> > , contains only PLAYER, PARTNER, PLATFORM TypeId s.
I need to write a method:
public List<Map<TypeId, Object> > merge(List<Map<TypeId, Object> > col1, List<Entity> col2){
What List<Map<TypeId, Object> > will create, each entry on the map contains an additional key value (AMOUNT, AMOUNT value) , where AMOUNT value is the value of the amount field of the e of Entity instance if e.player_id = entry.get(PLAYER) && e.platform_id = entry.get(PLATFORM) and null otherwise.
In fact, the operation will be the same as
col1 LEFT OUTER JOIN col2 ON e.player_id = entry.get(PLAYER) && e.platform_id = entry.get(PLATFORM)
SAMPLE:
col1: [{PLATFORM: 1, PARTNER: 1, PLAYER: 1}, {PLATFORM: 1, PARTNER: 3, PLAYER: 1}, {PLATFORM: 2, PARTNER: 1, PLAYER: 2} {PLATFORM: 3, PARTNER: 4, PLAYER: 5}] col2: [Entity(platform_id = 1, player_id = 1, amount = 100), Entity(platform_id = 2, player_id = 2, amount = 200), Entity(platform_id = 3, player_id = 4, amount = 300)] result: [{PLATFORM: 1, PARTNER: 1, PLAYER: 1, AMOUNT: 100}, {PLATFORM: 1, PARTNER: 3, PLAYER: 1, AMOUNT: 100}, {PLATFORM: 2, PARTNER: 1, PLAYER: 2, AMOUNT: 200}, {PLATFORM: 3, PARTNER: 4, PLAYER: 5, AMOUNT: null}]