posts - 28,  comments - 13,  trackbacks - 0
利用java.util.Collections.sort方法排序

    //所有选项集合
                List lsDefineOptions = new ArrayList();
                
                
for(int j=0;j<lsOptions.size();j++){
                    Element option 
= (Element) lsOptions.get(j);
                    String label 
= option.getAttributeValue("label");
                    String index 
= option.getAttributeValue("index");
                    String flowstate 
= option.getAttributeValue("flowstate");
                    String querySql 
= option.getChildText("query-sql");
                    
                    
//操作项对象
                    SearchOptionDefine defineOption = new SearchOptionDefine();
                    defineOption.setLabel(label);
                    
if(StringUtils.isNotBlank(index)){
                        defineOption.setIndex(Integer.parseInt(index));
                    }

                    
if(StringUtils.isNotBlank(flowstate)){
                        defineOption.setFlowstate(Integer.parseInt(flowstate));
                    }

                    defineOption.setQuerySql(querySql);
                    Log.debug(
"querySql:"+querySql);
                    
                    lsDefineOptions.add(defineOption);
                }

                
                
//所有选项集合的排序
                java.util.Collections.sort(lsDefineOptions);
操作项对象SearchOptionDefine 必须实现Comparable接口
package com.mip.core.objects;

import java.io.Serializable;

/**
 * <p> 
 * 主题查询对象
 * </p>
 * 
@author Libin
 * @date Mar 29, 2007
 * 
@version 4.0
 *
 * 
@see AnotherClass
 
*/

public class SearchOptionDefine implements Serializable,Comparable {

    
/**
     * 
     
*/

    
private static final long serialVersionUID = 3256440313546683697L;

    
/** A int variable 所有状态标志*/
    
public static final int ALL_STATE=999;
    
    
/**
     * Constructs a SearchDefine
     
*/

    
public SearchOptionDefine(){
        index
=0;
        flowstate
=ALL_STATE;
    }

    
    
/**
     * 主题查询的每一项定义:
    *    label:对应下拉框显示的中文名称
    *    index:排序序号
    *    flowstate:对应流程状态,结合流程状态来确定是否显示当前选项
    *    query_sql:原生SQL语句,主题查询的条件
    
*/
    
    
private String label;
    
private Integer index;
    
private Integer flowstate;
    
private String querySql;
    
    
public Integer getFlowstate() {
        
return flowstate;
    }

    
public void setFlowstate(Integer flowstate) {
        
this.flowstate = flowstate;
    }

    
public Integer getIndex() {
        
return index;
    }

    
public void setIndex(Integer index) {
        
this.index = index;
    }

    
public String getLabel() {
        
return label;
    }

    
public void setLabel(String label) {
        
this.label = label;
    }

    
public String getQuerySql() {
        
return querySql;
    }

    
public void setQuerySql(String query_sql) {
        
this.querySql = query_sql;
    }

    
    
public int compareTo(Integer arg0) {
        
return index.compareTo(arg0);
    }

    
    
public int compareTo(Object obj) {
        
// TODO Auto-generated method stub
        return (this.getIndex() - ((SearchOptionDefine)obj).getIndex());
    }

    
    
    
}

posted on 2007-03-29 13:15 Lib 阅读(11285) 评论(1)  编辑  收藏 所属分类: Java


FeedBack:
# re: 利用java.util.Collections.sort方法排序
2008-07-04 10:40 | 汽车
没写全呀..  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011



我的JavaEye博客
http://lib.javaeye.com


常用链接

留言簿(2)

随笔分类

文章分类

FLASH

Java

搜索

  •  

最新评论

阅读排行榜

评论排行榜