I have such a problem, that I fill in objects with data in two different way in my app. So sometimes can happen, that one has some null fields ant the second one does not. I would like to compare these two object in a way that when one object has a field with null value, this filed is excluded from comparison. Has anybody have some idea how to do it in practice? The best way for me would be some pseudoEquals() method template which I coud use to generete the code just like you can do with equals() and hashCode(), ... generators in InteliJ. Or to use some matcher, but I did not find one :/
class A {
T f1;
T f2;
T f3;
}
A a1 = new A(value1, value2, value3);
A a2 = new A(value1, null, value3);
a1.pseudoEquals(a2)
=> true
So I would like to have generator template in InteliJ to be able to generate something like this:
public boolean pseudoEquals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (f1 == null && f2 == null && f3 == null) return false;
A that = (A) o;
if (that.f1 == null && that.f2 == null && that.f3 == null) return false;
if ((f1 != null && that.f1 != null) && !f1.equals(that.f1)) return false;
if ((f2 != null && that.f2 != null) && !f2.equals(that.f2)) return false;
if ((f3 != null && that.f3 != null) && !f3.equals(that.f3)) return false;
return true;
}
Could anyone show me the way how to create such a template, or even better does anyone has one? :) Thanks.