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