18 package org.turro.file;
21 import java.util.Comparator;
22 import java.util.Properties;
30 private Properties props;
50 public int compare(Object o1, Object o2) {
57 for(
int i = 0; i < 10 && result == 0; i++) {
58 field = props.getProperty(
"file.ordering." + i +
".name");
59 desc =
"desc".equals(props.getProperty(
"file.ordering." + i +
".order"));
60 if(result == 0 &&
"directory".equals(field)) {
61 if(!f1.isDirectory() && f2.isDirectory()) {
64 else if(f1.isDirectory() && !f2.isDirectory()) {
70 if(desc) result *= -1;
72 else if(result == 0 &&
"fileName".equals(field)) {
73 result = f1.getName().compareTo(f2.getName());
74 if(desc) result *= -1;
76 else if(result == 0 &&
"fileDate".equals(field)) {
77 result = Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
78 if(desc) result *= -1;
80 else if(!f1.isDirectory() && !f2.isDirectory() && result == 0 &&
"fileSize".equals(field)) {
81 result = Long.valueOf(f1.length()).compareTo(f2.length());
82 if(desc) result *= -1;
FileComparator(Properties props)
int compare(Object o1, Object o2)