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