Class DroolsPatternBuilder<T>
- java.lang.Object
-
- org.optaplanner.core.impl.score.stream.drools.common.DroolsPatternBuilder<T>
-
- Type Parameters:
T
- generic type of the pattern to be eventually created by this builder
public final class DroolsPatternBuilder<T> extends Object
Instances ofPatternDSL.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 forPatternDSL.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 whenbuild()
orbuild(DeclarationSource)
is called. Callers must ensure thatPatternDSL.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 Summary
Constructors Constructor Description DroolsPatternBuilder(org.drools.model.Variable<T> baseVariable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.drools.model.PatternDSL.PatternDef<T>
build()
Builds a new instance of the pattern, with all theUnaryOperator
s fromexpand(UnaryOperator)
applied.org.drools.model.PatternDSL.PatternDef<T>
build(org.drools.model.DeclarationSource declarationSource)
Builds a new instance of the pattern, with all theUnaryOperator
s fromexpand(UnaryOperator)
applied.DroolsPatternBuilder<T>
expand(UnaryOperator<org.drools.model.PatternDSL.PatternDef<T>> expander)
Mutate the existingPatternDSL.PatternDef
, adding a new operation, such as a new filter or a new variable binding.org.drools.model.Variable<T>
getBaseVariable()
-
-
-
Constructor Detail
-
DroolsPatternBuilder
public DroolsPatternBuilder(org.drools.model.Variable<T> baseVariable)
- Parameters:
baseVariable
- will be used during thePatternDSL.pattern(Variable)
call withinbuild()
orbuild(DeclarationSource)
-
-
Method Detail
-
expand
public DroolsPatternBuilder<T> expand(UnaryOperator<org.drools.model.PatternDSL.PatternDef<T>> expander)
Mutate the existingPatternDSL.PatternDef
, adding a new operation, such as a new filter or a new variable binding.- Returns:
- copy of the
DroolsPatternBuilder
with the new expanding operation included.
-
build
public org.drools.model.PatternDSL.PatternDef<T> build()
Builds a new instance of the pattern, with all theUnaryOperator
s fromexpand(UnaryOperator)
applied.- Returns:
- should no longer be mutated to guarantee that rules can not influence one another
-
build
public org.drools.model.PatternDSL.PatternDef<T> build(org.drools.model.DeclarationSource declarationSource)
Builds a new instance of the pattern, with all theUnaryOperator
s fromexpand(UnaryOperator)
applied.- Parameters:
declarationSource
- will be applied to the newly created pattern- Returns:
- should no longer be mutated to guarantee that rules can not influence one another
-
getBaseVariable
public org.drools.model.Variable<T> getBaseVariable()
-
-