AbstractNumericChromosome.java
001 /*
002  * Java Genetic Algorithm Library (jenetics-1.6.0).
003  * Copyright (c) 2007-2014 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 import org.jenetics.util.ISeq;
023 
024 /**
025  * Abstract numeric chromosome.
026  *
027  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
028  @version 1.6 &mdash; <em>$Date: 2014-03-05 $</em>
029  @since 1.6
030  */
031 abstract class AbstractNumericChromosome<
032     extends Number & Comparable<? super N>,
033     extends AbstractNumericGene<N, G>
034 >
035     extends AbstractBoundedChromosome<N, G>
036     implements NumericChromosome<N, G>
037 {
038 
039     private static final long serialVersionUID = 1L;
040 
041     /**
042      * Create a new chromosome from the given genes array.
043      *
044      @param genes the genes of the new chromosome.
045      @throws IllegalArgumentException if the {@code genes.length()} is smaller
046      *          than one.
047      @throws NullPointerException if the {@code genes} are {@code null}.
048      */
049     protected AbstractNumericChromosome(final ISeq<? extends G> genes) {
050         super(genes);
051     }
052 
053     @Override
054     public byte byteValue(final int index) {
055         return getGene(index).getAllele().byteValue();
056     }
057 
058     @Override
059     public byte byteValue() {
060         return byteValue(0);
061     }
062 
063     @Override
064     public short shortValue(final int index) {
065         return getGene(index).getAllele().shortValue();
066     }
067 
068     @Override
069     public short shortValue() {
070         return shortValue(0);
071     }
072 
073     @Override
074     public int intValue(final int index) {
075         return getGene(index).getAllele().intValue();
076     }
077 
078     @Override
079     public int intValue() {
080         return intValue(0);
081     }
082 
083     @Override
084     public long longValue(final int index) {
085         return getGene(index).getAllele().longValue();
086     }
087 
088     @Override
089     public long longValue() {
090         return longValue(0);
091     }
092 
093     @Override
094     public float floatValue(final int index) {
095         return getGene(index).getAllele().floatValue();
096     }
097 
098     @Override
099     public float floatValue() {
100         return floatValue(0);
101     }
102 
103     @Override
104     public double doubleValue(final int index) {
105         return getGene(index).getAllele().doubleValue();
106     }
107 
108     @Override
109     public double doubleValue() {
110         return doubleValue(0);
111     }
112 
113 }