accumulo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keith Turner (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ACCUMULO-1627) Add hashcode() and equals() to ConditionalMutation
Date Fri, 27 Sep 2013 20:03:04 GMT

    [ https://issues.apache.org/jira/browse/ACCUMULO-1627?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13780316#comment-13780316
] 

Keith Turner commented on ACCUMULO-1627:
----------------------------------------

I experimented w/ the concept of moving the code thats in equals(Mutation) to equals(Object),
and forcing equals(Mutation) to call equals(Object).

{code:java}
class Mutation {
  int r;
  
  public Mutation(int r) {
    this.r = r;
  }

  public boolean equals(Mutation m) {
    return equals((Object) m);
  }
  
  public boolean equals(Object o) {
    if (o instanceof Mutation) {
      return r == ((Mutation) o).r;
    }
    
    return false;
  }
}

class CondMutation extends Mutation {
  int cond;
  
  public CondMutation(int r, int c) {
    super(r);
    this.cond = c;
  }
  
  public boolean equals(Object o) {
    if (o instanceof CondMutation) {
      if (super.equals(o)) {
        CondMutation cm = (CondMutation) o;
        return cond == cm.cond;
      }
    }
    return false;
  }
}
{code}   

With this change the following code will call Mutation.equals(Mutation) which calls ConditionalMutation.equals(Object).
 Have to be careful when implementing  ConditionalMutation.equals(Object) because if it calls
Mutation.equals(Mutation) then could have an infinite loop.

{code:java}
  ConditionalMutation cm1 = new ConditionalMutation(1,2);
  ConditionalMutation cm2 = new ConditionalMutation(3,2);

  cm1.equals(cm2);
{code}


                
> Add hashcode() and equals() to ConditionalMutation
> --------------------------------------------------
>
>                 Key: ACCUMULO-1627
>                 URL: https://issues.apache.org/jira/browse/ACCUMULO-1627
>             Project: Accumulo
>          Issue Type: Sub-task
>          Components: client, tserver
>            Reporter: Keith Turner
>            Assignee: Bill Havanki
>              Labels: newbie
>             Fix For: 1.6.0
>
>
> ConditionalMutation should define equals() and hashcode() methods that consider the conditions.
  Its parent class defines those methods, so it should.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message