Package jenkins.scm.api.trait
Class SCMBuilder<B extends SCMBuilder<B,S>,S extends SCM>
- java.lang.Object
-
- jenkins.scm.api.trait.SCMBuilder<B,S>
-
- Type Parameters:
B
- the type ofSCMBuilder
so that subclasses can chain correctly in theirwithHead(SCMHead)
etc methods.S
- the type ofSCM
returned bybuild()
public abstract class SCMBuilder<B extends SCMBuilder<B,S>,S extends SCM> extends Object
Builder for aSCM
instance. Typically instantiated inSCMSource.build(SCMHead, SCMRevision)
orSCMSource.build(SCMHead)
and then decorated bySCMSourceTrait.applyToBuilder(SCMBuilder)
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
SCMBuilder
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));
-
-
Constructor Summary
Constructors Constructor Description SCMBuilder(Class<S> clazz, SCMHead head, SCMRevision revision)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract S
build()
Instantiates theSCM
.SCMHead
head()
SCMRevision
revision()
Class<S>
scmClass()
Returns the base class ofSCM
that will be produced by theSCMBuilder
.B
withHead(SCMHead head)
B
withRevision(SCMRevision revision)
Replace therevision()
with a newSCMRevision
B
withTrait(SCMSourceTrait trait)
Apply theSCMSourceTrait
to thisSCMBuilder
.B
withTraits(Collection<SCMSourceTrait> traits)
Apply theSCMSourceTrait
instances to thisSCMBuilder
.B
withTraits(SCMSourceTrait... traits)
Apply theSCMSourceTrait
instances to thisSCMBuilder
.
-
-
-
Constructor Detail
-
SCMBuilder
public SCMBuilder(Class<S> clazz, @NonNull SCMHead head, @CheckForNull SCMRevision revision)
Constructor.- Parameters:
clazz
- The base class ofSCM
that will be produced by theSCMBuilder
.head
- TheSCMHead
to produce theSCM
for.revision
- TheSCMRevision
to produce theSCM
for ornull
to produce theSCM
for the head revision.
-
-
Method Detail
-
revision
@CheckForNull public final SCMRevision revision()
- Returns:
- the
SCMRevision
to produce theSCM
for ornull
to produce theSCM
for the head revision.
-
scmClass
@NonNull public final Class<S> scmClass()
Returns the base class ofSCM
that will be produced by theSCMBuilder
.- Returns:
- the base class of
SCM
that will be produced by theSCMBuilder
.
-
withRevision
@NonNull public final B withRevision(@CheckForNull SCMRevision revision)
Replace therevision()
with a newSCMRevision
- Parameters:
revision
- theSCMRevision
to produce theSCM
for ornull
to produce theSCM
for the head revision.- Returns:
this
for method chaining.
-
withTrait
@NonNull public final B withTrait(@NonNull SCMSourceTrait trait)
Apply theSCMSourceTrait
to thisSCMBuilder
.- Parameters:
trait
- theSCMSourceTrait
.- Returns:
this
for method chaining.
-
withTraits
@NonNull public final B withTraits(@NonNull SCMSourceTrait... traits)
Apply theSCMSourceTrait
instances to thisSCMBuilder
.- Parameters:
traits
- theSCMSourceTrait
instances.- Returns:
this
for method chaining.
-
withTraits
@NonNull public final B withTraits(@NonNull Collection<SCMSourceTrait> traits)
Apply theSCMSourceTrait
instances to thisSCMBuilder
.- Parameters:
traits
- theSCMSourceTrait
instances.- Returns:
this
for method chaining.
-
build
@NonNull public abstract S build()
Instantiates theSCM
.- Returns:
- the
SCMBuilder
instance
-
-