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>>
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 Summary
Modifier and TypeFieldDescriptionprivate Comparator
<Individual<T>> private static final long
private long
private int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a newTournament
.final Tournament.Builder
<T> comparator
(Comparator<Individual<T>> comparator) Initializes the value for thecomparator
attribute.private String
final Tournament.Builder
<T> from
(Tournament<T> instance) Fill a builder with attribute values from the providedTournament
instance.final Tournament.Builder
<T> numCandidates
(int numCandidates) Initializes the value for thenumCandidates
attribute.
-
Field Details
-
INIT_BIT_NUM_CANDIDATES
private static final long INIT_BIT_NUM_CANDIDATES- See Also:
-
initBits
private long initBits -
numCandidates
private int numCandidates -
comparator
-
-
Constructor Details
-
Builder
public Builder()Creates a builder forTournament
instances.new Tournament.Builder<T>() .numCandidates(int) // required
numCandidates
.comparator(Comparator<net.bmahe.genetics4j.core.Individual<T>>) // optionalcomparator
.build();
-
-
Method Details
-
from
Fill a builder with attribute values from the providedTournament
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
Initializes the value for thenumCandidates
attribute.- Parameters:
numCandidates
- The value for numCandidates- Returns:
this
builder for use in a chained invocation
-
comparator
Initializes the value for thecomparator
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
Builds a newTournament
.- Returns:
- An immutable instance of Tournament
- Throws:
IllegalStateException
- if any required attributes are missing
-
formatRequiredAttributesMessage
-