public class DefaultFileComparator
extends java.lang.Object
implements java.util.Comparator, java.io.Serializable
File.compareTo(File)
method.
This comparator can be used to sort lists or arrays of files by using the default file comparison.
Example of sorting a list of files using the
DEFAULT_COMPARATOR
singleton instance:
List<File> list = ... Collections.sort(list, DefaultFileComparator.DEFAULT_COMPARATOR);
Example of doing a reverse sort of an array of files using the
DEFAULT_REVERSE
singleton instance:
File[] array = ... Arrays.sort(array, DefaultFileComparator.DEFAULT_REVERSE);
Modifier and Type | Field and Description |
---|---|
static java.util.Comparator |
DEFAULT_COMPARATOR
Singleton default comparator instance
|
static java.util.Comparator |
DEFAULT_REVERSE
Singleton reverse default comparator instance
|
Constructor and Description |
---|
DefaultFileComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(java.lang.Object obj1,
java.lang.Object obj2)
Compare the two files using the
File.compareTo(File) method. |
public static final java.util.Comparator DEFAULT_COMPARATOR
public static final java.util.Comparator DEFAULT_REVERSE
public int compare(java.lang.Object obj1, java.lang.Object obj2)
File.compareTo(File)
method.compare
in interface java.util.Comparator
obj1
- The first file to compareobj2
- The second file to compareFile.compareTo(File)
with file2 as the parameter.Copyright (c) 2002-2012 Apache Software Foundation