001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.gl.web.util; 017 018 import java.io.File; 019 import java.util.Comparator; 020 import java.util.Date; 021 022 import org.apache.commons.lang.StringUtils; 023 024 /** 025 * An implementation of Comparator which compares origin entry Files by their name prefix and then by last modified date 026 */ 027 public class OriginEntryFileComparator implements Comparator<File> { 028 029 public int compare(File o1, File o2) { 030 String fileName1 = o1.getName(); 031 String fileName2 = o2.getName(); 032 033 // remove date from name 034 fileName1 = StringUtils.substringBefore(fileName1, "."); 035 fileName2 = StringUtils.substringBefore(fileName2, "."); 036 037 int c = fileName1.compareTo(fileName2); 038 if (c != 0) { 039 return c; 040 } 041 042 Date fileDate1 = new Date(o1.lastModified()); 043 Date fileDate2 = new Date(o2.lastModified()); 044 045 return fileDate1.compareTo(fileDate2); 046 } 047 048 }