1
2
3
4
5
6
7
8
9
10
11 package org.mule.routing.outbound;
12
13 import java.util.Collection;
14 import java.util.Iterator;
15
16 import org.apache.commons.lang.Validate;
17 import org.mule.routing.AbstractMessageSequence;
18 import org.mule.routing.MessageSequence;
19
20
21
22
23
24
25
26
27
28 public final class CollectionMessageSequence<T> extends AbstractMessageSequence<T>
29 {
30 private final Iterator<T> iter;
31 private int remaining;
32
33 public CollectionMessageSequence(Collection<T> collection)
34 {
35 Validate.notNull(collection);
36 this.iter = collection.iterator();
37 this.remaining = collection.size();
38 }
39
40 public int size()
41 {
42 return remaining;
43 }
44
45 public boolean hasNext()
46 {
47 return iter.hasNext();
48 }
49
50 public T next()
51 {
52 T next = iter.next();
53 remaining--;
54 return next;
55 }
56
57 }