利用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接口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);
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());
}
}
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());
}
}