[
https://issues.apache.org/jira/browse/HBASE-19103?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16227534#comment-16227534
]
Jan Hentschel commented on HBASE-19103:
---------------------------------------
Your implementation of hashCode and equals look a little bit off. Why do you
include hashCode and toString in the equals implementation?
I'm currently doing something similar in HBASE-19008 and the template looks
similar to the following (taken from ColumnCountGetFilter)
{code:java}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof ColumnCountGetFilter)) {
return false;
}
final ColumnCountGetFilter that = (ColumnCountGetFilter) o;
return Objects.equals(limit, that.limit);
}
@Override
public int hashCode() {
return Objects.hash(limit);
}
{code}
A test case covering this looks like the following
{code:java}
@Test
public void testEquals() {
// Check that equals returns true for identical objects
final ColumnCountGetFilter filter = new ColumnCountGetFilter(5);
assertTrue(filter.equals(filter));
assertEquals(filter.hashCode(), filter.hashCode());
// Check that equals returns true for the same object
final ColumnCountGetFilter filter1 = new ColumnCountGetFilter(5);
final ColumnCountGetFilter filter2 = new ColumnCountGetFilter(5);
assertTrue(filter1.equals(filter2));
assertEquals(filter1.hashCode(), filter2.hashCode());
// Check that equals returns false for different objects
final ColumnCountGetFilter filter3 = new ColumnCountGetFilter(4);
final ColumnCountGetFilter filter4 = new ColumnCountGetFilter(5);
assertFalse(filter3.equals(filter4));
assertNotEquals(filter3.hashCode(), filter4.hashCode());
// Check that equals returns false for a different type
final ColumnCountGetFilter filter5 = new ColumnCountGetFilter(5);
assertFalse(filter5.equals(0));
}
{code}
This also eliminates the need of a hashCode field in the class.
> Add BigDecimalComparator for filter
> -----------------------------------
>
> Key: HBASE-19103
> URL: https://issues.apache.org/jira/browse/HBASE-19103
> Project: HBase
> Issue Type: New Feature
> Components: Client
> Reporter: Qilin Cao
> Assignee: Qilin Cao
> Priority: Minor
> Fix For: 1.2.0, 3.0.0
>
> Attachments: HBASE-19103-1.2.0-v1.patch, HBASE-19103-1.2.0-v2.patch,
> HBASE-19103-trunk-v1.patch, HBASE-19103-trunk-v2.patch
>
>
> Should I add BigDecimalComparator for filter? Some scenarios need to
> calculate the data accurately may use it.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)