net.kindeditor.util.FileItemComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of filemanager Show documentation
Show all versions of filemanager Show documentation
KindEditor(http://kindeditor.org/) is a lightweight, Open Source(LGPL), cross browser, web based WYSIWYG HTML editor.
kind-file-manager is the upload manager and file manager for kindeditor,
it use Servlet 3.0 technology, and can be deployed as a single web fragment jar.
The newest version!
package net.kindeditor.util;
import java.util.Comparator;
import net.kindeditor.bean.FileItem;
/**
* Note: all these comparator class have natural ordering that are inconsistent with equals.
* @author luyanfei
*
*/
public class FileItemComparator {
public static final class SizeComparator implements Comparator {
@Override
public int compare(FileItem item1, FileItem item2) {
if(item1.isDir() && !item2.isDir())
return -1;
else if(!item1.isDir() && item2.isDir())
return 1;
else
return new Long(item1.getFileSize()).compareTo(new Long(item2.getFileSize()));
}
}
public static final class NameComparator implements Comparator {
@Override
public int compare(FileItem item1, FileItem item2) {
if(item1.isDir() && !item2.isDir())
return -1;
else if(!item1.isDir() && item2.isDir())
return 1;
else
return item1.getFileName().compareTo(item2.getFileName());
}
}
public static final class TypeComparator implements Comparator {
@Override
public int compare(FileItem item1, FileItem item2) {
if(item1.isDir() && !item2.isDir())
return -1;
else if(!item1.isDir() && item2.isDir())
return 1;
else
return item1.getFileType().compareTo(item2.getFileType());
}
}
}