/*
 * 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@gmx.at)
 */
package org.jenetics.engine;

import static java.lang.String.format;

import java.util.Arrays;

import org.testng.annotations.Test;

import org.jenetics.DoubleGene;
import org.jenetics.Genotype;
import org.jenetics.util.DoubleRange;
import org.jenetics.util.ISeq;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @version !__version__!
 * @since !__version__!
 */
public class CompositeCodecTest {

	@Test
	public void encoding() {
		final Codec<String, DoubleGene> codec = new CompositeCodec<>(
			ISeq.of(
				codecs.ofScalar(DoubleRange.of(0, 1)),
				codecs.ofVector(DoubleRange.of(10, 100), 3),
				codecs.ofScalar(DoubleRange.of(2, 3)),
				codecs.ofVector(DoubleRange.of(200, 500), DoubleRange.of(200, 500))
			),
			this::map
		);

		Genotype<DoubleGene> gt = codec.encoding().newInstance();
		System.out.println(gt);
		System.out.println(codec.decoder().apply(gt));
	}

	private String map(final Object[] values) {
		final Double v1 = (Double)values[0];
		final double[] v2 = (double[])values[1];
		final Double v3 = (Double)values[2];
		final double[] v4 = (double[])values[3];


		return format("%s:::%s:::%s:::%s", v1, Arrays.toString(v2), v3, Arrays.toString(v4));
 	}

}

@@ -820,19 +820,110 @@
 ava.
-util.Arrays
+time.Duration;%0Aimport java.time.LocalDate;%0Aimport java.util.Arrays;%0Aimport java.util.function.Function
 ;%0A%0Ai
@@ -954,24 +954,53 @@
 ions.Test;%0A%0A
+import org.jenetics.AnyGene;%0A
 import org.j
@@ -1049,16 +1049,113 @@
 notype;%0A
+import org.jenetics.LongChromosome;%0Aimport org.jenetics.LongGene;%0Aimport org.jenetics.Phenotype;%0A
 import o
@@ -1214,16 +1214,57 @@
 il.ISeq;
+%0Aimport org.jenetics.util.RandomRegistry;
 %0A%0A/**%0A *
@@ -2215,11 +2215,919 @@
 ));%0A
-
  %09%7D%0A%0A
+%09@Test%0A%09public void example() %7B%0A%09%09final Codec%3CLocalDate, LongGene%3E dateCodec1 = Codec.of(%0A%09%09%09Genotype.of(LongChromosome.of(0, 10_000)),%0A%09%09%09gt -%3E LocalDate.ofEpochDay(gt.getGene().longValue())%0A%09%09);%0A%0A%09%09final Codec%3CLocalDate, LongGene%3E dateCodec2 = Codec.of(%0A%09%09%09Genotype.of(LongChromosome.of(1_000_000, 10_000_000)),%0A%09%09%09gt -%3E LocalDate.ofEpochDay(gt.getGene().longValue())%0A%09%09);%0A%0A%09%09final Codec%3CDuration, LongGene%3E durationCodec = Codec.of(%0A%09%09%09dateCodec1,%0A%09%09%09dateCodec2,%0A%09%09%09(d1, d2) -%3E Duration.ofDays(d2.toEpochDay() - d1.toEpochDay())%0A%09%09);%0A%0A%09%09final Engine%3CLongGene, Long%3E engine = Engine%0A%09%09%09.builder(Duration::toMillis, durationCodec)%0A%09%09%09.build();%0A%0A%09%09final Phenotype%3CLongGene, Long%3E pt = engine.stream()%0A%09%09%09.limit(100)%0A%09%09%09.collect(EvolutionResult.toBestPhenotype());%0A%09%09System.out.println(pt);%0A%0A%09%09final Duration duration = durationCodec.decoder()%0A%09%09%09.apply(pt.getGenotype());%0A%09%09System.out.println(duration);%0A%09%7D%0A%0A
 %7D%0A

Add combining codec example.