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