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 閱讀(11315) 評論(1)  編輯  收藏 所屬分類: Java


          FeedBack:
          # re: 利用java.util.Collections.sort方法排序
          2008-07-04 10:40 | 汽車
          沒寫全呀..  回復  更多評論
            
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345



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


          常用鏈接

          留言簿(2)

          隨筆分類

          文章分類

          FLASH

          Java

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 沙洋县| 当阳市| 理塘县| 开鲁县| 宁蒗| 华宁县| 星子县| 吴堡县| 新平| 西乌珠穆沁旗| 宿松县| 乐平市| 遂宁市| 镇原县| 呼图壁县| 普洱| 朝阳县| 通州区| 墨竹工卡县| 自贡市| 汝城县| 邵武市| 新河县| 宜良县| 江都市| 马公市| 台前县| 大洼县| 那坡县| 木兰县| 临桂县| 手机| 绥芬河市| 礼泉县| 东城区| 白山市| 齐河县| 枝江市| 正安县| 巴青县| 巧家县|