hadoop-mapreduce-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sai Sai <saigr...@yahoo.in>
Subject Re: CompareTo vs equals
Date Thu, 28 Mar 2013 03:16:01 GMT
IntPair  class has these 2 methods, i understand that compareTo is used for comparing but
when is equals method used and is it necessary to write it when we alread have implemented
compareTo method.

@Override
public int compareTo(IntPair that) {
int cmp = first.compareTo(that.first);
if(cmp==0){
cmp = second.compareTo(that.second);
}
return cmp;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof IntPair){
IntPair that = (IntPair)obj;
return (first.equals(that.first) && second.equals(that.second));
}
return false;
}

Thanks

Sai
Mime
View raw message