01 /*
02 * Java Genetic Algorithm Library (jenetics-3.0.0).
03 * Copyright (c) 2007-2014 Franz Wilhelmstötter
04 *
05 * Licensed under the Apache License, Version 2.0 (the "License");
06 * you may not use this file except in compliance with the License.
07 * You may obtain a copy of the License at
08 *
09 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author:
18 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19 */
20 package org.jenetics.engine;
21
22 import java.util.function.Predicate;
23 import java.util.stream.Stream;
24
25 import org.jenetics.Gene;
26
27 /**
28 * The {@code EvolutionStream} class extends the Java {@link Stream} and adds a
29 * method for limiting the evolution by a given predicate.
30 *
31 * @see java.util.stream.Stream
32 * @see Engine
33 *
34 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
35 * @since 3.0
36 * @version 3.0 — <em>$Date: 2014-12-28 $</em>
37 */
38 public interface EvolutionStream<
39 G extends Gene<?, G>,
40 C extends Comparable<? super C>
41 >
42 extends Stream<EvolutionResult<G, C>>
43 {
44
45 /**
46 * Returns a stream consisting of the elements of this stream, truncated
47 * when the given {@code proceed} predicate returns {@code false}.
48 * <p>
49 * <i>General usage example:</i>
50 * [code]
51 * final Phenotype<DoubleGene, Double> result = engine.stream()
52 * // Truncate the evolution stream after 5 "steady" generations.
53 * .limit(bySteadyFitness(5))
54 * // The evolution will stop after maximal 100 generations.
55 * .limit(100)
56 * .collect(toBestPhenotype());
57 * [/code]
58 *
59 * @see limit
60 *
61 * @param proceed the predicate which determines whether the stream is
62 * truncated or not. <i>If the predicate returns {@code false}, the
63 * evolution stream is truncated.</i>
64 * @return the new stream
65 * @throws NullPointerException if the given predicate is {@code null}.
66 */
67 public EvolutionStream<G, C>
68 limit(final Predicate<? super EvolutionResult<G, C>> proceed);
69
70 }
|