/*
 * 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;

import static java.util.Objects.requireNonNull;

import io.jenetics.util.ISeq;
import io.jenetics.util.Seq;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
 * @version !__version__!
 * @since !__version__!
 */
final class IndexedAlterer<
	G extends Gene<?, G>,
	C extends Comparable<? super C>
>
	implements Alterer<G, C>
{

	private final SAlterer<G, C> _alterer;

	private IndexedAlterer(final SAlterer<G, C> alterer) {
		_alterer = requireNonNull(alterer);
	}

	@Override
	public AltererResult<G, C>
	alter(final Seq<Phenotype<G, C>> population, final long generation) {
		final Section section = _alterer.section;
		final Alterer<G, C> alterer = _alterer.alterer;

		final Seq<Phenotype<G, C>> split  = section.split(population);
		final AltererResult<G, C> result = alterer.alter(split, generation);

		return AltererResult.of(
			section.merge(result.getPopulation(), population),
			result.getAlterations()
		);
	}


	private static final class SAlterer<
		G extends Gene<?, G>,
		C extends Comparable<? super C>
	> {
		final Section section;
		final Alterer<G, C> alterer;

		private SAlterer(final Section section, final Alterer<G, C> alterer) {
			this.section = requireNonNull(section);
			this.alterer = requireNonNull(alterer);
		}
	}


	static final class Section {
		final int[] indices;

		Section(final int[] indices) {
			this.indices = indices;
		}

		<G extends Gene<?, G>, C extends Comparable<? super C>>
		Seq<Phenotype<G, C>>
		split(final Seq<Phenotype<G, C>> population) {
			return null;
		}

		<G extends Gene<?, G>, C extends Comparable<? super C>>
		ISeq<Phenotype<G, C>> merge(
			final Seq<Phenotype<G, C>> section,
			final Seq<Phenotype<G, C>> population
		) {
			return population.asISeq();
		}

	}


}

@@ -819,26 +819,92 @@
 ort 
-io.jenetics.util.I
+java.util.stream.IntStream;%0A%0Aimport io.jenetics.util.ISeq;%0Aimport io.jenetics.util.M
 Seq;
@@ -2316,19 +2316,17 @@
 e%3CG, C%3E%3E
-%0A%09%09
+ 
 split(fi
@@ -2378,12 +2378,542 @@
 urn 
-null
+population.map(this::split);%0A%09%09%7D%0A%0A%09%09%3CG extends Gene%3C?, G%3E, C extends Comparable%3C? super C%3E%3E%0A%09%09Phenotype%3CG, C%3E split(final Phenotype%3CG, C%3E phenotype) %7B%0A%09%09%09final ISeq%3CChromosome%3CG%3E%3E chromosomes = IntStream.of(indices)%0A%09%09%09%09.mapToObj(phenotype.getGenotype()::get)%0A%09%09%09%09.collect(ISeq.toISeq());%0A%0A%09%09%09final Genotype%3CG%3E genotype = Genotype.of(chromosomes);%0A%0A%09%09%09return phenotype.isEvaluated()%0A%09%09%09%09? Phenotype.of(%0A%09%09%09%09%09genotype,%0A%09%09%09%09%09phenotype.getGeneration(),%0A%09%09%09%09%09phenotype.getFitness())%0A%09%09%09%09: Phenotype.of(genotype, phenotype.getGeneration())
 ;%0A%09%09
@@ -3097,28 +3097,172 @@
 %0A%09%09%09
-return population.as
+final MSeq%3CPhenotype%3CG, C%3E%3E pop = population.asMSeq();%0A%09%09%09for (int i = 0; i %3C indices.length; ++i) %7B%0A%09%09%09%09pop.set(indices%5Bi%5D, section.get(i));%0A%09%09%09%7D%0A%0A%09%09%09return pop.to
 ISeq

Implement indexed alterer.