KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > util > collection > TreeFactory


1
2  /*
3  -- GeiNuke --
4 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
5  http://www.hostingjava.it/-geinuke/
6
7 This file is part of GeiNuke.
8
9     GeiNuke is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     GeiNuke is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with GeiNuke; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */

23 package com.geinuke.util.collection;
24
25 import java.util.ArrayList JavaDoc;
26
27 import com.geinuke.vo.CommentVO;
28
29 public class TreeFactory {
30     
31     
32     protected static ArrayList JavaDoc getChildsOf(CommentVO c,ArrayList JavaDoc list){
33         ArrayList JavaDoc childs=null;
34         childs=new ArrayList JavaDoc();
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 JavaDoc list,CommentVO c){
64         TreeArrayList tree=null;
65         ArrayList JavaDoc aux=null;
66         /*
67         CommentVO c=new CommentVO();
68         c.setCId(0);
69         */

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