Class ImmutableEvolutionStep.Builder<T extends Comparable<T>,U>

java.lang.Object
net.bmahe.genetics4j.extras.evolutionlisteners.ImmutableEvolutionStep.Builder<T,U>
Direct Known Subclasses:
EvolutionStep.Builder
Enclosing class:
ImmutableEvolutionStep<T extends Comparable<T>,U>

public static class ImmutableEvolutionStep.Builder<T extends Comparable<T>,U> extends Object
Builds instances of type ImmutableEvolutionStep. Initialize attributes and then invoke the build() method to create an immutable instance.

Builder is not thread-safe and generally should not be stored in a field or collection, but instead used immediately to create instances.

  • Field Details

    • INIT_BIT_GENERATION

      private static final long INIT_BIT_GENERATION
      See Also:
    • INIT_BIT_INDIVIDUAL_INDEX

      private static final long INIT_BIT_INDIVIDUAL_INDEX
      See Also:
    • INIT_BIT_INDIVIDUAL

      private static final long INIT_BIT_INDIVIDUAL
      See Also:
    • INIT_BIT_FITNESS

      private static final long INIT_BIT_FITNESS
      See Also:
    • INIT_BIT_IS_DONE

      private static final long INIT_BIT_IS_DONE
      See Also:
    • initBits

      private long initBits
    • context

      private U context
    • generation

      private long generation
    • individualIndex

      private int individualIndex
    • individual

      private Genotype individual
    • fitness

      private T extends Comparable<T> fitness
    • isDone

      private boolean isDone
  • Constructor Details

    • Builder

      public Builder()
      Creates a builder for ImmutableEvolutionStep instances.
       new EvolutionStep.Builder&lt;T, U&gt;()
          .context(U) // optional context
          .generation(long) // required generation
          .individualIndex(int) // required individualIndex
          .individual(net.bmahe.genetics4j.core.Genotype) // required individual
          .fitness(T) // required fitness
          .isDone(boolean) // required isDone
          .build();
       
  • Method Details

    • from

      public final EvolutionStep.Builder<T,U> from(EvolutionStep<T,U> instance)
      Fill a builder with attribute values from the provided EvolutionStep instance. Regular attribute values will be replaced with those from the given instance. Absent optional values will not replace present values.
      Parameters:
      instance - The instance from which to copy values
      Returns:
      this builder for use in a chained invocation
    • context

      public final EvolutionStep.Builder<T,U> context(U context)
      Initializes the optional value context to context.
      Parameters:
      context - The value for context
      Returns:
      this builder for chained invocation
    • context

      public final EvolutionStep.Builder<T,U> context(Optional<? extends U> context)
      Initializes the optional value context to context.
      Parameters:
      context - The value for context
      Returns:
      this builder for use in a chained invocation
    • generation

      public final EvolutionStep.Builder<T,U> generation(long generation)
      Initializes the value for the generation attribute.
      Parameters:
      generation - The value for generation
      Returns:
      this builder for use in a chained invocation
    • individualIndex

      public final EvolutionStep.Builder<T,U> individualIndex(int individualIndex)
      Initializes the value for the individualIndex attribute.
      Parameters:
      individualIndex - The value for individualIndex
      Returns:
      this builder for use in a chained invocation
    • individual

      public final EvolutionStep.Builder<T,U> individual(Genotype individual)
      Initializes the value for the individual attribute.
      Parameters:
      individual - The value for individual
      Returns:
      this builder for use in a chained invocation
    • fitness

      public final EvolutionStep.Builder<T,U> fitness(T fitness)
      Initializes the value for the fitness attribute.
      Parameters:
      fitness - The value for fitness
      Returns:
      this builder for use in a chained invocation
    • isDone

      public final EvolutionStep.Builder<T,U> isDone(boolean isDone)
      Initializes the value for the isDone attribute.
      Parameters:
      isDone - The value for isDone
      Returns:
      this builder for use in a chained invocation
    • build

      public ImmutableEvolutionStep<T,U> build()
      Returns:
      An immutable instance of EvolutionStep
      Throws:
      IllegalStateException - if any required attributes are missing
    • formatRequiredAttributesMessage

      private String formatRequiredAttributesMessage()