记录一下由当前节点获取所有子级节点

来源:互联网 发布:手机域名劫持 编辑:程序博客网 时间:2024/04/23 22:39
<pre name="code" class="java">/** * 根据资源id查询在列表中他所有的子节点。 * @param resId * @param allRes * @return */private List<Resources> getChildsByResId(Long resId,List<Resources> allRes){List<Resources> rtnList=new ArrayList<Resources>();for(Iterator<Resources> it=allRes.iterator();it.hasNext();){Resources res=it.next();if(!res.getParentId().equals(resId)) continue;rtnList.add(res);recursiveChilds(res.getResId(),rtnList,allRes);}return rtnList;}/** * 递归查找节点。 * @param resId * @param rtnList * @param allRes */private void recursiveChilds(Long resId,List<Resources> rtnList,List<Resources> allRes){for(Iterator<Resources> it=allRes.iterator();it.hasNext();){Resources res=it.next();if(!res.getParentId().equals(resId)) continue;rtnList.add(res);recursiveChilds(res.getResId(),rtnList,allRes);}}

public List<Long> getOwnOrangId(Long orangId) {if (orangId == null) {return null;}List<Orangize> allList = getList(new HashMap());Map<Long, List<Orangize>> fatherIdMap = new HashMap<Long, List<Orangize>>();Set<Long> allOrangIds = new HashSet<Long>();for (Orangize orangize : allList) {List<Orangize> subList = fatherIdMap.get(orangize.getParentid());if (subList == null) {subList = new ArrayList<Orangize>();fatherIdMap.put(orangize.getParentid(), subList);}subList.add(orangize);}// fatherId 列表List<Long> fatherIds = new ArrayList<Long>();allOrangIds.add(orangId);fatherIds.add(orangId);while (fatherIds.size() > 0) {List<Long> currFatherIds = fatherIds;fatherIds = new ArrayList<Long>();for (Long fatherId : currFatherIds) {List<Orangize> subOrangizes = fatherIdMap.get(fatherId);if (subOrangizes != null) {for (Orangize orangize : subOrangizes) {allOrangIds.add(orangize.getId());fatherIds.add(orangize.getId());}}}}return new ArrayList<Long>(allOrangIds);}





0 0
原创粉丝点击