1 2 23 package com.geinuke.util.collection; 24 25 import java.util.ArrayList ; 26 27 import com.geinuke.vo.CommentVO; 28 29 public class TreeFactory { 30 31 32 protected static ArrayList getChildsOf(CommentVO c,ArrayList list){ 33 ArrayList childs=null; 34 childs=new ArrayList (); 35 CommentVO cx=null; 36 37 for(int i=0;i<list.size();i++){ 38 cx=(CommentVO)list.get(i); 39 if(cx.getLink()==c.getCId()){ 40 41 TreeArrayList root=new TreeArrayList(cx); 42 childs.add(root); 43 root.setChilds(getChildsOf(cx,list)); 44 int count=0; 45 if(root.getChilds()!=null) 46 count+=root.getChilds().size(); 47 TreeArrayList x=null; 48 49 for(int j=0;root.getChilds()!=null && j<root.getChilds().size();j++){ 50 x=(TreeArrayList)root.getChilds().get(j); 51 count+=x.getSize(); 52 53 } 54 55 root.setSize(count); 56 } 57 } 58 if(childs.size()>0) 59 return childs; 60 else 61 return null; 62 } 63 public static TreeArrayList getCommentsTree(ArrayList list,CommentVO c){ 64 TreeArrayList tree=null; 65 ArrayList aux=null; 66 70 if(list==null || list.size()==0){ 71 tree=new TreeArrayList(c); 72 }else{ 73 74 aux=getChildsOf(c,list); 75 tree=new TreeArrayList(c); 76 tree.setChilds(aux); 77 int count=0; 78 if(tree.getChilds()!=null) 79 count+=tree.getChilds().size(); 80 TreeArrayList x=null; 81 82 for(int j=0;tree.getChilds()!=null && j<tree.getChilds().size();j++){ 83 x=(TreeArrayList)tree.getChilds().get(j); 84 count+=x.getSize(); 85 86 } 87 tree.setSize(count); 88 } 89 return tree; 90 } 91 92 } 93 | Popular Tags |