Package jenkins.scm.api.trait
Class SCMSourceBuilder<B extends SCMSourceBuilder<B,S>,S extends SCMSource>
- java.lang.Object
-
- jenkins.scm.api.trait.SCMSourceBuilder<B,S>
-
- Type Parameters:
B
- the type ofSCMSourceBuilder
so that subclasses can chain correctly in theirwithTrait(SCMSourceTrait)
etc methods.S
- the type ofSCMSource
returned bybuild()
. In general this should be a type that hasSCMSourceTrait
support.
public abstract class SCMSourceBuilder<B extends SCMSourceBuilder<B,S>,S extends SCMSource> extends Object
Builder for aSCMSource
instance. Typically instantiated inSCMNavigator.visitSources(SCMSourceObserver)
and then decorated bySCMNavigatorTrait.applyToBuilder(SCMSourceBuilder)
before callingbuild()
to generate the return value. Conventions:- The builder is not designed to be shared by multiple threads.
- All methods should be either
final
orabstract
unless there is a documented reason for allowing overrides - All "setter" methods will return
SCMSourceBuilder
and be called "withXxx" - All "getter" methods will be called "xxx()". Callers should not assume that the returned value is resistant
from concurrent changes. Implementations should ensure that the returned value is immutable by the caller.
In other words, it is intentional for implementations to reduce intermediate allocations by
return Collections.unmodifiableList(theList);
rather than the concurrency safereturn Collections.unmodifiableList(new ArrayList<>(theList));
SCMTrait
instances to the builder, theSCMNavigatorTrait
instances will modify the builder itself while theSCMSourceTrait
instances will be retained to be added to theSCMSource
duringbuild()
-
-
Constructor Summary
Constructors Constructor Description SCMSourceBuilder(Class<S> clazz, String projectName)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract S
build()
Instantiates theSCMSource
.String
projectName()
Returns the project name.Class<S>
sourceClass()
Returns the base class ofSCMSource
that will be produced by theSCMSourceBuilder
.List<SCMSourceTrait>
traits()
Returns theSCMSourceTrait
instances to provide to theSCMSource
(assuming theSCMSource
isSCMSourceTrait
aware.B
withRequest(SCMNavigatorRequest request)
Apply theSCMNavigatorRequest
to thisSCMSourceBuilder
.B
withTrait(SCMNavigatorTrait trait)
Apply theSCMNavigatorTrait
to thisSCMSourceBuilder
.B
withTrait(SCMSourceTrait trait)
B
withTraits(Collection<? extends SCMTrait<?>> traits)
Apply theSCMTrait
instances to thisSCMSourceBuilder
.B
withTraits(SCMTrait<? extends SCMTrait<?>>... traits)
Apply theSCMTrait
instances to thisSCMSourceBuilder
.
-
-
-
Constructor Detail
-
SCMSourceBuilder
public SCMSourceBuilder(@NonNull Class<S> clazz, @NonNull String projectName)
Constructor.- Parameters:
clazz
- the base class ofSCMSource
that will be produced by theSCMSourceBuilder
.projectName
- the project name.
-
-
Method Detail
-
sourceClass
@NonNull public final Class<S> sourceClass()
Returns the base class ofSCMSource
that will be produced by theSCMSourceBuilder
.- Returns:
- the base class of
SCMSource
that will be produced by theSCMSourceBuilder
.
-
projectName
@NonNull public final String projectName()
Returns the project name.- Returns:
- the project name.
-
traits
@NonNull public final List<SCMSourceTrait> traits()
Returns theSCMSourceTrait
instances to provide to theSCMSource
(assuming theSCMSource
isSCMSourceTrait
aware.- Returns:
- the
SCMSourceTrait
instances to provide to theSCMSource
(assuming theSCMSource
isSCMSourceTrait
aware.
-
withTrait
@NonNull public final B withTrait(@NonNull SCMNavigatorTrait trait)
Apply theSCMNavigatorTrait
to thisSCMSourceBuilder
.- Parameters:
trait
- theSCMNavigatorTrait
.- Returns:
this
for method chaining.
-
withTrait
@NonNull public final B withTrait(@NonNull SCMSourceTrait trait)
- Parameters:
trait
- theSCMSourceTrait
.- Returns:
this
for method chaining.
-
withTraits
@NonNull public final B withTraits(@NonNull SCMTrait<? extends SCMTrait<?>>... traits)
Apply theSCMTrait
instances to thisSCMSourceBuilder
.- Parameters:
traits
- theSCMTrait
instances.- Returns:
this
for method chaining.
-
withTraits
@NonNull public B withTraits(@NonNull Collection<? extends SCMTrait<?>> traits)
Apply theSCMTrait
instances to thisSCMSourceBuilder
.- Parameters:
traits
- theSCMTrait
instances.- Returns:
this
for method chaining.
-
withRequest
public B withRequest(@NonNull SCMNavigatorRequest request)
Apply theSCMNavigatorRequest
to thisSCMSourceBuilder
.- Parameters:
request
- theSCMNavigatorRequest
instance.- Returns:
this
for method chaining.
-
build
@NonNull public abstract S build()
Instantiates theSCMSource
. The implementation is responsible to ensure that thetraits()
are provided to theSCMSource
.- Returns:
- the
SCMSourceBuilder
instance
-
-