01: package org.codehaus.groovy.runtime;
02:
03: import groovy.lang.Closure;
04: import groovy.lang.MetaClass;
05:
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: /**
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: 1205 $
15: */
16: public class IteratorClosureAdapter extends Closure {
17:
18: private List list = new ArrayList();
19: private MetaClass metaClass = InvokerHelper.getMetaClass(this );
20:
21: public IteratorClosureAdapter(Object 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 asList() {
34: return list;
35: }
36:
37: protected Object doCall(Object argument) {
38: list.add(argument);
39: return null;
40: }
41: }
|