View Javadoc

    1   package org.codehaus.groovy.runtime;
    2
    3   import groovy.lang.Closure;
    4   import groovy.lang.MetaClass;
    5
    6   import java.util.ArrayList;
    7   import java.util.List;
    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 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  }