org.apache.commons.io.comparator
Class DefaultFileComparator

java.lang.Object
  extended by org.apache.commons.io.comparator.DefaultFileComparator
All Implemented Interfaces:
Serializable, Comparator

public class DefaultFileComparator
extends Object
implements Comparator, Serializable

Compare two files using the default 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);
 

Since:
Commons IO 1.4
Version:
$Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
See Also:
Serialized Form

Field Summary
static Comparator DEFAULT_COMPARATOR
          Singleton default comparator instance
static Comparator DEFAULT_REVERSE
          Singleton reverse default comparator instance
 
Constructor Summary
DefaultFileComparator()
           
 
Method Summary
 int compare(Object obj1, Object obj2)
          Compare the two files using the File.compareTo(File) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

DEFAULT_COMPARATOR

public static final Comparator DEFAULT_COMPARATOR
Singleton default comparator instance


DEFAULT_REVERSE

public static final Comparator DEFAULT_REVERSE
Singleton reverse default comparator instance

Constructor Detail

DefaultFileComparator

public DefaultFileComparator()
Method Detail

compare

public int compare(Object obj1,
                   Object obj2)
Compare the two files using the File.compareTo(File) method.

Specified by:
compare in interface Comparator
Parameters:
obj1 - The first file to compare
obj2 - The second file to compare
Returns:
the result of calling file1's File.compareTo(File) with file2 as the parameter.


Copyright © 2002-2008 The Apache Software Foundation. All Rights Reserved.