1 7 34 35 package com.sun.tools.example.debug.tty; 36 37 import com.sun.jdi.ThreadGroupReference; 38 import com.sun.jdi.ThreadReference; 39 import java.util.List ; 40 import java.util.Stack ; 41 import java.util.ArrayList ; 42 import java.util.Iterator ; 43 44 48 class ThreadGroupIterator implements Iterator { 49 private final Stack stack = new Stack (); 50 51 ThreadGroupIterator(List tgl) { 52 push(tgl); 53 } 54 55 ThreadGroupIterator(ThreadGroupReference tg) { 56 List tgl = new ArrayList (); 57 tgl.add(tg); 58 push(tgl); 59 } 60 61 ThreadGroupIterator() { 62 this(Env.vm().topLevelThreadGroups()); 63 } 64 65 private Iterator top() { 66 return (Iterator )stack.peek(); 67 } 68 69 75 private void push(List tgl) { 76 stack.push(tgl.iterator()); 77 while (!stack.isEmpty() && !top().hasNext()) { 78 stack.pop(); 79 } 80 } 81 82 public boolean hasNext() { 83 return !stack.isEmpty(); 84 } 85 86 public Object next() { 87 return nextThreadGroup(); 88 } 89 90 public ThreadGroupReference nextThreadGroup() { 91 ThreadGroupReference tg = (ThreadGroupReference)top().next(); 92 push(tg.threadGroups()); 93 return tg; 94 } 95 96 public void remove() { 97 throw new UnsupportedOperationException (); 98 } 99 100 static ThreadGroupReference find(String name) { 101 ThreadGroupIterator tgi = new ThreadGroupIterator(); 102 while (tgi.hasNext()) { 103 ThreadGroupReference tg = tgi.nextThreadGroup(); 104 if (tg.name().equals(name)) { 105 return tg; 106 } 107 } 108 return null; 109 } 110 111 } 112 113 | Popular Tags |