当前位置: 首页 > 图文教程 > Java技术 > Java基础 > apatche组件的研究和使用

Java基础
通过Java套接字传递对象(1)
通过Java套接字传递对象(2)
浅谈JDBC驱动程序和XAResource
浅谈Java语言特点那些事
Java编程中的UDP协议

Java基础 中的 apatche组件的研究和使用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 95 ::
收藏到网摘: n/a

你换在写n个比较器进行比较吗?









import java.util.Comparator;
import java.util.logging.Logger;

import org.apache.commons.beanutils.BeanUtils;


/**
* 排序的类的应用
* @author bailonggang
* 2008-12-7
* 上午11:21:51
*/
public class CompartorUtil implements Comparator<Object>{
  /***对象的升序应用**/
public static final int SORT_DESC=0;
    /***对象的降序应用**/
public static final int SORT_ASC=1;
private static  Logger logger=Logger.getLogger(CompartorUtil.class.getName());
//排序的属性
private String property; 
//排序的类型升降序
private int sortType;

    public  CompartorUtil(String property,int sortType)
    {
    this.property=property;
    this.sortType=sortType;
    }
    /**
     *排序的实现的类的
     */
@SuppressWarnings("unchecked")
public int compare(Object o1,Object o2) {
try {
String property0=BeanUtils.getProperty(o1, this.property);
    String property1=BeanUtils.getProperty(o2, this.property);
    int result=0;
    result=property0.compareTo(property1);
    if(SORT_DESC==this.sortType)
    {
    result=-result;
    }
    if(result>=1)
    {
    return 1;
    }else if(result<=-1)
    {
    return -1;
    }
    return result;
} catch (Exception e) {
logger.info("对象排序时错误:"+e);
}

return 0;
    }

}