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


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}

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

Reply via email to