KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > bdi > ThreadGroupIterator


1 /*
2  * @(#)ThreadGroupIterator.java 1.10 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.bdi;
36
37 import com.sun.jdi.ThreadGroupReference;
38 import com.sun.jdi.ThreadReference;
39 import java.util.List JavaDoc;
40 import java.util.Stack JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.Iterator JavaDoc;
43             
44 /**
45  * Descend the tree of thread groups.
46  * @author Robert G. Field
47  */

48 public class ThreadGroupIterator implements Iterator JavaDoc {
49     private final Stack JavaDoc stack = new Stack JavaDoc();
50
51     public ThreadGroupIterator(List JavaDoc tgl) {
52         push(tgl);
53     }
54
55     public ThreadGroupIterator(ThreadGroupReference tg) {
56         List JavaDoc tgl = new ArrayList JavaDoc();
57         tgl.add(tg);
58         push(tgl);
59     }
60
61 /*
62     ThreadGroupIterator() {
63         this(Env.vm().topLevelThreadGroups());
64     }
65 */

66
67     private Iterator JavaDoc top() {
68         return (Iterator JavaDoc)stack.peek();
69     }
70
71     /**
72      * The invariant in this class is that the top iterator
73      * on the stack has more elements. If the stack is
74      * empty, there is no top. This method assures
75      * this invariant.
76      */

77     private void push(List JavaDoc tgl) {
78         stack.push(tgl.iterator());
79         while (!stack.isEmpty() && !top().hasNext()) {
80             stack.pop();
81         }
82     }
83
84     public boolean hasNext() {
85         return !stack.isEmpty();
86     }
87
88     public Object JavaDoc next() {
89         return nextThreadGroup();
90     }
91
92     public ThreadGroupReference nextThreadGroup() {
93         ThreadGroupReference tg = (ThreadGroupReference)top().next();
94         push(tg.threadGroups());
95         return tg;
96     }
97
98     public void remove() {
99         throw new UnsupportedOperationException JavaDoc();
100     }
101
102 /*
103     static ThreadGroupReference find(String name) {
104         ThreadGroupIterator tgi = new ThreadGroupIterator();
105         while (tgi.hasNext()) {
106             ThreadGroupReference tg = tgi.nextThreadGroup();
107             if (tg.name().equals(name)) {
108                 return tg;
109             }
110         }
111         return null;
112     }
113 */

114 }
115             
116
Popular Tags