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

java.lang.Object
net.bmahe.genetics4j.moo.nsga2.spec.ImmutableNSGA2Selection.Builder<T>
Direct Known Subclasses:
NSGA2Selection.Builder
Enclosing class:
ImmutableNSGA2Selection<T extends Comparable<T>>

public static class ImmutableNSGA2Selection.Builder<T extends Comparable<T>> extends Object
Builds instances of type ImmutableNSGA2Selection. 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 ImmutableNSGA2Selection instances.
       new NSGA2Selection.Builder&lt;T&gt;()
          .numberObjectives(int) // required numberObjectives
          .dominance(Comparator&lt;T&gt;) // optional dominance
          .deduplicate(Optional&lt;Comparator&lt;net.bmahe.genetics4j.core.Genotype&gt;&gt;) // optional deduplicate
          .objectiveComparator(function.Function&lt;Integer, Comparator&lt;T&gt;&gt;) // required objectiveComparator
          .distance(net.bmahe.genetics4j.moo.ObjectiveDistance&lt;T&gt;) // required distance
          .build();
       
  • Method Details

    • from

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

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

      public final NSGA2Selection.Builder<T> dominance(Comparator<T> dominance)
      Initializes the value for the dominance attribute.

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

      Parameters:
      dominance - The value for dominance
      Returns:
      this builder for use in a chained invocation
    • deduplicate

      public final NSGA2Selection.Builder<T> deduplicate(Optional<Comparator<Genotype>> deduplicate)
      Initializes the value for the deduplicate attribute.

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

      Parameters:
      deduplicate - The value for deduplicate
      Returns:
      this builder for use in a chained invocation
    • objectiveComparator

      public final NSGA2Selection.Builder<T> objectiveComparator(Function<Integer,Comparator<T>> objectiveComparator)
      Initializes the value for the objectiveComparator attribute.
      Parameters:
      objectiveComparator - The value for objectiveComparator
      Returns:
      this builder for use in a chained invocation
    • distance

      public final NSGA2Selection.Builder<T> distance(ObjectiveDistance<T> distance)
      Initializes the value for the distance attribute.
      Parameters:
      distance - The value for distance
      Returns:
      this builder for use in a chained invocation
    • build

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

      private String formatRequiredAttributesMessage()