Package com.mastfrog.util.builder
Interface Builder<ElementType,CreateType,BuilderType extends Builder<ElementType,CreateType,BuilderType>>
- All Known Implementing Classes:
AbstractBuilder,URLBuilder
public interface Builder<ElementType,CreateType,BuilderType extends Builder<ElementType,CreateType,BuilderType>>
Basic abstraction for the builder pattern. A builder can have elements
added to it, and once some number of elements have been added, can use those
elements to construct an object of some sort.
Builders are meant to be used once to create an object and then thrown
away, not reused.
This class is parameterized on (typically) its own type so that, if additional
methods are required (for example, URLBuilder lets you set some things and
add others), the exact builder subclass does not need to be exposed.
- Author:
- Tim Boudreau
-
Method Summary
Modifier and TypeMethodDescriptionadd(ElementType element) Add an elementAdd an element as a string.default CreateTypebuild()create()Create an object.
-
Method Details
-
add
Add an element May throw an exception if called aftercreate()has been called.- Parameters:
element- The element- Returns:
- this, or a new builder (callers should not assume all implementations return
this)
-
add
Add an element as a string. Optional operation, may throw UnsupportedOperationException. May throw an exception if called aftercreate()has been called.- Parameters:
element- The element as a string which will be parsed- Returns:
- this, or a new builder (callers should not assume all implementations return
this)
-
create
CreateType create()Create an object. A Builder should be thrown away after a call to this method, and implementations will typically throw an exception if this is called twice.- Returns:
- The object this builder creates, which somehow composes together the elements that were passed to it
-
build
-