class Object {
string name;
Time date;
string createdBy;
int version;
}
How do I merge two sets of Objects, with the requirement that if an object from Set1 has matching name
and version
as an object from Set2, keep only the one from Set2 in the resulting merged set.
E.g.
Set1: { Object1(name:wilson, date:00:00:00, createdBy:admin, version:1), Object2(name:wilson, date:00:00:00, createdBy:admin, version:2) }
Set2: { Object3(name:arizona, date:00:00:00, createdBy:user, version:5), Object4(name:wilson, date:00:00:00, createdBy:user, version:1) }
With the resulting merged set:
{ Object4(name:wilson, date:00:00:00, createdBy:user, version:1), Object2(name:wilson, date:00:00:00, createdBy:admin, version:2), Object3(name:arizona, date:00:00:00, createdBy:user, version:5), }
(ordering doesn't matter)
I can union the two sets and but I'm not sure how to take advantage of Java 8 streams to add this filtering condition