MAPREDUCE-4272. SortedRanges.Range#compareTo was not spec compliant. (Yu Gao via llu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1425180 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luke Lu 2012-12-21 23:10:52 +00:00
parent 40c3b7f0b2
commit 02e940d6a4
2 changed files with 9 additions and 5 deletions

View File

@ -81,6 +81,9 @@ Trunk (Unreleased)
BUG FIXES
MAPREDUCE-4272. SortedRanges.Range#compareTo is not spec compliant.
(Yu Gao via llu)
MAPREDUCE-4356. [Rumen] Provide access to the method
ParsedTask.obtainTaskAttempts(). (ravigummadi)

View File

@ -271,7 +271,7 @@ boolean isEmpty() {
}
public boolean equals(Object o) {
if(o!=null && o instanceof Range) {
if (o instanceof Range) {
Range range = (Range)o;
return startIndex==range.startIndex &&
length==range.length;
@ -285,10 +285,11 @@ public int hashCode() {
}
public int compareTo(Range o) {
if(this.equals(o)) {
return 0;
}
return (this.startIndex > o.startIndex) ? 1:-1;
// Ensure sgn(x.compareTo(y) == -sgn(y.compareTo(x))
return this.startIndex < o.startIndex ? -1 :
(this.startIndex > o.startIndex ? 1 :
(this.length < o.length ? -1 :
(this.length > o.length ? 1 : 0)));
}
public void readFields(DataInput in) throws IOException {