Coverage Report - org.apache.commons.io.comparator.AbstractFileComparator
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFileComparator
100%
8/8
100%
4/4
1.667
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.io.comparator;
 18  
 
 19  
 import java.io.File;
 20  
 import java.util.Arrays;
 21  
 import java.util.Collections;
 22  
 import java.util.Comparator;
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * Abstract file {@link Comparator} which provides sorting for file arrays and lists.
 27  
  *
 28  
  * @version $Id: AbstractFileComparator.java 1415850 2012-11-30 20:51:39Z ggregory $
 29  
  * @since 2.0
 30  
  */
 31  180
 abstract class AbstractFileComparator implements Comparator<File> {
 32  
 
 33  
     /**
 34  
      * Sort an array of files.
 35  
      * <p>
 36  
      * This method uses {@link Arrays#sort(Object[], Comparator)}
 37  
      * and returns the original array.
 38  
      *
 39  
      * @param files The files to sort, may be null
 40  
      * @return The sorted array
 41  
      * @since 2.0
 42  
      */
 43  
     public File[] sort(final File... files) {
 44  30
         if (files != null) {
 45  14
             Arrays.sort(files, this);
 46  
         }
 47  30
         return files;
 48  
     }
 49  
 
 50  
     /**
 51  
      * Sort a List of files.
 52  
      * <p>
 53  
      * This method uses {@link Collections#sort(List, Comparator)}
 54  
      * and returns the original list.
 55  
      *
 56  
      * @param files The files to sort, may be null
 57  
      * @return The sorted list
 58  
      * @since 2.0
 59  
      */
 60  
     public List<File> sort(final List<File> files) {
 61  30
         if (files != null) {
 62  14
             Collections.sort(files, this);
 63  
         }
 64  30
         return files;
 65  
     }
 66  
 
 67  
     /**
 68  
      * String representation of this file comparator.
 69  
      *
 70  
      * @return String representation of this file comparator
 71  
      */
 72  
     @Override
 73  
     public String toString() {
 74  60
         return getClass().getSimpleName();
 75  
     }
 76  
 }