HADOOP-14683. FileStatus.compareTo binary compatible issue. Contributed by Akira Ajisaka.

(cherry picked from commit cf6794ebe9)
(cherry picked from commit 60c10ea7b47f185997b215aea7a3f375ed713ac5)
This commit is contained in:
Junping Du 2017-08-01 17:13:02 -07:00
parent f2f09e2bb0
commit 168d8e0c04
1 changed files with 17 additions and 3 deletions

View File

@ -31,7 +31,7 @@ import org.apache.hadoop.io.Writable;
*/ */
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Stable @InterfaceStability.Stable
public class FileStatus implements Writable, Comparable<FileStatus> { public class FileStatus implements Writable, Comparable<Object> {
private Path path; private Path path;
private long length; private long length;
@ -328,11 +328,25 @@ public class FileStatus implements Writable, Comparable<FileStatus> {
* @return a negative integer, zero, or a positive integer as this object * @return a negative integer, zero, or a positive integer as this object
* is less than, equal to, or greater than the specified object. * is less than, equal to, or greater than the specified object.
*/ */
@Override
public int compareTo(FileStatus o) { public int compareTo(FileStatus o) {
return this.getPath().compareTo(o.getPath()); return this.getPath().compareTo(o.getPath());
} }
/**
* Compare this FileStatus to another FileStatus.
* This method was added back by HADOOP-14683 to keep binary compatibility.
*
* @param o the FileStatus to be compared.
* @return a negative integer, zero, or a positive integer as this object
* is less than, equal to, or greater than the specified object.
* @throws ClassCastException if the specified object is not FileStatus
*/
@Override
public int compareTo(Object o) {
FileStatus other = (FileStatus) o;
return compareTo(other);
}
/** Compare if this object is equal to another object /** Compare if this object is equal to another object
* @param o the object to be compared. * @param o the object to be compared.
* @return true if two file status has the same path name; false if not. * @return true if two file status has the same path name; false if not.