Gene.java
01 /*
02  * Java Genetic Algorithm Library (jenetics-4.0.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@gmail.com)
19  */
20 package io.jenetics;
21 
22 import io.jenetics.util.Factory;
23 import io.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  @see Chromosome
35  *
36  @param <A> the <a href="http://en.wikipedia.org/wiki/Allele">Allele</a> type
37  *         of this gene.
38  *
39  @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
40  @since 1.0
41  @version 3.1
42  */
43 public interface Gene<A, G extends Gene<A, G>>
44     extends
45         Factory<G>,
46         Verifiable
47 {
48 
49     /**
50      * Return the allele of this gene.
51      *
52      @return the allele of this gene.
53      */
54     public A getAllele();
55 
56     /**
57      * Return a new, random gene with the same type and with the same constraints
58      * than this gene. For all genes returned by this method holds
59      * {@code gene.getClass() == gene.newInstance().getClass()}. Implementations
60      * of this method has to use the {@link java.util.Random} object which can
61      * be fetched from the {@link io.jenetics.util.RandomRegistry}.
62      */
63     @Override
64     public G newInstance();
65 
66     /**
67      * Create a new gene from the given {@code value} and the gene context.
68      *
69      @since 2.0
70      @param value the value of the new gene.
71      @return a new gene with the given value.
72      */
73     public G newInstance(final A value);
74 
75 }