KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > XFileCompare


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util;
11
12 /**
13  * Class to compare XFile object depending on their comparefield.
14  * @see SortedVector
15  * @see CompareInterface
16  * @see XFile
17  *
18  * @author David V van Zeventer
19  * @application SCAN or Devices
20  * @version $Id: XFileCompare.java,v 1.7 2004/09/30 08:52:16 pierre Exp $
21  * @todo Should implement java.util.Comparator, perhaps be named 'FileComparator'.
22  */

23 public class XFileCompare implements CompareInterface {
24
25     /**
26      * Attribute to compare on ('filepath' or 'modtime')
27      */

28     String JavaDoc compareField;
29
30     /**
31      * Create a XFuileCompare.
32      * @param compareField Attribute to compare on ('filepath' or 'modtime')
33      */

34     public XFileCompare(String JavaDoc compareField) {
35         this.compareField = compareField;
36     }
37
38     /**
39      * Make the comparison.
40      * The result is a negative value if the comparefield of the first file is 'smaller' than the second,
41      * a positive value if it is 'larger', and 0 if they are 'equal'.
42      * @param thisOne the first object to compare. should be a <code>XFile</code>.
43      * @param other the second object to compare. should be a <code>XFile</code>.
44      * @return the result of the comparison
45      */

46     public int compare(Object JavaDoc thisOne, Object JavaDoc other) {
47         int result = 0;
48         long longresult=0;
49         XFile xfileobj1 = (XFile)thisOne;
50         XFile xfileobj2 = (XFile)other;
51
52         if (compareField.equals("filepath")) { //Compare objects using their filepathname.
53
result = (xfileobj1.getFilePath()).compareTo(xfileobj2.getFilePath());
54             //log.debug("XFileCompare: Filepath compare result= "+result);
55

56         } else {
57             if (compareField.equals("modtime")) { //Compare objects using their modification time.
58
longresult = xfileobj1.getModTime() - xfileobj2.getModTime();
59                 result = (int)(longresult/1000);
60                 //log.debug("XFileCompare: Modificationtime compare result= "+result);
61
}
62         }
63         return result;
64     }
65 }
66
Popular Tags