/*
 * 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 java.util.Arrays;

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 Alt<G, C> _alterer;

	private IndexedAlterer(final Alt<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>> pop  = section.split(population);
		final AltererResult<G, C> result = alterer.alter(pop, generation);

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


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

		private Alt(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();
		}

		@Override
		public int hashCode() {
			return Arrays.hashCode(indices);
		}

		@Override
		public boolean equals(final Object obj) {
			return obj == this ||
				obj instanceof Section &&
				Arrays.equals(((Section)obj).indices, indices);
		}

		@Override
		public String toString() {
			return Arrays.toString(indices);
		}

	}


}

@@ -812,34 +812,8 @@
 l;%0A%0A
-import java.util.Arrays;%0A%0A
 impo
@@ -1137,27 +1137,32 @@
 ivate final 
+S
 Alt
+erer
 %3CG, C%3E _alte
@@ -1197,19 +1197,24 @@
 r(final 
+S
 Alt
+erer
 %3CG, C%3E a
@@ -1499,19 +1499,21 @@
 %3CG, C%3E%3E 
-pop
+split
   = sect
@@ -1586,19 +1586,21 @@
 r.alter(
-pop
+split
 , genera
@@ -1753,19 +1753,24 @@
 l class 
+S
 Alt
+erer
 %3C%0A%09%09G ex
@@ -1893,19 +1893,24 @@
 private 
+S
 Alt
+erer
 (final S
@@ -2536,337 +2536,8 @@
 %09%7D%0A%0A
-%09%09@Override%0A%09%09public int hashCode() %7B%0A%09%09%09return Arrays.hashCode(indices);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public boolean equals(final Object obj) %7B%0A%09%09%09return obj == this %7C%7C%0A%09%09%09%09obj instanceof Section &&%0A%09%09%09%09Arrays.equals(((Section)obj).indices, indices);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public String toString() %7B%0A%09%09%09return Arrays.toString(indices);%0A%09%09%7D%0A%0A
 %09%7D%0A%0A

Implement indexed alterer.