1 7 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 ; 40 import java.util.Stack ; 41 import java.util.ArrayList ; 42 import java.util.Iterator ; 43 44 48 public class ThreadGroupIterator implements Iterator { 49 private final Stack stack = new Stack (); 50 51 public ThreadGroupIterator(List tgl) { 52 push(tgl); 53 } 54 55 public ThreadGroupIterator(ThreadGroupReference tg) { 56 List tgl = new ArrayList (); 57 tgl.add(tg); 58 push(tgl); 59 } 60 61 66 67 private Iterator top() { 68 return (Iterator )stack.peek(); 69 } 70 71 77 private void push(List 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 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 (); 100 } 101 102 114 } 115 116 | Popular Tags |