1 /*------------------------------------------------------------------------------
2 Name: FileComparator.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 package org.xmlBlaster.client.filepoller;
8
9 import java.util.Comparator;
10
11
12 /**
13 * FileComparator used to compare two FileInfo objects
14 *
15 * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a>
16 * @deprectated it is now replaced by the corresponding class in org.xmlBlaster.contrib.filewatcher
17 */
18 public class FileComparator implements Comparator {
19
20 public FileComparator() {
21 }
22
23 /**
24 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
25 */
26 public int compare(Object o1, Object o2) {
27 if (o1 == o2 || o1.equals(o2))
28 return 0;
29 if (o1 instanceof FileInfo && o2 instanceof FileInfo) {
30 FileInfo info1 = (FileInfo)o1;
31 FileInfo info2 = (FileInfo)o2;
32 if (info1.getTimestamp() > info2.getTimestamp()) {
33 return 1;
34 }
35 else if (info1.getTimestamp() < info2.getTimestamp()) {
36 return -1;
37 }
38 else { // then same timestamp
39 return info1.getName().compareTo(info2.getName());
40 }
41 }
42 return o1.toString().compareTo(o2.toString());
43 }
44 }
syntax highlighted by Code2HTML, v. 0.9.1