I'm looking at a class with this method
public boolean equals(Object o){
if (o instanceof MyObject) {
MyObject other = (MyObject) o;
return new EqualsBuilder ()
.append(this.getPropA(), other.getPropA())
.append(this.getPropB(), other.getPropB())
.append(this.getPropC(), other.getPropC())
.isEquals();
}
return false;
}
And in another class I'm trying to do this
List duplicateList = (ArrayList) CollectionUtils.intersection(listA, listB);
All the lists are of type MyObject.
I've discoverd that the equals method does not satisfy my requirements. It turns out that I am comparing objects that were instantiated in different ways.
So for the objects to be equal for my purpose I would need this method:
public boolean equals(Object o){
if (o instanceof MyObject) {
MyObject other = (MyObject) o;
return new EqualsBuilder ()
.append(this.getPropX(), other.getPropX())
.append(this.getPropY(), other.getPropX())
.append(this.getPropZ(), other.getPropZ())
.isEquals();
}
return false;
}
I cannot extend the class ( the class is not final, I 'm just not allowed to), and I don't really want to loop through each list.
So can anyone point me to a way to 'pass in' my own equals method?
Thanks