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


          FeedBack:
          # re: 利用java.util.Collections.sort方法排序
          2008-07-04 10:40 | 汽車
          沒寫全呀..  回復  更多評論
            
          <2025年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456



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


          常用鏈接

          留言簿(2)

          隨筆分類

          文章分類

          FLASH

          Java

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 定结县| 卓尼县| 西安市| 津南区| 古浪县| 综艺| 临沭县| 长宁区| 株洲市| 新邵县| 秭归县| 轮台县| 绿春县| 行唐县| 辉县市| 同仁县| 班戈县| 尼勒克县| 双城市| 昆山市| 建宁县| 宁城县| 江北区| 丰顺县| 永丰县| 通辽市| 丹阳市| 泽库县| 土默特右旗| 竹山县| 东乌珠穆沁旗| 曲松县| 思南县| 周口市| 天津市| 桂林市| 武乡县| 永登县| 静海县| 太和县| 屯昌县|