Coverage Report - org.mule.transport.file.comparator.OlderFirstComparator
 
Classes in this File Line Coverage Branch Coverage Complexity
OlderFirstComparator
0%
0/12
0%
0/10
8
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.file.comparator;
 8  
 
 9  
 import org.mule.util.ClassUtils;
 10  
 import org.mule.util.FileUtils;
 11  
 
 12  
 import java.io.File;
 13  
 import java.text.MessageFormat;
 14  
 import java.util.Comparator;
 15  
 
 16  
 /**
 17  
  * <p><code>OlderComparatorComparator</code> is a {@link Comparator} of File
 18  
  * which is capable of comparing files for equality based on their modification dates.</p>
 19  
  */
 20  0
 public class OlderFirstComparator implements Comparator
 21  
 {
 22  
     public int compare(Object o1, Object o2)
 23  
     {
 24  0
         if (o1 instanceof File && o2 instanceof File)
 25  
         {
 26  0
             File f = (File) o1;
 27  0
             File f1 = (File) o2;
 28  0
             boolean fileNewer = FileUtils.isFileNewer(f, f1);
 29  0
             boolean fileOlder = FileUtils.isFileOlder(f, f1);
 30  0
             if (!fileNewer && !fileOlder)
 31  
             {
 32  0
                 return 0;
 33  
             }
 34  0
             else if (fileNewer)
 35  
             {
 36  0
                 return 1;
 37  
             }
 38  
             else
 39  
             {
 40  0
                 return -1;
 41  
             }
 42  
 
 43  
         }
 44  0
         throw new IllegalArgumentException(MessageFormat.format(
 45  
                 "Expected java.io.File instance, but was {0} and {1}",
 46  
                 ClassUtils.getShortClassName(o1, "<null>"),
 47  
                 ClassUtils.getShortClassName(o2, "<null")));
 48  
     }
 49  
 }