Java: How do I perform list operations with different definitions of equals? -
Java: How do I handle the list with different definitions of equal?
For example, if my POJO had the following structure:
Public Class Generator Pojo {Private string ID ; Private string address; Private string city; Private string country; Private string extra; description; }
(with the appropriate getters and setters)
List1 & gt; Generic Pojo & gt;
and List2 & gt; GenericPojo & gt;
, How do I know:
List 1 - list 2 (where
list 1 and Cutting 2 list (where id
, address
, city
, country
, but extraDetails < / Code> is
genericPoO
similar)
Can two different custom comparator classes be helpful here? Is there a library that handles these tasks effectively or should I try to implement my own?
If you have to manipulate the class outside your control, I will suggest using the delegation. Try:
-
Rich list
contractlist - Single method `Public boolean equivalent (TT1, T, T2) for applying bracket
list
s ) With aparity checker & lt; T & gt;
Create integration. - Implement this interface for your generic pie twice: one probe is just checking the ID and other fields.
- Both methods are interested in you (set set object and set intersection), but with a complementary argument, which is called
EquityCaiker & lt; T & gt;
is a solid example that will test for you equality.
So you can add both functions to all existing list
s for any type of object for which you have written a equacquaker
.
Further Improvements: You default Equity Checker & lt; T & gt;
which calls the equivalent method of comparative objects. You can download both new tasks to define parity checker
.
Comments
Post a Comment