I have a collection of coll myObject. I would like to add an element to coll only if the collection does not have such an element.
I redefined the equals method myObject. He checks the equality of his 20 attributes.
However, in the case of a collection, I would like to do an equality check (and therefore add) based on only one of these attributes.
Maybe my architecture is wrong, and I should not have two equals definitions, and instead you should have two different objects.
However, is it possible, not too much refactoring, to achieve what I want from here? That is, I need some kind of Set collection, where I could tell how to do a comparison check. This will be similar to the Collection.sort () method, where you can give the comparator the ability to check the comparison.
java
jbenz
source share