Class ImmutableIndividual.Builder<T extends Comparable<T>>

java.lang.Object
net.bmahe.genetics4j.core.ImmutableIndividual.Builder<T>
Enclosing class:
ImmutableIndividual<T extends Comparable<T>>

public static final class ImmutableIndividual.Builder<T extends Comparable<T>> extends Object
Builds instances of type ImmutableIndividual. 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_GENOTYPE

      private static final long INIT_BIT_GENOTYPE
      See Also:
    • INIT_BIT_FITNESS

      private static final long INIT_BIT_FITNESS
      See Also:
    • initBits

      private long initBits
    • genotype

      private Genotype genotype
    • fitness

      private T extends Comparable<T> fitness
  • Constructor Details

    • Builder

      private Builder()
  • Method Details

    • from

      public final ImmutableIndividual.Builder<T> from(Individual<T> instance)
      Fill a builder with attribute values from the provided Individual 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
    • genotype

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

      public final ImmutableIndividual.Builder<T> 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
    • build

      public ImmutableIndividual<T> build()
      Builds a new ImmutableIndividual.
      Returns:
      An immutable instance of Individual
      Throws:
      IllegalStateException - if any required attributes are missing
    • formatRequiredAttributesMessage

      private String formatRequiredAttributesMessage()