T - The target type: an instance of that type is associated with the builder instance
to hold the data to be collected during the build process.
That type is expected to be mutable, at least in the scope of the concrete builder implementation.B - The builder type: the intended effective type of the concrete builder implementation.public class Charger<T,B extends Charger<T,B>> extends BuilderBase<B> implements Setup<T,B>
<B> and as such provides a model that separates
basic builder concepts from the actual target data model <T>.
This implementation can be used as a base if an instance of the target type should be associated with the builder instance from the start and also be used as the result of the build process.
An instance of this builder type is limited to single use.
Once the terminating release() method has been used, subsequent calls to setup() throw an
IllegalStateException.
| Modifier | Constructor and Description |
|---|---|
protected |
Charger(T target,
Class<B> builderClass)
Initializes a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
T |
charged()
Returns the associated target instance.
|
T |
release()
Deprecated.
use
charged() instead. |
B |
setup(Consumer<T> consumer)
Accepts a
Consumer as modifying operation to be performed on a target instance immediately
or no later than the final build() operation and returns the builder instance itself. |
THISprotected Charger(T target, Class<B> builderClass)
target - The target instance to be associated with the builder.
The implementation assumes that it is exclusively available to the builder
for the course of the build process.builderClass - The Class representation of the intended effective builder type.IllegalArgumentException - if the specified builder class does not represent the instance to create.public final B setup(Consumer<T> consumer)
Consumer as modifying operation to be performed on a target instance immediately
or no later than the final build() operation and returns the builder instance itself.
This implementation applies the given consumer directly to the associated target.
public final T charged()
Subsequent calls of setup(Consumer) will lead to an IllegalStateException.
@Deprecated public final T release()
charged() instead.Copyright © 2023 Andreas Kluge-Kaindl, Bremen (de). All rights reserved.