NumericChromosome.java
001 /*
002  * Java Genetic Algorithm Library (jenetics-4.1.0).
003  * Copyright (c) 2007-2018 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  */
020 package io.jenetics;
021 
022 /**
023  * Numeric chromosome interface.
024  *
025  @see NumericGene
026  *
027  @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
028  @since 1.6
029  @version 3.0
030  */
031 public interface NumericChromosome<
032     extends Number & Comparable<? super N>,
033     extends NumericGene<N, G>
034 >
035     extends BoundedChromosome<N, G>
036 {
037 
038     /**
039      * Return the byte value of this {@code NumericChromosome} at the given
040      * {@code index}.
041      *
042      @param index the index of the {@link NumericGene}.
043      @return the byte value of the {@link Gene} with the given {@code index}.
044      @throws IndexOutOfBoundsException if the index is out of range
045      *         (index &lt; 0 || index &gt;= length()).
046      */
047     public default byte byteValue(int index) {
048         return getGene(index).getAllele().byteValue();
049     }
050 
051     /**
052      * Return the byte value of this {@code NumericChromosome} at the
053      * {@code index} 0.
054      *
055      @return the byte value of the {@link Gene} with {@code index} 0.
056      */
057     public default byte byteValue() {
058         return byteValue(0);
059     }
060 
061     /**
062      * Return the short value of this {@code NumericChromosome} at the given
063      * {@code index}.
064      *
065      @param index the index of the {@link NumericGene}.
066      @return the short value of the {@link Gene} with the given {@code index}.
067      @throws IndexOutOfBoundsException if the index is out of range
068      *         (index &lt; 0 || index &gt;= length()).
069      */
070     public default short shortValue(int index) {
071         return getGene(index).getAllele().shortValue();
072     }
073 
074     /**
075      * Return the short value of this {@code NumericChromosome} at the
076      * {@code index} 0.
077      *
078      @return the short value of the {@link Gene} with {@code index} 0.
079      */
080     public default short shortValue() {
081         return shortValue(0);
082     }
083 
084     /**
085      * Return the int value of this {@code NumericChromosome} at the given
086      * {@code index}.
087      *
088      @param index the index of the {@link NumericGene}.
089      @return the int value of the {@link Gene} with the given {@code index}.
090      @throws IndexOutOfBoundsException if the index is out of range
091      *         (index &lt; 0 || index &gt;= length()).
092      */
093     public default int intValue(int index) {
094         return getGene(index).getAllele().intValue();
095     }
096 
097     /**
098      * Return the int value of this {@code NumericChromosome} at the
099      * {@code index} 0.
100      *
101      @return the int value of the {@link Gene} with {@code index} 0.
102      */
103     public default int intValue() {
104         return intValue(0);
105     }
106 
107     /**
108      * Return the long value of this {@code NumericChromosome} at the given
109      * {@code index}.
110      *
111      @param index the index of the {@link NumericGene}.
112      @return the long value of the {@link Gene} with the given {@code index}.
113      @throws IndexOutOfBoundsException if the index is out of range
114      *         (index &lt; 0 || index &gt;= length()).
115      */
116     public default long longValue(int index) {
117         return getGene(index).getAllele().longValue();
118     }
119 
120     /**
121      * Return the long value of this {@code NumericChromosome} at the
122      * {@code index} 0.
123      *
124      @return the long value of the {@link Gene} with {@code index} 0.
125      */
126     public default long longValue() {
127         return longValue(0);
128     }
129 
130     /**
131      * Return the float value of this {@code NumericChromosome} at the given
132      * {@code index}.
133      *
134      @param index the index of the {@link NumericGene}.
135      @return the float value of the {@link Gene} with the given {@code index}.
136      @throws IndexOutOfBoundsException if the index is out of range
137      *         (index &lt; 0 || index &gt;= length()).
138      */
139     public default float floatValue(int index) {
140         return getGene(index).getAllele().floatValue();
141     }
142 
143     /**
144      * Return the float value of this {@code NumericChromosome} at the
145      * {@code index} 0.
146      *
147      @return the float value of the {@link Gene} with {@code index} 0.
148      */
149     public default float floatValue() {
150         return floatValue(0);
151     }
152 
153     /**
154      * Return the double value of this {@code NumericChromosome} at the given
155      * {@code index}.
156      *
157      @param index the index of the {@link NumericGene}.
158      @return the double value of the {@link Gene} with the given {@code index}.
159      @throws IndexOutOfBoundsException if the index is out of range
160      *         (index &lt; 0 || index &gt;= length()).
161      */
162     public default double doubleValue(int index) {
163         return getGene(index).getAllele().doubleValue();
164     }
165 
166     /**
167      * Return the double value of this {@code NumericChromosome} at the
168      * {@code index} 0.
169      *
170      @return the double value of the {@link Gene} with {@code index} 0.
171      */
172     public default double doubleValue() {
173         return doubleValue(0);
174     }
175 
176 }