Allow comparison through equals method if exists

Change-Id: I8c25ef274b557d58d8f82bfb52ff09265e222126
(cherry picked from commit 0e340c691b9844d83431360c927e7123f4359e61)