You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-issues@hadoop.apache.org by "Owen O'Malley (JIRA)" <ji...@apache.org> on 2011/01/06 21:22:46 UTC

[jira] Updated: (MAPREDUCE-2249) Better to check the reflexive property of the object while overriding equals method of it

     [ https://issues.apache.org/jira/browse/MAPREDUCE-2249?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Owen O'Malley updated MAPREDUCE-2249:
-------------------------------------

    Description: 
It is better to check the reflexive property of the object while overriding equals method of it.
 
It improves the performance when a heavy object is compared to itself.


  was:
It is better to check the reflexive property of the object while overriding equals method of it.
 
It improves the performance when a heavy object is compared to itself.

For example pls find the below snippet from Counters.java

  {code:title=Current Implementation|borderStyle=solid}
  @Override
  public synchronized boolean equals(Object obj) {
    boolean isEqual = false;
    if (obj != null && obj instanceof Counters) {
      Counters other = (Counters) obj;
      if (size() == other.size()) {
        isEqual = true;
        for (Map.Entry<String, Group> entry : this.counters.entrySet()) {
          String key = entry.getKey();
          Group sourceGroup = entry.getValue();
          Group targetGroup = other.getGroup(key);
          if (!sourceGroup.equals(targetGroup)) {
            isEqual = false;
            break;
          }
        }
      }
    }
    return isEqual;
  }
  {code}     

  {code:title=Proposed Implementation|borderStyle=solid}
  @Override
  public synchronized boolean equals(Object obj) {
    if(this == obj) { 
      return true;
    }
    boolean isEqual = false;
    if (obj != null && obj instanceof Counters) {
      Counters other = (Counters) obj;
      if (size() == other.size()) {
        isEqual = true;
        for (Map.Entry<String, Group> entry : this.counters.entrySet()) {
          String key = entry.getKey();
          Group sourceGroup = entry.getValue();
          Group targetGroup = other.getGroup(key);
          if (!sourceGroup.equals(targetGroup)) {
            isEqual = false;
            break;
          }
        }
      }
    }
    return isEqual;
  }
  {code}


Please don't put proposed solutions into the descriptions. They are mailed out as part of every comment. Make a reasonably brief description and add the proposal as the first comment.

The rest of your description follows:

For example pls find the below snippet from Counters.java

  {code:title=Current Implementation|borderStyle=solid}
  @Override
  public synchronized boolean equals(Object obj) {
    boolean isEqual = false;
    if (obj != null && obj instanceof Counters) {
      Counters other = (Counters) obj;
      if (size() == other.size()) {
        isEqual = true;
        for (Map.Entry<String, Group> entry : this.counters.entrySet()) {
          String key = entry.getKey();
          Group sourceGroup = entry.getValue();
          Group targetGroup = other.getGroup(key);
          if (!sourceGroup.equals(targetGroup)) {
            isEqual = false;
            break;
          }
        }
      }
    }
    return isEqual;
  }
  {code}     

  {code:title=Proposed Implementation|borderStyle=solid}
  @Override
  public synchronized boolean equals(Object obj) {
    if(this == obj) { 
      return true;
    }
    boolean isEqual = false;
    if (obj != null && obj instanceof Counters) {
      Counters other = (Counters) obj;
      if (size() == other.size()) {
        isEqual = true;
        for (Map.Entry<String, Group> entry : this.counters.entrySet()) {
          String key = entry.getKey();
          Group sourceGroup = entry.getValue();
          Group targetGroup = other.getGroup(key);
          if (!sourceGroup.equals(targetGroup)) {
            isEqual = false;
            break;
          }
        }
      }
    }
    return isEqual;
  }
  {code}

> Better to check the reflexive property of the object while overriding equals method of it
> -----------------------------------------------------------------------------------------
>
>                 Key: MAPREDUCE-2249
>                 URL: https://issues.apache.org/jira/browse/MAPREDUCE-2249
>             Project: Hadoop Map/Reduce
>          Issue Type: Improvement
>          Components: jobtracker, tasktracker
>    Affects Versions: 0.21.0
>         Environment: NA
>            Reporter: Bhallamudi Venkata Siva Kamesh
>             Fix For: 0.22.0, 0.23.0
>
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> It is better to check the reflexive property of the object while overriding equals method of it.
>  
> It improves the performance when a heavy object is compared to itself.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.