Compare two list of objects and create a List<Map<String, obj>
where each Map has key "old" with value as oldObj and key "new" with value as newObj
Eg: First List of Objects is -> List<Company>
(Updated list)
class Company{
String region;
String code;
String type;
String contactPerson;
String startDate;
String endDate;
String field1;
String field2;
}
and second list is List<Company>
(old Values)
How to compare both the lists and form a List<Map<string, Company>
where each Map has key "old" with value as oldObj and key "new" with value as newObj where the fields to check for comparison are region, code, type.
eg:
List<Company> companyList = Arrays.asList( new Company("1", "100", "tier1", "bob", "2010", "20201"), new Company("1", "101", "tier1", "rick", "2010", "20201"), new Company("1", "101", "tier2", "personA", "2010", "20201"), new Company("2", "200", "tier3", "personC", "2010", "20201"))
List<Company> dbValues = Arrays.asList( new Company("1", "100", "tier1", "jenny", "2010", "20201"), new Company("1", "101", "tier1", "rinson", "2010", "20201"), new Company("1", "101", "tier2", "personB", "2018", "2020"), new Company("2", "200", "tier3", "personD", "2010", "20201"))
Thanks.
You need to do it by steps :
Company
in theoldList
(can be done also by swapping old and new lists)Company
related to the current old one : matchcode/type/region
"old" and "new"
as keys, then add thismap
in thelistMap