/** * Returns an char array containing all of the elements in this chromosome * in proper sequence. If the chromosome fits in the specified array, it is * returned therein. Otherwise, a new array is allocated with the length of * this chromosome. * * @since 3.0 * * @param array the array into which the elements of this chromosomes are to * be stored, if it is big enough; otherwise, a new array is * allocated for this purpose. * @return an array containing the elements of this chromosome * @throws NullPointerException if the given {@code array} is {@code null} */ public char[] toArray(final char[] array) { final char[] a = array.length >= length() ? array : new char[length()]; for (int i = length(); --i >= 0;) { a[i] = charAt(i); } return a; }
/** * Returns an char array containing all of the elements in this chromosome * in proper sequence. * * @since 3.0 * * @return an array containing the elements of this chromosome */ public char[] toArray() { return toArray(new char[length()]); }
private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(length()); out.writeObject(_validCharacters); for (CharacterGene gene : _genes) { out.writeChar(gene.getAllele()); } }