C - The core 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.T - The target type: an instance of that type will be returned by build().B - The builder type: the intended effective type of the concrete builder implementation.public class DataBuilder<C,T,B extends ProtoBuilder<C,B>> extends ProtoBuilder<C,B>
<B> and as such provides a model that separates basic
builder concepts from the actual core data model <C>.
This implementation can be used as a base if an instance of the core type <C> should be linked to the
builder instance from the start, the result of the build process shouldn't necessarily be of the core type and
a mapping exists that converts the core type <C> to the final target type <T>.
Core type <C> and target type <T> may also be the same, but avoid the final result to be identical
to the originally associated target instance (e.g. when using Function.identity() as mapping).
You should prefer Charger in this particular case!
ProtoBuilder.Lifecycle| Modifier | Constructor and Description |
|---|---|
protected |
DataBuilder(C core,
Function<C,T> mapping,
Class<B> builderClass)
Initializes a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
T |
build()
Returns the build result.
|
<R> R |
peek(Function<C,R> function)
Applies the core of this builder to the given
Function and returns the result. |
build, setupTHISprotected DataBuilder(C core, Function<C,T> mapping, Class<B> builderClass)
core - The core instance to be associated with the builder.
The implementation assumes that it is exclusively available to the builder,
at least for the course of the build process.mapping - A Function to map the associated core to the final target.
Even if the core type <C> matches the target type <T> that Function
should create a new target instance (otherwise prefer Charger).builderClass - The Class representation of the intended effective builder type.IllegalArgumentException - if the given builder class does not represent this instance.Copyright © 2024 Andreas Kluge-Kaindl, Bremen (de). All rights reserved.