/** * Returns an int 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 int[] toArray(final int[] array) { final int[] a = array.length >= length() ? array : new int[length()]; for (int i = length(); --i >= 0;) { a[i] = intValue(i); } return a; }
private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(length()); out.writeObject(lengthRange()); out.writeInt(_min); out.writeInt(_max); for (IntegerGene gene : _genes) { out.writeInt(gene.getAllele()); } }
/** * Returns a sequential stream of the alleles with this chromosome as its * source. * * @since 4.3 * * @return a sequential stream of alleles */ public IntStream intStream() { return IntStream.range(0, length()).map(this::intValue); }
/** * Returns an int 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 int[] toArray() { return toArray(new int[length()]); }
static void write(final IntegerChromosome ch, final XMLStreamWriter xml) throws XMLStreamException { xml.writeStartElement("int-chromosome"); xml.writeAttribute("length", Integer.toString(ch.length())); xml.writeStartElement("min"); xml.writeCharacters(ch.getMin().toString()); xml.writeEndElement(); xml.writeStartElement("max"); xml.writeCharacters(ch.getMax().toString()); xml.writeEndElement(); xml.writeStartElement("alleles"); for (IntegerGene gene : ch) { xml.writeStartElement("allele"); xml.writeCharacters(gene.getAllele().toString()); xml.writeEndElement(); } xml.writeEndElement(); xml.writeEndElement(); }