KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > graph > SearchTree


1 /*
2  * Generic graph library
3  * Copyright (C) 2000,2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 // $Revision: 1.6 $
21

22 package edu.umd.cs.findbugs.graph;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27
28 /**
29  * SearchTree represents a search tree produced by a graph
30  * search algorithm, such as BreadthFirstSearch or DepthFirstSearch.
31  */

32 public class SearchTree <VertexType extends GraphVertex<VertexType>> {
33
34     private VertexType m_vertex;
35     private ArrayList JavaDoc<SearchTree<VertexType>> m_childList;
36
37     /**
38      * Create a new search tree.
39      */

40     public SearchTree(VertexType v) {
41         m_vertex = v;
42         m_childList = new ArrayList JavaDoc<SearchTree<VertexType>>();
43     }
44
45     /**
46      * Get the vertex contained in this node.
47      */

48     public VertexType getVertex() {
49         return m_vertex;
50     }
51
52     /**
53      * Add a child search tree.
54      */

55     public void addChild(SearchTree<VertexType> child) {
56         m_childList.add(child);
57     }
58
59     /**
60      * Return collection of children of this search tree.
61      * (Elements returned are also SearchTree objects).
62      */

63     public Iterator JavaDoc<SearchTree<VertexType>> childIterator() {
64         return m_childList.iterator();
65     }
66
67     /**
68      * Add all vertices contained in this search tree to the given
69      * set.
70      */

71     public void addVerticesToSet(Set JavaDoc<VertexType> set) {
72         // Add the vertex for this object
73
set.add(this.m_vertex);
74
75         // Add vertices for all children
76
Iterator JavaDoc<SearchTree<VertexType>> i = childIterator();
77         while (i.hasNext()) {
78             SearchTree<VertexType> child = i.next();
79             child.addVerticesToSet(set);
80         }
81     }
82
83 }
84
85 // vim:ts=4
86
Popular Tags