/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Provides various {@link java.util.Comparator} implementations * for {@link java.io.File}s and {@link java.nio.file.Path}. *

Sorting

*

* All the comparators include convenience utility sort(File...) and * sort(List) methods. *

*

* For example, to sort the files in a directory by name: *

*
 * File[] files = dir.listFiles();
 * NameFileComparator.NAME_COMPARATOR.sort(files);
 * 
*

* ...alternatively you can do this in one line: *

*
 * File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
 * 
*

Composite Comparator

*

* The CompositeFileComparator can be used * to compare (and sort lists or arrays of files) by combining a number of other comparators. *

*

* For example, to sort an array of files by type (directory or file) * and then by name: *

*
 * CompositeFileComparator comparator =
 * new CompositeFileComparator(
 * DirectoryFileComparator.DIRECTORY_COMPARATOR,
 * NameFileComparator.NAME_COMPARATOR);
 * File[] files = dir.listFiles();
 * comparator.sort(files);
 * 
*

Singleton Instances (thread-safe)

*

* The {@link java.util.Comparator} implementations have some convenience * singleton(thread-safe) instances ready to use: *

* */ package org.apache.commons.io.comparator;