T
- generic type of the pattern to be eventually created by this builderpublic final class DroolsPatternBuilder<T> extends Object
PatternDSL.PatternDef
are mutable and as such can not be reused by constraint streams that could
result in mutually different rules.
However, multiple rules can be based on the same constraint streams through stream sharing.
This class makes it nearly impossible for PatternDSL.PatternDef
s to be unknowingly shared.
Instances of this class are immutable.
Mutating methods (such as expand(UnaryOperator)
) create a new instance, effectively preventing
streams from sharing patterns.
Patterns are only built when build()
or build(DeclarationSource)
is called. Callers must ensure
that PatternDSL.PatternDef
s obtained by these methods are never mutated, as that defeats the purpose.
Example:
Stream 1 joins A and B.
Stream 2 filters Stream 1.
Stream 3 also filters Stream 1, but with a different filter.
If the pattern inside Stream 1 was shared by Stream 2 and Stream 3, filters from Stream 2 would also apply to
Stream 3, and vice versa.
Therefore, Stream 2 and Stream 3 each get their own immutable copy of Stream 1's DroolsPatternBuilder
, one
which only applies their individual filters.
Constructor and Description |
---|
DroolsPatternBuilder(org.drools.model.Variable<T> baseVariable) |
Modifier and Type | Method and Description |
---|---|
org.drools.model.PatternDSL.PatternDef<T> |
build()
Builds a new instance of the pattern, with all the
UnaryOperator s from
expand(UnaryOperator) applied. |
org.drools.model.PatternDSL.PatternDef<T> |
build(org.drools.model.DeclarationSource declarationSource)
Builds a new instance of the pattern, with all the
UnaryOperator s from
expand(UnaryOperator) applied. |
DroolsPatternBuilder<T> |
expand(UnaryOperator<org.drools.model.PatternDSL.PatternDef<T>> expander)
Mutate the existing
PatternDSL.PatternDef , adding a new operation, such as a new filter or a new variable
binding. |
org.drools.model.Variable<T> |
getBaseVariable() |
public DroolsPatternBuilder(org.drools.model.Variable<T> baseVariable)
baseVariable
- will be used during the PatternDSL.pattern(Variable)
call within build()
or
build(DeclarationSource)
public DroolsPatternBuilder<T> expand(UnaryOperator<org.drools.model.PatternDSL.PatternDef<T>> expander)
PatternDSL.PatternDef
, adding a new operation, such as a new filter or a new variable
binding.DroolsPatternBuilder
with the new expanding operation included.public org.drools.model.PatternDSL.PatternDef<T> build()
UnaryOperator
s from
expand(UnaryOperator)
applied.public org.drools.model.PatternDSL.PatternDef<T> build(org.drools.model.DeclarationSource declarationSource)
UnaryOperator
s from
expand(UnaryOperator)
applied.declarationSource
- will be applied to the newly created patternpublic org.drools.model.Variable<T> getBaseVariable()
Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.