01 /*
02 * Java Genetic Algorithm Library (jenetics-8.0.0).
03 * Copyright (c) 2007-2024 Franz Wilhelmstötter
04 *
05 * Licensed under the Apache License, Version 2.0 (the "License");
06 * you may not use this file except in compliance with the License.
07 * You may obtain a copy of the License at
08 *
09 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author:
18 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
19 */
20 package io.jenetics;
21
22 import io.jenetics.util.Factory;
23 import io.jenetics.util.Self;
24 import io.jenetics.util.Verifiable;
25
26 /**
27 * Genes are the atoms of the <em>Jenetics</em> library. They contain the actual
28 * information (alleles) of the encoded solution. All implementations of the
29 * interface are final, immutable and can be only created via static
30 * factory methods which have the name {@code of}. When extending the library
31 * with own {@code Gene} implementations, it is recommended to also implement it
32 * as <a href="https://en.wikipedia.org/wiki/Value_object">value objects</a>.
33 *
34 * @implSpec
35 * <em>Jenetics</em> requires that the individuals ({@link Genotype} and
36 * {@link Phenotype}) are not changed after they have been created. Therefore,
37 * all implementations of the {@code Gene} interface must also be
38 * <em>immutable</em>.
39 *
40 * @see <a href="https://en.wikipedia.org/wiki/Value_object">Value object</a>
41 * @see Chromosome
42 *
43 * @param <A> the <a href="http://en.wikipedia.org/wiki/Allele">Allele</a> type
44 * of this gene.
45 *
46 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
47 * @since 1.0
48 * @version 6.0
49 */
50 public interface Gene<A, G extends Gene<A, G>>
51 extends
52 Self<G>,
53 Factory<G>,
54 Verifiable
55 {
56
57 /**
58 * Return the allele of this gene.
59 *
60 * @return the allele of this gene.
61 */
62 A allele();
63
64 /**
65 * Return a new, random gene with the same type and with the same constraints
66 * as this gene. For all genes returned by this method holds
67 * {@code gene.getClass() == gene.newInstance().getClass()}. Implementations
68 * of this method have to use the {@link java.util.Random} object which can
69 * be fetched from the {@link io.jenetics.util.RandomRegistry}.
70 */
71 @Override
72 G newInstance();
73
74 /**
75 * Create a new gene from the given {@code value} and the gene context.
76 *
77 * @since 2.0
78 * @param value the value of the new gene.
79 * @return a new gene with the given value.
80 */
81 G newInstance(final A value);
82
83 }
|