Class Writers.PermutationChromosome

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

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

Writer code

final PermutationChromosome<Integer> value =
    PermutationChromosome.ofInteger(5);

final Writer<PermutationChromosome<Integer>> writer =
    Writers.PermutationChromosome.writer();

try (AutoCloseableXMLStreamWriter xml = XML.writer(System.out, "    ")) {
    Writers.PermutationChromosome.writer().write(value, xml);
}
XML output
 
 <permutation-chromosome length="5">
     <valid-alleles type="java.lang.Integer">
         <allele>0</allele>
         <allele>1</allele>
         <allele>2</allele>
         <allele>3</allele>
         <allele>4</allele>
     </valid-alleles>
     <order>2 1 3 5 4</order>
 </permutation-chromosome>
  
  • Method Details

    • writer

      public static <A> Writer<PermutationChromosome<A>> writer(Writer<? super A> alleleWriter)
      Create a writer for permutation-chromosomes. How to write the valid alleles is defined by the given Writer.
      Type Parameters:
      A - the allele type
      Parameters:
      alleleWriter - the allele writer
      Returns:
      a new permutation chromosome writer
      Throws:
      NullPointerException - if the given allele writer is null
    • writer

      public static <A> Writer<PermutationChromosome<A>> writer()
      Create a writer for permutation-chromosomes. The valid alleles are serialized by calling the Object.toString() method. Calling this method is equivalent with:
      final Writer<PermutationChromosome<Double>> writer =
          PermutationChromosome.write(text().map(Objects::toString));
      
      Example output:
       
       <permutation-chromosome length="15">
           <valid-alleles type="java.lang.Double">
               <allele>0.27251556008507416</allele>
               <allele>0.003140816229067145</allele>
               <allele>0.43947528327497376</allele>
               <allele>0.10654807463069327</allele>
               <allele>0.19696530915810317</allele>
               <allele>0.7450003838065538</allele>
               <allele>0.5594416969271359</allele>
               <allele>0.02823782430152355</allele>
               <allele>0.5741102315010789</allele>
               <allele>0.4533651041367144</allele>
               <allele>0.811148141800367</allele>
               <allele>0.5710456351848858</allele>
               <allele>0.30166768355230955</allele>
               <allele>0.5455492865240272</allele>
               <allele>0.21068427527733102</allele>
           </valid-alleles>
           <order>13 12 4 6 8 14 7 2 11 5 3 0 9 10 1</order>
       </permutation-chromosome>
        
      Type Parameters:
      A - the allele type
      Returns:
      a new permutation chromosome writer
    • write

      public static <A> void write(OutputStream out, PermutationChromosome<A> data, String indent) throws XMLStreamException
      Write the given PermutationChromosome to the given output stream.
      Type Parameters:
      A - the allele type
      Parameters:
      out - the target output stream
      data - the chromosome to write
      indent - the XML level indentation
      Throws:
      XMLStreamException - if an error occurs while writing the chromosome
      NullPointerException - if the chromosome or output stream is null
    • write

      public static <A> void write(OutputStream out, PermutationChromosome<A> data, String indent, Writer<? super A> alleleWriter) throws XMLStreamException
      Write the given PermutationChromosome to the given output stream.
      Type Parameters:
      A - the allele type
      Parameters:
      out - the target output stream
      data - the chromosome to write
      indent - the XML level indentation
      alleleWriter - the allele writer of the permutation chromosome
      Throws:
      XMLStreamException - if an error occurs while writing the chromosome
      NullPointerException - if the chromosome or output stream is null
    • write

      public static <A> void write(OutputStream out, PermutationChromosome<A> data) throws XMLStreamException
      Write the given PermutationChromosome to the given output stream.
      Type Parameters:
      A - the allele type
      Parameters:
      out - the target output stream
      data - the chromosome to write
      Throws:
      XMLStreamException - if an error occurs while writing the chromosome
      NullPointerException - if the chromosome or output stream is null
    • write

      public static <A> void write(OutputStream out, PermutationChromosome<A> data, Writer<? super A> alleleWriter) throws XMLStreamException
      Write the given PermutationChromosome to the given output stream.
      Type Parameters:
      A - the allele type
      Parameters:
      out - the target output stream
      data - the chromosome to write
      alleleWriter - the allele writer used to write the chromosome alleles
      Throws:
      XMLStreamException - if an error occurs while writing the chromosome
      NullPointerException - if the chromosome or output stream is null