Class Writers.Genotype

java.lang.Object
io.jenetics.xml.Writers.Genotype
Enclosing class:
Writers

public static final class Writers.Genotype extends Object
This class contains static writer methods for Genotype objects.

Writer code

final Genotype<DoubleGene> gt = Genotype.of(
    DoubleChromosome.of(0.0, 1.0, 3),
    DoubleChromosome.of(0.0, 1.0, 2)
);
final Writer<Genotype<DoubleGene>> writer =
    Writers.Genotype.writer(Writers.DoubleChromosome.writer());

try (AutoCloseableXMLStreamWriter xml = XML.writer(System.out, "    ")) {
    writer.write(value, xml);
}
XML output
 
 <genotype length="2" ngenes="5">
     <double-chromosome length="3">
         <min>0.0</min>
         <max>1.0</max>
         <alleles>
             <allele>0.27251556008507416</allele>
             <allele>0.003140816229067145</allele>
             <allele>0.43947528327497376</allele>
         </alleles>
     </double-chromosome>
     <double-chromosome length="2">
         <min>0.0</min>
         <max>1.0</max>
         <alleles>
             <allele>0.4026521545744768</allele>
             <allele>0.36137605952663554</allele>
         <alleles>
     </double-chromosome>
 </genotype>
  
  • Method Details

    • writer

      public static <A, G extends Gene<A, G>, C extends Chromosome<G>> Writer<Genotype<G>> writer(Writer<? super C> writer)
      Create a writer for genotypes of arbitrary chromosomes. How to write the genotype chromosomes is defined by the given Writer.
      Type Parameters:
      A - the allele type
      G - the gene type
      C - the chromosome type
      Parameters:
      writer - the chromosome writer
      Returns:
      a new genotype writer
      Throws:
      NullPointerException - if the given chromosome writer is null
    • write

      public static <A, G extends Gene<A, G>, C extends Chromosome<G>> void write(OutputStream out, Genotype<G> data, String indent, Writer<? super C> chromosomeWriter) throws XMLStreamException
      Write the given Genotype to the given output stream.
      Type Parameters:
      A - the allele type
      G - the gene type
      C - the chromosome type
      Parameters:
      out - the target output stream
      data - the genotype to write
      indent - the XML level indentation
      chromosomeWriter - the chromosome writer used to write the genotypes
      Throws:
      XMLStreamException - if an error occurs while writing the chromosome
      NullPointerException - if the one of the arguments is null
    • write

      public static <A, G extends Gene<A, G>, C extends Chromosome<G>> void write(OutputStream out, Genotype<G> data, Writer<? super C> chromosomeWriter) throws XMLStreamException
      Write the given Genotype to the given output stream.
      Type Parameters:
      A - the allele type
      G - the gene type
      C - the chromosome type
      Parameters:
      out - the target output stream
      data - the genotype to write
      chromosomeWriter - the chromosome writer used to write the genotypes
      Throws:
      XMLStreamException - if an error occurs while writing the chromosome
      NullPointerException - if the one of the arguments is null