01: /*
02: * Copyright (c) 2000, Jacob Smullyan.
03: *
04: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
05: * for the latest version.
06: *
07: * SkunkDAV is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License as published
09: * by the Free Software Foundation; either version 2, or (at your option)
10: * any later version.
11: *
12: * SkunkDAV is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with SkunkDAV; see the file COPYING. If not, write to the Free
19: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20: * 02111-1307, USA.
21: */
22:
23: package org.skunk.dav.client;
24:
25: import java.util.Comparator;
26:
27: public class DAVFileComparator implements Comparator {
28: public static final int NAME = 0;
29: public static final int LAST_MODIFIED = 1;
30: public static final int CREATION_DATE = 2;
31: private boolean ignoreCase = false;
32: private boolean directoriesFirst = true;
33: private int sortAttribute;
34:
35: public DAVFileComparator() {
36: this (false, true, NAME);
37: }
38:
39: public DAVFileComparator(boolean ignoreCase,
40: boolean directoriesFirst, int sortAttribute) {
41: this .ignoreCase = ignoreCase;
42: this .directoriesFirst = directoriesFirst;
43: this .sortAttribute = sortAttribute;
44: }
45:
46: public int compare(Object object1, Object object2) {
47: if ((object1 instanceof DAVFile)
48: && (object2 instanceof DAVFile)) {
49: if (object1.equals(object2))
50: return 0;
51:
52: DAVFile file1 = (DAVFile) object1;
53: DAVFile file2 = (DAVFile) object2;
54:
55: if (directoriesFirst) {
56: boolean coll1 = file1.isCollection();
57: boolean coll2 = file2.isCollection();
58: if (coll1 && !coll2)
59: return -1;
60: if (coll2 && !coll1)
61: return 1;
62: }
63:
64: if (ignoreCase) {
65: return file1.getName().compareToIgnoreCase(
66: file2.getName());
67: } else {
68: return file1.getName().compareTo(file2.getName());
69: }
70: }
71: throw new IllegalArgumentException(
72: "arguments must be instances of DAVFile");
73: }
74: }
75:
76: /* $Log: DAVFileComparator.java,v $
77: /* Revision 1.4 2000/12/19 22:06:15 smulloni
78: /* adding documentation.
79: /*
80: /* Revision 1.3 2000/12/03 23:53:25 smulloni
81: /* added license and copyright preamble to java files.
82: /*
83: /* Revision 1.2 2000/11/09 23:34:51 smullyan
84: /* log added to every Java file, with the help of python. Lock stealing
85: /* implemented, and treatment of locks made more robust.
86: /* */
|