import java.util.Comparator;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DocumentComparator implements Comparator {
private String criteria="standardname";
private int srtOrder=1;
public int compare(Object arg0, Object arg1) {
if(arg0 instanceof DocumentInfo.FileInfo && arg1 instanceof DocumentInfo.FileInfo ){
DocumentInfo.FileInfo doc0=(DocumentInfo.FileInfo)arg0;
DocumentInfo.FileInfo doc1=(DocumentInfo.FileInfo)arg1;
if(criteria.equals("description")){
return this.getSrtOrder()*(doc0.busDescription.compareTo(doc1.busDescription));
}
if(criteria.equals("filename")){
return this.getSrtOrder()*(doc0.fileName.compareTo(doc1.fileName));
}
if(criteria.equals("format")){
return this.getSrtOrder()*(doc0.format.compareTo(doc1.format));
}
if(criteria.equals("size")){
return this.getSrtOrder()*(new Integer(doc0.fileSize).compareTo(new Integer(doc1.fileSize)));
}
if(criteria.equals("date")){
Date date0=this.getDateObject(doc0.revisedDate);
Date date1=this.getDateObject(doc1.revisedDate);
return this.getSrtOrder()*(date0.compareTo(date1));
}
}
return 0;
}
public String getCriteria() {
return criteria;
}
public void setCriteria(String string) {
criteria = string;
}
private Date getDateObject(String string){
SimpleDateFormat dateFormat=new SimpleDateFormat("MM/dd/yyyy");
try{
return(dateFormat.parse(string));
}catch(Exception e){
e.printStackTrace();
return null;
}
}
public int getSrtOrder() {
return srtOrder;
}
public void setSrtOrder(int i) {
srtOrder = i;
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
public class DocumentComparator implements Comparator {
private String criteria="standardname";
private int srtOrder=1;
public int compare(Object arg0, Object arg1) {
if(arg0 instanceof DocumentInfo.FileInfo && arg1 instanceof DocumentInfo.FileInfo ){
DocumentInfo.FileInfo doc0=(DocumentInfo.FileInfo)arg0;
DocumentInfo.FileInfo doc1=(DocumentInfo.FileInfo)arg1;
if(criteria.equals("description")){
return this.getSrtOrder()*(doc0.busDescription.compareTo(doc1.busDescription));
}
if(criteria.equals("filename")){
return this.getSrtOrder()*(doc0.fileName.compareTo(doc1.fileName));
}
if(criteria.equals("format")){
return this.getSrtOrder()*(doc0.format.compareTo(doc1.format));
}
if(criteria.equals("size")){
return this.getSrtOrder()*(new Integer(doc0.fileSize).compareTo(new Integer(doc1.fileSize)));
}
if(criteria.equals("date")){
Date date0=this.getDateObject(doc0.revisedDate);
Date date1=this.getDateObject(doc1.revisedDate);
return this.getSrtOrder()*(date0.compareTo(date1));
}
}
return 0;
}
public String getCriteria() {
return criteria;
}
public void setCriteria(String string) {
criteria = string;
}
private Date getDateObject(String string){
SimpleDateFormat dateFormat=new SimpleDateFormat("MM/dd/yyyy");
try{
return(dateFormat.parse(string));
}catch(Exception e){
e.printStackTrace();
return null;
}
}
public int getSrtOrder() {
return srtOrder;
}
public void setSrtOrder(int i) {
srtOrder = i;
}
}