/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * 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:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
 */
package io.jenetics.engine;

import java.util.concurrent.atomic.AtomicBoolean;

import io.jenetics.Gene;
import io.jenetics.Phenotype;

/**
 * This class allows to force a reevaluation of the fitness function. A
 * reevaluation is necessary, if the fitness function changes. Changing the
 * fitness function is not the usual use case, but is necessary for some
 * problems, like symbolic regression analyses with changing input data (time
 * series).
 *
 * <pre>{@code
 * final var nullifier = new FitnessNullifier<DoubleGene, Double>();
 *
 * final Engine<DoubleGene, Double> engine =
 * 	new Engine.Builder<>(evaluator, genotype)
 * 		.interceptor(nullifier)
 * 		.populationSize(populationSize)
 * 		.build();
 *
 * // Invalidate fitness value by calling the 'nullifyFitness' method,
 * // possible from a different thread. This forces the reevaluation of
 * // the fitness values at the next generation.
 * nullifier.nullifyFitness();
 * }</pre>
 *
 * @param <G> the gene type
 * @param <C> the fitness result type
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 * @since !__version__!
 * @version !__version__!
 */
public final class FitnessNullifier<
	G extends Gene<?, G>,
	C extends Comparable<? super C>
>
	implements EvolutionInterceptor<G, C>
{

	private final AtomicBoolean _invalid = new AtomicBoolean(false);

	@Override
	public EvolutionStart<G, C> before(final EvolutionStart<G, C> start) {
		final boolean invalid = _invalid.getAndSet(false);
		return invalid ? invalidate(start) : start;
	}

	private EvolutionStart<G, C> invalidate(final EvolutionStart<G, C> start) {
		return EvolutionStart.of(
			start.population().map(Phenotype::nullifyFitness),
			start.generation()
		);
	}

	public void nullifyFitness() {
		_invalid.set(true);
	}

}

@@ -1326,24 +1326,16 @@
 ne =
-%0A * %09new
  Engine.
 Buil
@@ -1334,44 +1334,32 @@
 ine.
-B
+b
 uilder
-%3C%3E(evaluator, genotype
+(problem
 )%0A * 
-%09%09
+    
 .int
@@ -1385,47 +1385,12 @@
 %0A * 
-%09%09.populationSize(populationSize)%0A * %09%09
+    
 .bui
@@ -1573,16 +1573,29 @@
  at the 
+start of the 
 next gen
@@ -2060,16 +2060,437 @@
 alse);%0A%0A
+%09/**%0A%09 * Nullifies the fitness values of the population, if requested. The%0A%09 * %3Cem%3Enullification flag%3C/em%3E is reset after this call. Two consecutive%0A%09 * calls of this method might lead to two different results.%0A%09 *%0A%09 * @see #nullifyFitness()%0A%09 *%0A%09 * @param start the evolution start object%0A%09 * @return the evolution start object with the nullified fitness values,%0A%09 *         if the nullification has been triggered%0A%09 */%0A
 %09@Overri
@@ -2857,16 +2857,163 @@
 %09);%0A%09%7D%0A%0A
+%09/**%0A%09 * Triggers the nullification of the fitness values of the population for%0A%09 * the next generation.%0A%09 *%0A%09 * @see #before(EvolutionStart)%0A%09 */%0A
 %09public 

Add Javadoc.