001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.teams.hibernate.data;
021:
022: public class HibernateTree {
023:
024: public long id;
025: public HibernateTree preceding;
026: public HibernateTree subsequent;
027: public String name;
028: public int depth;
029:
030: public HibernateTree() {
031: }
032:
033: public HibernateTree(String name, int depth) {
034: this .name = name;
035: this .depth = depth;
036: }
037:
038: public long getId() {
039: return id;
040: }
041:
042: public void setId(long id) {
043: this .id = id;
044: ;
045: }
046:
047: public HibernateTree getPreceding() {
048: return preceding;
049: }
050:
051: public void setPreceding(HibernateTree tree) {
052: preceding = tree;
053: }
054:
055: public HibernateTree getSubsequent() {
056: return subsequent;
057: }
058:
059: public void setSubsequent(HibernateTree tree) {
060: subsequent = tree;
061: }
062:
063: public String getName() {
064: return name;
065: }
066:
067: public void setName(String name) {
068: this .name = name;
069: }
070:
071: public int getDepth() {
072: return depth;
073: }
074:
075: public void setDepth(int depth) {
076: this .depth = depth;
077: }
078:
079: public static HibernateTree createTree(int depth) {
080: return createTree(depth, 0);
081: }
082:
083: private static HibernateTree createTree(int maxDepth,
084: int currentDepth) {
085:
086: if (maxDepth <= 0) {
087: return null;
088: }
089:
090: HibernateTree tree = new HibernateTree();
091: if (currentDepth == 0) {
092: tree.name = "root";
093: } else {
094: tree.name = "node at depth " + currentDepth;
095: }
096: tree.depth = currentDepth;
097: tree.preceding = createTree(maxDepth - 1, currentDepth + 1);
098: tree.subsequent = createTree(maxDepth - 1, currentDepth + 1);
099: return tree;
100: }
101:
102: public static void traverse(HibernateTree tree,
103: HibernateTreeVisitor visitor) {
104: if (tree == null) {
105: return;
106: }
107: traverse(tree.preceding, visitor);
108: traverse(tree.subsequent, visitor);
109: visitor.visit(tree);
110: }
111:
112: }
|