1 /*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14 package org.apache.commons.functor.generator;
15
16 import java.util.Collection;
17
18 import org.apache.commons.functor.UnaryFunction;
19 import org.apache.commons.functor.UnaryProcedure;
20
21 /**
22 * The Generator interface defines a number of useful actions applying UnaryFunctors
23 * to each in a series of argument Objects.
24 *
25 * @param <E> the type of elements held in this generator.
26 * @version $Revision: 1160786 $ $Date: 2011-08-23 18:40:12 +0200 (Tue, 23 Aug 2011) $
27 * @author Jason Horman (jason@jhorman.org)
28 * @author Rodney Waldhoff
29 */
30 public interface Generator<E> {
31 /**
32 * Generators must implement this method.
33 * @param proc UnaryProcedure to run
34 */
35 void run(UnaryProcedure<? super E> proc);
36
37 /**
38 * Stop the generator. Will stop the wrapped generator if one was set.
39 */
40 void stop();
41
42 /**
43 * Check if the generator is stopped.
44 * @return true if stopped
45 */
46 boolean isStopped();
47
48 /**
49 * Transforms this generator using the passed in
50 * transformer. An example transformer might turn the contents of the
51 * generator into a {@link Collection} of elements.
52 * @param <Z> the returned value type of the input {@link UnaryFunction}.
53 * @param transformer UnaryFunction to apply to this
54 * @return transformation result
55 */
56 <Z> Z to(UnaryFunction<Generator<? extends E>, ? extends Z> transformer);
57
58 /**
59 * Same as to(new CollectionTransformer(collection)).
60 * @param collection Collection to which my elements should be added
61 * @return <code>collection</code>
62 */
63 Collection<? super E> to(Collection<? super E> collection);
64
65 /**
66 * Same as to(new CollectionTransformer()).
67 * @return Collection
68 */
69 Collection<? super E> toCollection();
70 }