01 /*
02 * Java Genetic Algorithm Library (jenetics-3.9.0).
03 * Copyright (c) 2007-2017 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@gmx.at)
19 */
20 package org.jenetics;
21
22 import org.jenetics.util.Factory;
23 import org.jenetics.util.Verifiable;
24
25 /**
26 * Genes are the atoms of the <em>Jenetics</em> library. They contain the actual
27 * information (alleles) of the encoded solution. All implementations of the
28 * this interface are final, immutable and can be only created via static
29 * factory methods which have the name {@code of}. When extending the library
30 * with own {@code Gene} implementations, it is recommended to also implement it
31 * as <a href="https://en.wikipedia.org/wiki/Value_object">value objects</a>.
32 *
33 * @see <a href="https://en.wikipedia.org/wiki/Value_object">Value object</a>
34 *
35 * @param <A> the <a href="http://en.wikipedia.org/wiki/Allele">Allele</a> type
36 * of this gene.
37 *
38 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
39 * @since 1.0
40 * @version 3.1
41 */
42 public interface Gene<A, G extends Gene<A, G>>
43 extends
44 Factory<G>,
45 Verifiable
46 {
47
48 /**
49 * Return the allele of this gene.
50 *
51 * @return the allele of this gene.
52 */
53 public A getAllele();
54
55 /**
56 * Return a new, random gene with the same type and with the same constraints
57 * than this gene. For all genes returned by this method holds
58 * {@code gene.getClass() == gene.newInstance().getClass()}. Implementations
59 * of this method has to use the {@link java.util.Random} object which can
60 * be fetched from the {@link org.jenetics.util.RandomRegistry}.
61 */
62 @Override
63 public G newInstance();
64
65 /**
66 * Create a new gene from the given {@code value} and the gene context.
67 *
68 * @since 2.0
69 * @param value the value of the new gene.
70 * @return a new gene with the given value.
71 */
72 public G newInstance(final A value);
73
74 }
|