Groupie: Discussion - another method for comparing content equality in place of `Item.equals()`

Created on 17 Sep 2019  路  5Comments  路  Source: lisawray/groupie

I'd like to start making more quality of life improvements in the library.

Currently to do a content comparison of two Items which are the same (meaning, isSameAs returned true for them) Groupie uses the Java equals method.

This forces subclasses to override both equals and hashCode for correct implementations and creates unnecessary boilerplate. This is especially nasty in Kotlin projects which 99% of the time don't ever override equals thanks to data classes.

In the interest of a nicer API, I'd like to create a companion function to isSameAs that will be used for the areContentsTheSame DiffUtil callback.

My proposed name is hasSameContentAs but open to other suggestions. areContentsTheSame is also an option but then the name would be different from isSameAs.

Whatever that function is called the default implementation would use the equals to not break current implementations.

Thoughts?

question

Most helpful comment

I think it's a good idea, overriding hashCode() just for this reason can be a pain and shouldn't be necessary.
hasSameContentAs() sounds good to me.

All 5 comments

I intended to propose isContentEqualTo, but hasSameContentAs sounds better.

Agree with this. Also we should have a separate section regarding diffing with groupie.

I think it's a good idea, overriding hashCode() just for this reason can be a pain and shouldn't be necessary.
hasSameContentAs() sounds good to me.

Now deployed in 2.6.0 - thank you for the feedback

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kawaiiDango picture kawaiiDango  路  5Comments

mattinger picture mattinger  路  3Comments

jordond picture jordond  路  6Comments

lisawray picture lisawray  路  7Comments

ovitrif picture ovitrif  路  5Comments