Class LateBuilder<T,B extends LateBuilder<T,B>>

java.lang.Object
de.team33.patterns.building.elara.BuilderBase<B>
de.team33.patterns.building.elara.LateBuilder<T,B>
Type Parameters:
T - The target type: an instance of that type is finally built. That type is expected to be mutable.
B - The builder type: the intended effective type of the concrete builder implementation.
All Implemented Interfaces:
Setup<T,B>

public class LateBuilder<T,B extends LateBuilder<T,B>> extends BuilderBase<B> implements Setup<T,B>
Serves as a base class for builder implementations <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 instances of a target type are to be built that is itself mutable but does not itself implement a builder pattern. The builder initially only collects the modifying operations and only applies them to a newly created target instance with build().

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    LateBuilder(Supplier<? extends T> newResult, Class<B> builderClass)
    Initializes a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    final T
    Returns the build result.
    final B
    setup(Consumer<? super 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.

    Methods inherited from class de.team33.patterns.building.elara.BuilderBase

    THIS

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LateBuilder

      protected LateBuilder(Supplier<? extends T> newResult, Class<B> builderClass)
      Initializes a new instance.
      Parameters:
      newResult - A Supplier method to retrieve a new instance of the result type.
      builderClass - The Class representation of the intended effective builder type.
      Throws:
      IllegalArgumentException - if the given builder class does not represent this instance.
  • Method Details

    • setup

      public final B setup(Consumer<? super 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.

      This implementation stores the given consumer in order to apply it to a newly created target during build().

      Specified by:
      setup in interface Setup<T,B extends LateBuilder<T,B>>
    • build

      public final T build()
      Returns the build result.