hbase-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jan Hentschel (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HBASE-19103) Add BigDecimalComparator for filter
Date Tue, 31 Oct 2017 20:55:01 GMT

    [ 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)

  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);

  public int hashCode() {
    return Objects.hash(limit);

A test case covering this looks like the following

  public void testEquals() {
    // Check that equals returns true for identical objects
    final ColumnCountGetFilter filter = new ColumnCountGetFilter(5);
    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);
    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);
    assertNotEquals(filter3.hashCode(), filter4.hashCode());

    // Check that equals returns false for a different type
    final ColumnCountGetFilter filter5 = new ColumnCountGetFilter(5);

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,
> Should I add BigDecimalComparator for filter? Some scenarios need to calculate the data
accurately may use it.

This message was sent by Atlassian JIRA

View raw message