View Javadoc

1   /*
2    * $Id: IteratorMessageSequence.java 22272 2011-06-27 16:17:16Z mike.schilling $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.routing.outbound;
12  
13  import java.util.Iterator;
14  
15  import org.apache.commons.lang.Validate;
16  import org.mule.routing.AbstractMessageSequence;
17  import org.mule.routing.MessageSequence;
18  
19  /**
20   * A {@link MessageSequence} that delegates its {@link #hasNext()} and
21   * {@link #next()} methods to an {@link Iterator}, and has no estimated size
22   * 
23   * @author flbulgarelli
24   * @param <T>
25   */
26  public final class IteratorMessageSequence<T> extends AbstractMessageSequence<T>
27  {
28      private final Iterator<T> iter;
29  
30      public IteratorMessageSequence(Iterator<T> iter)
31      {
32          Validate.notNull(iter);
33          this.iter = iter;
34      }
35  
36      public int size()
37      {
38          return UNKNOWN_SIZE;
39      }
40  
41      public boolean hasNext()
42      {
43          return iter.hasNext();
44      }
45  
46      public T next()
47      {
48          return iter.next();
49      }
50  
51  }