001 /*
002 * Java Genetic Algorithm Library (jenetics-3.9.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 * Base interface for numeric genes.
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 NumericGene<
030 N extends Number & Comparable<? super N>,
031 G extends NumericGene<N, G>
032 >
033 extends
034 BoundedGene<N, G>,
035 Comparable<G>
036 {
037
038 /**
039 * Returns the value of the specified gene as an byte. This may involve
040 * rounding or truncation.
041 *
042 * @return the numeric value represented by this object after conversion to
043 * type {@code byte}.
044 */
045 public default byte byteValue() {
046 return getAllele().byteValue();
047 }
048
049 /**
050 * Returns the value of the specified gene as an short. This may involve
051 * rounding or truncation.
052 *
053 * @return the numeric value represented by this object after conversion to
054 * type {@code short}.
055 */
056 public default short shortValue() {
057 return getAllele().shortValue();
058 }
059
060 /**
061 * Returns the value of the specified gene as an int. This may involve
062 * rounding or truncation.
063 *
064 * @return the numeric value represented by this object after conversion to
065 * type {@code int}.
066 */
067 public default int intValue() {
068 return getAllele().intValue();
069 }
070
071 /**
072 * Returns the value of the specified gene as an long. This may involve
073 * rounding or truncation.
074 *
075 * @return the numeric value represented by this object after conversion to
076 * type {@code long}.
077 */
078 public default long longValue() {
079 return getAllele().longValue();
080 }
081
082 /**
083 * Returns the value of the specified gene as an float. This may involve
084 * rounding or truncation.
085 *
086 * @return the numeric value represented by this object after conversion to
087 * type {@code float}.
088 */
089 public default float floatValue() {
090 return getAllele().floatValue();
091 }
092
093 /**
094 * Returns the value of the specified gene as an double. This may involve
095 * rounding or truncation.
096 *
097 * @return the numeric value represented by this object after conversion to
098 * type {@code double}.
099 */
100 public default double doubleValue() {
101 return getAllele().doubleValue();
102 }
103
104 @Override
105 public G newInstance(final Number number);
106
107 }
|