001 /*
002 * Java Genetic Algorithm Library (jenetics-4.3.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 * Base interface for numeric genes.
024 *
025 * @implSpec
026 * <em>Jenetics</em> requires that the individuals ({@link Genotype} and
027 * {@link Phenotype}) are not changed after they have been created. Therefore,
028 * all implementations of the {@code NumericGene} interface must also be
029 * <em>immutable</em>.
030 *
031 * @see NumericChromosome
032 *
033 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
034 * @since 1.6
035 * @version 3.0
036 */
037 public interface NumericGene<
038 N extends Number & Comparable<? super N>,
039 G extends NumericGene<N, G>
040 >
041 extends
042 BoundedGene<N, G>,
043 Comparable<G>
044 {
045
046 /**
047 * Returns the value of the specified gene as an byte. This may involve
048 * rounding or truncation.
049 *
050 * @return the numeric value represented by this object after conversion to
051 * type {@code byte}.
052 */
053 public default byte byteValue() {
054 return getAllele().byteValue();
055 }
056
057 /**
058 * Returns the value of the specified gene as an short. This may involve
059 * rounding or truncation.
060 *
061 * @return the numeric value represented by this object after conversion to
062 * type {@code short}.
063 */
064 public default short shortValue() {
065 return getAllele().shortValue();
066 }
067
068 /**
069 * Returns the value of the specified gene as an int. This may involve
070 * rounding or truncation.
071 *
072 * @return the numeric value represented by this object after conversion to
073 * type {@code int}.
074 */
075 public default int intValue() {
076 return getAllele().intValue();
077 }
078
079 /**
080 * Returns the value of the specified gene as an long. This may involve
081 * rounding or truncation.
082 *
083 * @return the numeric value represented by this object after conversion to
084 * type {@code long}.
085 */
086 public default long longValue() {
087 return getAllele().longValue();
088 }
089
090 /**
091 * Returns the value of the specified gene as an float. This may involve
092 * rounding or truncation.
093 *
094 * @return the numeric value represented by this object after conversion to
095 * type {@code float}.
096 */
097 public default float floatValue() {
098 return getAllele().floatValue();
099 }
100
101 /**
102 * Returns the value of the specified gene as an double. This may involve
103 * rounding or truncation.
104 *
105 * @return the numeric value represented by this object after conversion to
106 * type {@code double}.
107 */
108 public default double doubleValue() {
109 return getAllele().doubleValue();
110 }
111
112 @Override
113 public G newInstance(final Number number);
114
115 }
|