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 generic pie class is the same if only id is the same)

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:

  1. Rich list list contract
  2. Single method `Public boolean equivalent (TT1, T, T2) for applying bracket list s ) With a parity checker & lt; T & gt; Create integration.
  3. Implement this interface for your generic pie twice: one probe is just checking the ID and other fields.
  4. 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

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -