org.fcrepo.utilities.FileComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fcrepo-common Show documentation
Show all versions of fcrepo-common Show documentation
Common, generally useful utilities
/* The contents of this file are subject to the license and copyright terms
* detailed in the license directory at the root of the source tree (also
* available online at http://fedora-commons.org/license/).
*/
package org.fcrepo.utilities;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
/**
* Comparator for sorting files and directories in a deterministic manner. The
* sort order can be case-sensitive (default) or case-insensitive, ascending
* (default) or descending, with directories occurring before (if ascending) or
* after files within the same directory. The default behavior has the
* convenient property that it sorts in the same order as would be done when
* performing a pre-order traversal of the filesystem.
*
*
* Example input:
* afile
* file1
* file2
* dir1/
* FILE3
* dir1/file4
* dir2/file5
* dir2/file10
* dir2/
* file6
*
* Example output (with default behavior: case-sensitive, ascending):
* dir1
* dir1\file4
* dir2
* dir2\file10
* dir2\file5
* FILE3
* afile
* file1
* file2
* file6
*
*
* @author Chris Wilper
*/
public class FileComparator
implements Comparator