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

java.lang.Object
net.bmahe.genetics4j.core.spec.selection.ImmutableTournament.Builder<T>
Direct Known Subclasses:
Tournament.Builder
Enclosing class:
ImmutableTournament<T extends Comparable<T>>

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

  • Constructor Details

    • Builder

      public Builder()
      Creates a builder for Tournament instances.
       new Tournament.Builder&lt;T&gt;()
          .numCandidates(int) // required numCandidates
          .comparator(Comparator&lt;net.bmahe.genetics4j.core.Individual&lt;T&gt;&gt;) // optional comparator
          .build();
       
  • Method Details

    • from

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

      public final Tournament.Builder<T> numCandidates(int numCandidates)
      Initializes the value for the numCandidates attribute.
      Parameters:
      numCandidates - The value for numCandidates
      Returns:
      this builder for use in a chained invocation
    • comparator

      public final Tournament.Builder<T> comparator(Comparator<Individual<T>> comparator)
      Initializes the value for the comparator attribute.

      If not set, this attribute will have a default value as returned by the initializer of comparator.

      Parameters:
      comparator - The value for comparator
      Returns:
      this builder for use in a chained invocation
    • build

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

      private String formatRequiredAttributesMessage()