public class SizeFileComparatorextends Objectimplements Serializable
This comparator can be used to sort lists or arrays of files by their length/size.
Example of sorting a list of files using the
SIZE_COMPARATOR singleton instance:
List<File> list = ... ((AbstractFileComparator) SizeFileComparator.SIZE_COMPARATOR).sort(list);
Example of doing a reverse sort of an array of files using the
SIZE_REVERSE singleton instance:
File array = ... ((AbstractFileComparator) SizeFileComparator.SIZE_REVERSE).sort(array);
N.B. Directories are treated as zero size unless
|Modifier and Type||Field and Description|
Size comparator instance - directories are treated as zero size
Reverse size comparator instance - directories are treated as zero size
Size comparator instance which sums the size of a directory's contents using
Reverse size comparator instance which sums the size of a directory's contents using
|Constructor and Description|
Construct a file size comparator instance (directories treated as zero size).
Construct a file size comparator instance specifying whether the size of the directory contents should be aggregated.
|Modifier and Type||Method and Description|
Compare the length of two files.
Sort an array of files.
Sort a List of files.
String representation of this file comparator.
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public static final Comparator<File> SIZE_COMPARATOR
public static final Comparator<File> SIZE_REVERSE
public static final Comparator<File> SIZE_SUMDIR_COMPARATOR
public SizeFileComparator(boolean sumDirectoryContents)
true The size of directories is calculated using
trueif the sum of the directoryies contents should be calculated, otherwise
falseif directories should be treated as size zero (see
file1- The first file to compare
file2- The second file to compare
public String toString()
This method uses
Arrays.sort(Object, Comparator) and returns the original array.
files- The files to sort, may be null
Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.