View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.gl.web.util;
17  
18  import java.io.File;
19  import java.util.Comparator;
20  import java.util.Date;
21  
22  import org.apache.commons.lang.StringUtils;
23  
24  /**
25   * An implementation of Comparator which compares origin entry Files by their name prefix and then by last modified date
26   */
27  public class OriginEntryFileComparator implements Comparator<File> {
28  
29      public int compare(File o1, File o2) {
30          String fileName1 = o1.getName();
31          String fileName2 = o2.getName();
32  
33          // remove date from name
34          fileName1 = StringUtils.substringBefore(fileName1, ".");
35          fileName2 = StringUtils.substringBefore(fileName2, ".");
36  
37          int c = fileName1.compareTo(fileName2);
38          if (c != 0) {
39              return c;
40          }
41  
42          Date fileDate1 = new Date(o1.lastModified());
43          Date fileDate2 = new Date(o2.lastModified());
44  
45          return fileDate1.compareTo(fileDate2);
46      }
47  
48  }