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

Java基础
体验Java 1.5中面向(AOP)编程
Java中基于Aspectwerkz的AOP
2004开发技术年度综述之Java世界
JavaBeans程序开发
开发基于Java的图形用户界面
Java加密和数字签名编程
Java应用程序中创建图像
初探Java类加载机制
EJB3.0之实体Bean的继承
javamail收取Hotmail的退信
JavaMail访问Hotmail邮箱
EJB3.0开发之多对多和一对一
EJB 3.0开发指南之多表映射
EJB组件与可重用性的矛盾
J2SE中的序默认序列化
Java操作文本文件的方法
Java多线程编程之限制优先级
EJB 3.0 开发指南之定时服务
J2SE中的序列化之继承
J2SE中的序列化的认识

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 106 ::
收藏到网摘: 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;
    }

}