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

java.lang.Object
net.bmahe.genetics4j.moo.spea2.spec.replacement.ImmutableSPEA2Replacement.Builder<T>
Direct Known Subclasses:
SPEA2Replacement.Builder
Enclosing class:
ImmutableSPEA2Replacement<T extends Comparable<T>>

public static class ImmutableSPEA2Replacement.Builder<T extends Comparable<T>> extends Object
Builds instances of type ImmutableSPEA2Replacement. 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 ImmutableSPEA2Replacement instances.
       new SPEA2Replacement.Builder&lt;T&gt;()
          .dominance(Comparator&lt;T&gt;) // optional dominance
          .deduplicate(Optional&lt;Comparator&lt;net.bmahe.genetics4j.core.Genotype&gt;&gt;) // optional deduplicate
          .k(Optional&lt;Integer&gt;) // optional k
          .distance(function.BiFunction&lt;T, T, Double&gt;) // required distance
          .build();
       
  • Method Details

    • from

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

      public final SPEA2Replacement.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 SPEA2Replacement.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
    • k

      Initializes the value for the k attribute.

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

      Parameters:
      k - The value for k
      Returns:
      this builder for use in a chained invocation
    • distance

      public final SPEA2Replacement.Builder<T> distance(BiFunction<T,T,Double> 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 ImmutableSPEA2Replacement<T> build()
      Returns:
      An immutable instance of SPEA2Replacement
      Throws:
      IllegalStateException - if any required attributes are missing
    • formatRequiredAttributesMessage

      private String formatRequiredAttributesMessage()