生成树的排序方法

 
private List CreateTree(List all)
{
if(all==null||all.size()==0)
return null;

int count=all.size();

Base_sysfunc bi=new Base_sysfunc();
Base_sysfunc bj=new Base_sysfunc();

//组织好父子之间的关系 填充layer与parentname这两个字段的内容
for(int i=0;i<count;i++)
{
bi=(Base_sysfunc)all.get(i);
bi.setLayer(0);
bi.setFullname(bi.getFuncname());
boolean trans=false;
for(int j=i+1;j<count;j++)
{
bj=(Base_sysfunc)all.get(j);
if(bi.getParentid()==bj.getFuncid())
{
//是父子关系
all.set(i,bj);
all.set(j, bi); //父在前面子在后面
trans=true;
}
}

if(trans)
i--;
}


for (int i=0;i<count;i++)
{
bi=(Base_sysfunc)all.get(i);
boolean trans=false;
for(int j=i+1;j<count;j++)
{
bj=(Base_sysfunc)all.get(j);
if(bj.getParentid()==bi.getFuncid())
{
bj.setLayer(bi.getLayer()+1);
bj.setFullname(bi.getFullname()+">>"+bj.getFuncname());
}
}
}

//组织在vector中的存放顺序

for(int i=0;i<count;i++)
{
bi=(Base_sysfunc)all.get(i);
boolean trans=false;
for(int j=i+1;j<count;j++)
{
bj=(Base_sysfunc)all.get(j);
if(bi.getFuncid()==bj.getParentid())
{
all.remove(j);
all.add(i+1,bj);
}
}
}

for(int i=0;i<count;i++)
{
bi=(Base_sysfunc)all.get(i);
boolean trans=false;
for(int j=i+1;j<count;j++)
{
bj=(Base_sysfunc)all.get(j);
if(bi.getFuncid()==bj.getParentid())
{
all.remove(j);
all.add(i+1,bj);
}
}
}

return all;

}


private List CreateTree(List all,int topid)
{
all=CreateTree(all);
int count=all.size();
Base_sysfunc bj=new Base_sysfunc();

//把不在这一顶层的其它项都删除掉

// 查找ID=topid所在的位置
int topidj=0;
int topidlayer=0;

//查找ID=topid所在的位置
for(int j=0;j<count;j++)
{
bj=(Base_sysfunc)all.get(j);
//找到TopID对应的对象
if(bj.getFuncid()==topid)
{
topidj=j;
topidlayer=bj.getLayer();
break;
}
}
Vector reslut=new Vector();
for(int j=topidj;j<count;j++)
{
bj=(Base_sysfunc)all.get(j);

//找到TopID对应的对象
if(bj.getLayer()<=topidlayer&&j>topidj)
{
break;
}
else
{
bj.setLayer(bj.getLayer()-topidlayer);
reslut.add(bj);
}
}

return reslut;

}


//
public class Base_sysfunc implements java.io.Serializable {


// Fields

private long funcid;
private long parentid;
private long funcstatus;
private String funcversion;
private String funcname;
private long showorder;
private long menuflag;
private String entranceurl;
private String comments;
// set/getMethod..........

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值