KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > mirroring > JobComparator


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.mirroring;
19
20 import java.util.Comparator JavaDoc;
21
22 /**
23  * @author zubov
24  * @version $Id: JobComparator.java,v 1.4 2004/02/21 05:28:21 zubov Exp $
25  *
26  */

27 public class JobComparator implements Comparator JavaDoc {
28
29     /**
30      * Compares Jobs
31      */

32     public JobComparator() {
33     }
34
35     /* (non-Javadoc)
36      * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
37      */

38     public int compare(Object JavaDoc arg0, Object JavaDoc arg1) {
39         Job job1 = (Job) arg0;
40         Job job2 = (Job) arg1;
41         if (job1.getPriority() > job2.getPriority())
42             return -1;
43         if (job1.getPriority() < job2.getPriority())
44             return 1;
45         if (job1.getTimeCreated() < job2.getTimeCreated()) { //older
46
return -1;
47         }
48         if (job1.getTimeCreated() > job2.getTimeCreated()) { //younger
49
return 1;
50         }
51         // same priority, and same time
52
return 0;
53     }
54
55 }
56
Popular Tags