KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > teams > hibernate > data > HibernateTree


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA. */

19
20 package org.polepos.teams.hibernate.data;
21
22
23 public class HibernateTree {
24     
25     public long id;
26     public HibernateTree preceding;
27     public HibernateTree subsequent;
28     public String JavaDoc name;
29     public int depth;
30     
31     public HibernateTree(){
32     }
33     
34     public HibernateTree(String JavaDoc name, int depth){
35         this.name = name;
36         this.depth = depth;
37     }
38     
39     public long getId(){
40         return id;
41     }
42     
43     public void setId(long id){
44         this.id = id;;
45     }
46
47     public HibernateTree getPreceding(){
48         return preceding;
49     }
50     
51     public void setPreceding(HibernateTree tree){
52         preceding = tree;
53     }
54
55     public HibernateTree getSubsequent(){
56         return subsequent;
57     }
58     
59     public void setSubsequent(HibernateTree tree){
60         subsequent = tree;
61     }
62     
63     public String JavaDoc getName(){
64         return name;
65     }
66     
67     public void setName(String JavaDoc name){
68         this.name = name;
69     }
70     
71     public int getDepth(){
72         return depth;
73     }
74     
75     public void setDepth(int depth){
76         this.depth = depth;
77     }
78     
79     public static HibernateTree createTree(int depth){
80         return createTree(depth, 0);
81     }
82     
83     private static HibernateTree createTree(int maxDepth, int currentDepth){
84         
85         if(maxDepth <= 0){
86             return null;
87         }
88         
89         HibernateTree tree = new HibernateTree();
90         if(currentDepth == 0){
91             tree.name = "root";
92         }else{
93             tree.name = "node at depth " + currentDepth;
94         }
95         tree.depth = currentDepth;
96         tree.preceding = createTree(maxDepth - 1, currentDepth + 1);
97         tree.subsequent = createTree(maxDepth - 1, currentDepth + 1);
98         return tree;
99     }
100     
101     public static void traverse(HibernateTree tree, HibernateTreeVisitor visitor){
102         if(tree == null){
103             return;
104         }
105         traverse(tree.preceding, visitor);
106         traverse(tree.subsequent, visitor);
107         visitor.visit(tree);
108     }
109
110 }
111
Popular Tags