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 閱讀(11316) 評論(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

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 论坛| 阳谷县| 黎城县| 重庆市| 易门县| 茂名市| 阜新| 高安市| 金川县| 高台县| 定兴县| 苏尼特左旗| 抚顺县| 咸宁市| 开江县| 衡阳县| 上蔡县| 平阳县| 叶城县| 轮台县| 济南市| 通辽市| 博乐市| 德令哈市| 施秉县| 巫山县| 滨海县| 洛扎县| 郎溪县| 阆中市| 石林| 商城县| 昌宁县| 卓尼县| 翼城县| 天长市| 长岛县| 五华县| 剑阁县| 榕江县| 天柱县|