KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > runtime > IteratorClosureAdapter


1 package org.codehaus.groovy.runtime;
2
3 import groovy.lang.Closure;
4 import groovy.lang.MetaClass;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.List JavaDoc;
8
9 /**
10  * A closure which stores calls in a List so that method calls
11  * can be iterated over in a 'yield' style way
12  *
13  * @author <a HREF="mailto:james@coredevelopers.net">James Strachan</a>
14  * @version $Revision: 1.2 $
15  */

16 public class IteratorClosureAdapter extends Closure {
17
18     private List JavaDoc list = new ArrayList JavaDoc();
19     private MetaClass metaClass = InvokerHelper.getMetaClass(this);
20     
21     public IteratorClosureAdapter(Object JavaDoc delegate) {
22         super(delegate);
23     }
24
25     public MetaClass getMetaClass() {
26         return metaClass;
27     }
28
29     public void setMetaClass(MetaClass metaClass) {
30         this.metaClass = metaClass;
31     }
32     
33     public List JavaDoc asList() {
34         return list;
35     }
36
37     protected Object JavaDoc doCall(Object JavaDoc argument) {
38         list.add(argument);
39         return null;
40     }
41 }
42
Popular Tags