HADOOP-12209 Comparable type should be in FileStatus. (Yong Zhang via stevel)
This commit is contained in:
parent
05130e94c5
commit
9141e1aa16
|
@ -972,6 +972,9 @@ Release 2.8.0 - UNRELEASED
|
||||||
HADOOP-12235 hadoop-openstack junit & mockito dependencies should be
|
HADOOP-12235 hadoop-openstack junit & mockito dependencies should be
|
||||||
"provided". (Ted Yu via stevel)
|
"provided". (Ted Yu via stevel)
|
||||||
|
|
||||||
|
HADOOP-12209 Comparable type should be in FileStatus.
|
||||||
|
(Yong Zhang via stevel)
|
||||||
|
|
||||||
Release 2.7.2 - UNRELEASED
|
Release 2.7.2 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.hadoop.io.Writable;
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Public
|
@InterfaceAudience.Public
|
||||||
@InterfaceStability.Stable
|
@InterfaceStability.Stable
|
||||||
public class FileStatus implements Writable, Comparable {
|
public class FileStatus implements Writable, Comparable<FileStatus> {
|
||||||
|
|
||||||
private Path path;
|
private Path path;
|
||||||
private long length;
|
private long length;
|
||||||
|
@ -323,19 +323,14 @@ public class FileStatus implements Writable, Comparable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare this object to another object
|
* Compare this FileStatus to another FileStatus
|
||||||
*
|
* @param o the FileStatus to be compared.
|
||||||
* @param o the object to be compared.
|
|
||||||
* @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.
|
||||||
*
|
|
||||||
* @throws ClassCastException if the specified object's is not of
|
|
||||||
* type FileStatus
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object o) {
|
public int compareTo(FileStatus o) {
|
||||||
FileStatus other = (FileStatus)o;
|
return this.getPath().compareTo(o.getPath());
|
||||||
return this.getPath().compareTo(other.getPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compare if this object is equal to another object
|
/** Compare if this object is equal to another object
|
||||||
|
|
|
@ -90,17 +90,13 @@ public class LocatedFileStatus extends FileStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare this object to another object
|
* Compare this FileStatus to another FileStatus
|
||||||
*
|
* @param o the FileStatus to be compared.
|
||||||
* @param o the object to be compared.
|
|
||||||
* @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.
|
||||||
*
|
|
||||||
* @throws ClassCastException if the specified object's is not of
|
|
||||||
* type FileStatus
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object o) {
|
public int compareTo(FileStatus o) {
|
||||||
return super.compareTo(o);
|
return super.compareTo(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.hadoop.fs.viewfs;
|
package org.apache.hadoop.fs.viewfs;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.BlockLocation;
|
import org.apache.hadoop.fs.BlockLocation;
|
||||||
|
import org.apache.hadoop.fs.FileStatus;
|
||||||
import org.apache.hadoop.fs.LocatedFileStatus;
|
import org.apache.hadoop.fs.LocatedFileStatus;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
|
@ -120,7 +121,7 @@ class ViewFsLocatedFileStatus extends LocatedFileStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object o) {
|
public int compareTo(FileStatus o) {
|
||||||
return super.compareTo(o);
|
return super.compareTo(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,9 @@ import java.io.DataInputStream;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -183,6 +186,25 @@ public class TestFileStatus {
|
||||||
validateToString(fileStatus);
|
validateToString(fileStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCompareTo() throws IOException {
|
||||||
|
Path path1 = new Path("path1");
|
||||||
|
Path path2 = new Path("path2");
|
||||||
|
FileStatus fileStatus1 =
|
||||||
|
new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"),
|
||||||
|
"one", "one", null, path1);
|
||||||
|
FileStatus fileStatus2 =
|
||||||
|
new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"),
|
||||||
|
"one", "one", null, path2);
|
||||||
|
assertTrue(fileStatus1.compareTo(fileStatus2) < 0);
|
||||||
|
assertTrue(fileStatus2.compareTo(fileStatus1) > 0);
|
||||||
|
|
||||||
|
List<FileStatus> statList = new ArrayList<>();
|
||||||
|
statList.add(fileStatus1);
|
||||||
|
statList.add(fileStatus2);
|
||||||
|
assertTrue(Collections.binarySearch(statList, fileStatus1) > -1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that toString produces the expected output for a symlink.
|
* Check that toString produces the expected output for a symlink.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue