/**
 * Copyright 2005-2007 Yu Zhang
 * Distributed under the GNU General Public License 2.0
 */

package com.xruby.runtime.value;

import java.util.Vector;
import java.util.List;

import com.xruby.runtime.lang.RubyBasic;
import com.xruby.runtime.lang.RubyRuntime;

public class RubyThreadGroup extends RubyBasic{
    
    private List<RubyThread> threads_ = new Vector<RubyThread>();
    
    public static RubyThreadGroup defaultThreadGroup = new RubyThreadGroup();   
    
    public RubyThreadGroup(){
        super(RubyRuntime.ThreadGroupClass);
    }
    
    public void add(RubyThread thread){
        if(thread.getThreadGroup() != ObjectFactory.NIL_VALUE){
            RubyThreadGroup group = (RubyThreadGroup)thread.getThreadGroup();
            group.threads_.remove(thread);
        }
        thread.setThreadGroup(this);
        threads_.add(thread);
    }
    
    //When a thread terminates,remove it from this group.
    public void remove(RubyThread thread){
        thread.setThreadGroup(null);
        threads_.remove(thread);
    }
    
    public List list(){
        return threads_;
    }

}

@@ -148,22 +148,20 @@
 va.util.
-Vector
+List
 ;%0D%0Aimpor
@@ -172,20 +172,22 @@
 va.util.
-List
+Vector
 ;%0D%0A%0D%0Aimp
@@ -225,16 +225,62 @@
 Basic;%0D%0A
+import com.xruby.runtime.lang.RubyException;%0D%0A
 import c
@@ -368,24 +368,63 @@
 sic%7B%0D%0A    %0D%0A
+    private boolean enclosed = false;%0D%0A
     private 
@@ -843,24 +843,176 @@
 adGroup();%0D%0A
+            if(group.isEnclosed())%0D%0A                throw new RubyException(RubyRuntime.ThreadErrorClass,%22can't move from the enclosed thread group%22);%0D%0A
             
@@ -1382,13 +1382,151 @@
 %0A    %7D%0D%0A
+    %0D%0A    public void enclose()%7B%0D%0A        enclosed = true;%0D%0A    %7D%0D%0A    %0D%0A    public boolean isEnclosed()%7B%0D%0A        return enclosed;%0D%0A    %7D
 %0D%0A%7D%0D%0A

the function about enclose