001/*
002 * Java Genetic Algorithm Library (jenetics-8.0.0).
003 * Copyright (c) 2007-2024 Franz Wilhelmstötter
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 * Author:
018 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
019 */
020package io.jenetics;
021
022import static java.util.Objects.requireNonNull;
023
024import java.io.Serial;
025import java.io.Serializable;
026
027import io.jenetics.internal.util.Requires;
028import io.jenetics.util.ISeq;
029import io.jenetics.util.Seq;
030
031/**
032 * Represents the result pair of a {@link Alterer#alter(Seq, long)} call, which
033 * consists of the altered population and the number of altered individuals.
034 *
035 * @see Alterer
036 *
037 * @param population the altered population
038 * @param alterations the number of altered individuals
039 * @param <G> the gene type
040 * @param <C> the result type
041 *
042 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
043 * @since 4.0
044 * @version 7.0
045 */
046public record AltererResult<
047        G extends Gene<?, G>,
048        C extends Comparable<? super C>
049> (
050        ISeq<Phenotype<G, C>> population,
051        int alterations
052)
053        implements Serializable
054{
055        @Serial
056        private static final long serialVersionUID = 2L;
057
058        /**
059         * Create a new alter result for the given arguments.
060         *
061         * @param population the altered population
062         * @param alterations the number of altered individuals
063         * @throws NullPointerException if the given population is {@code null}
064         * @throws IllegalArgumentException if the given {@code alterations} is
065         *         negative
066         */
067        public AltererResult {
068                Requires.nonNegative(alterations);
069                requireNonNull(population);
070        }
071
072        /**
073         * Create a new alter result for the given population with zero alterations.
074         *
075         * @param population the altered population
076         * @throws NullPointerException if the given population is {@code null}
077         */
078        public AltererResult(ISeq<Phenotype<G, C>> population) {
079                this(population, 0);
080        }
081
082}