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