<commit_before>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    <NAME> (<EMAIL>)
 */
package org.jenetics.engine;

import java.util.function.Predicate;

import org.jenetics.internal.util.require;

/**
 * This class contains factory methods for creating predicates, which can be
 * used for limiting the evolution stream.
 *
 * @see EvolutionStream#limit(Predicate)
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since 3.0
 * @version 3.0 &mdash; <em>$Date: 2014-10-22 $</em>
 */
public final class limit {
	private limit() {require.noInstance();}


	/**
	 * Return a predicate, which will truncate the evolution stream if no
	 * better phenotype could be found after the given number of
	 * {@code generations}.
	 *
	 * [code]
	 * final Phenotype&lt;DoubleGene, Double&gt; result = engine.stream()
	 *      // Truncate the evolution stream after 5 "steady" generations.
	 *     .limit(bySteadyFitness(5))
	 *      // The evolution will stop after maximal 100 generations.
	 *     .limit(100)
	 *     .collect(toBestPhenotype());
	 * [/code]
	 *
	 * @param generations the number of <i>steady</i> generations
	 * @param <C> the fitness type
	 * @return a predicate which truncate the evolution stream if no better
	 *         phenotype could be found after a give number of
	 *         {@code generations}
	 * @throws IllegalArgumentException if the generation is smaller than
	 *         one.
	 */
	public static <C extends Comparable<? super C>>
	Predicate<EvolutionResult<?, C>> bySteadyFitness(final int generations) {
		return new SteadyFitnessLimit<>(generations);
	}

}<commit_msg>Add factory methods for new evolution stream truncation strategy.<commit_after>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    <NAME> (<EMAIL>)
 */
package org.jenetics.engine;

import java.time.Clock;
import java.time.Duration;
import java.util.function.Predicate;

import org.jenetics.internal.util.NanoClock;
import org.jenetics.internal.util.require;

/**
 * This class contains factory methods for creating predicates, which can be
 * used for limiting the evolution stream.
 *
 * @see EvolutionStream#limit(Predicate)
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since 3.0
 * @version 3.0 &mdash; <em>$Date: 2015-01-06 $</em>
 */
public final class limit {
	private limit() {require.noInstance();}


	/**
	 * Return a predicate, which will truncate the evolution stream if no
	 * better phenotype could be found after the given number of
	 * {@code generations}.
	 *
	 * [code]
	 * final Phenotype&lt;DoubleGene, Double&gt; result = engine.stream()
	 *      // Truncate the evolution stream after 5 "steady" generations.
	 *     .limit(bySteadyFitness(5))
	 *      // The evolution will stop after maximal 100 generations.
	 *     .limit(100)
	 *     .collect(toBestPhenotype());
	 * [/code]
	 *
	 * @param generations the number of <i>steady</i> generations
	 * @param <C> the fitness type
	 * @return a predicate which truncate the evolution stream if no better
	 *         phenotype could be found after a give number of
	 *         {@code generations}
	 * @throws IllegalArgumentException if the generation is smaller than
	 *         one.
	 */
	public static <C extends Comparable<? super C>>
	Predicate<EvolutionResult<?, C>> bySteadyFitness(final int generations) {
		return new SteadyFitnessLimit<>(generations);
	}

	/**
	 * Return a predicate, which will truncate the evolution stream if the GA
	 * execution exceeds a given time duration. This predicate is (normally)
	 * used as safety net, for guaranteed stream truncation.
	 *
	 * [code]
	 * final Phenotype&lt;DoubleGene, Double&gt; result = engine.stream()
	 *      // Truncate the evolution stream after 5 "steady" generations.
	 *     .limit(bySteadyFitness(5))
	 *      // The evolution will stop after maximal 500 ms.
	 *     .limit(byExecutionTime(Duration.ofMillis(500), Clock.systemUTC())
	 *     .collect(toBestPhenotype());
	 * [/code]
	 *
	 * @param duration the duration after the evolution stream will be truncated
	 * @param clock the clock used for measure the execution time
	 * @return a predicate, which will truncate the evolution stream, based on
	 *         the exceeded execution time
	 * @throws NullPointerException if one of the arguments is {@code null}
	 */
	public static Predicate<EvolutionResult<?, ?>>
	byExecutionTime(final Duration duration, final Clock clock) {
		return new ExecutionTimeLimit(duration, clock);
	}

	/**
	 * Return a predicate, which will truncate the evolution stream if the GA
	 * execution exceeds a given time duration. This predicate is (normally)
	 * used as safety net, for guaranteed stream truncation.
	 *
	 * [code]
	 * final Phenotype&lt;DoubleGene, Double&gt; result = engine.stream()
	 *      // Truncate the evolution stream after 5 "steady" generations.
	 *     .limit(bySteadyFitness(5))
	 *      // The evolution will stop after maximal 500 ms.
	 *     .limit(byExecutionTime(Duration.ofMillis(500))
	 *     .collect(toBestPhenotype());
	 * [/code]
	 *
	 * @param duration the duration after the evolution stream will be truncated
	 * @return a predicate, which will truncate the evolution stream, based on
	 *         the exceeded execution time
	 * @throws NullPointerException if one of the arguments is {@code null}
	 */
	public static Predicate<EvolutionResult<?, ?>>
	byExecutionTime(final Duration duration) {
		return new ExecutionTimeLimit(duration, NanoClock.INSTANCE);
	}

}
{'fraction_non_alphanumeric': 0.10161870503597123, 'fraction_numerical': 0.009592326139088728, 'mean_word_length': 3.6308119361554474, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3519285', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1794, 'n_words': 714}