PatternVar
- type of the variable of the primary pattern (see getPrimaryPatternBuilder()
)public abstract class DroolsRuleStructure<PatternVar> extends Object
Modifier | Constructor and Description |
---|---|
protected |
DroolsRuleStructure(LongSupplier variableIdSupplier) |
Modifier and Type | Method and Description |
---|---|
<X> org.drools.model.Variable<? extends X> |
createVariable(Class<X> clz,
String name)
Declare a new
Variable in this rule, with a given name and no declared source. |
<X> org.drools.model.Variable<? extends X> |
createVariable(Class<X> clz,
String name,
org.drools.model.DeclarationSource source)
Declare a new
Variable in this rule, with a given name and a declaration source. |
<X> org.drools.model.Variable<X> |
createVariable(String name)
Declares a new
Object -typed variable, see createVariable(Class, String, DeclarationSource) for
details. |
<X> org.drools.model.Variable<X> |
createVariable(String name,
org.drools.model.DeclarationSource source)
Declares a new
Object -typed variable, see createVariable(Class, String) for details. |
List<org.drools.model.RuleItemBuilder<?>> |
finish(org.drools.model.consequences.ConsequenceBuilder.AbstractValidBuilder<?> consequence) |
abstract List<org.drools.model.view.ViewItemBuilder<?>> |
getDependents()
Patterns that follow up on the primary pattern, yet are not used for filtering or joining.
|
Class[] |
getExpectedJustificationTypes()
Determines the types we expect to see as the result of this rule.
|
abstract List<org.drools.model.view.ViewItemBuilder<?>> |
getPrerequisites()
See
getPrimaryPatternBuilder() for a definition. |
abstract DroolsPatternBuilder<PatternVar> |
getPrimaryPatternBuilder()
Primary pattern is the Drools pattern to which operations such as filter and join will be applied.
|
abstract List<org.drools.model.view.ViewItemBuilder<?>> |
getShelvedRuleItems()
Patterns that are no longer of any use to the primary pattern, yet are required for the Drools rule to function.
|
LongSupplier |
getVariableIdSupplier() |
protected abstract Class[] |
getVariableTypes() |
protected List<org.drools.model.view.ViewItemBuilder<?>> |
mergeDependents(org.drools.model.view.ViewItemBuilder<?>... newDependents) |
protected List<org.drools.model.view.ViewItemBuilder<?>> |
mergeShelved(org.drools.model.view.ViewItemBuilder<?>... newClosedItems) |
<NewA> DroolsUniRuleStructure<NewA,NewA> |
recollect(org.drools.model.Variable<NewA> newA,
org.drools.model.view.ViewItem<?> accumulatePattern) |
<NewA> DroolsUniRuleStructure<NewA,NewA> |
regroup(org.drools.model.Variable<Set<NewA>> newASource,
org.drools.model.PatternDSL.PatternDef<Set<NewA>> collectPattern,
org.drools.model.view.ViewItem<?> accumulatePattern) |
<NewA,NewB> |
regroupBi(org.drools.model.Variable<Set<BiTuple<NewA,NewB>>> newSource,
org.drools.model.PatternDSL.PatternDef<Set<BiTuple<NewA,NewB>>> collectPattern,
org.drools.model.view.ViewItem<?> accumulatePattern) |
<NewA,NewB,NewC,NewD> |
regroupBiToQuad(org.drools.model.Variable<Set<QuadTuple<NewA,NewB,NewC,NewD>>> newSource,
org.drools.model.PatternDSL.PatternDef<Set<QuadTuple<NewA,NewB,NewC,NewD>>> collectPattern,
org.drools.model.view.ViewItem<?> accumulatePattern) |
<NewA,NewB,NewC> |
regroupBiToTri(org.drools.model.Variable<Set<TriTuple<NewA,NewB,NewC>>> newSource,
org.drools.model.PatternDSL.PatternDef<Set<TriTuple<NewA,NewB,NewC>>> collectPattern,
org.drools.model.view.ViewItem<?> accumulatePattern) |
protected DroolsRuleStructure(LongSupplier variableIdSupplier)
public final <X> org.drools.model.Variable<? extends X> createVariable(Class<X> clz, String name)
Variable
in this rule, with a given name and no declared source. Delegates to
DSL.declarationOf(Class, String)
.
Creating variables via this method guarantees unique variable name within the context of a rule through the use
of DroolsConstraintFactory.getVariableIdSupplier()
.X
- Generic type of the variable.clz
- type of the variable. Using Object
will work in all cases, but Drools will spend unnecessary
amount of time looking up applicable instances of that variable, as it has to traverse instances of all types in
the working memory. Therefore, it is desirable to be as specific as possible.name
- name of the variable, mostly useful for debugging purposes. Will be decorated by a pseudo-random
numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single
rule.public final <X> org.drools.model.Variable<? extends X> createVariable(Class<X> clz, String name, org.drools.model.DeclarationSource source)
Variable
in this rule, with a given name and a declaration source.
Delegates to DSL.declarationOf(Class, String, DeclarationSource)
.
Creating variables via this method guarantees unique variable names within the context of a rule through the use
of DroolsConstraintFactory.getVariableIdSupplier()
.X
- Generic type of the variable.clz
- type of the variable. Using Object
will work in all cases, but Drools will spend unnecessary
amount of time looking up applicable instances of that variable, as it has to traverse instances of all types in
the working memory. Therefore, it is desirable to be as specific as possible.name
- name of the variable, mostly useful for debugging purposes. Will be decorated by a pseudo-random
numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single
rule.source
- declaration source of the variablepublic final <X> org.drools.model.Variable<X> createVariable(String name)
Object
-typed variable, see createVariable(Class, String, DeclarationSource)
for
details.public final <X> org.drools.model.Variable<X> createVariable(String name, org.drools.model.DeclarationSource source)
Object
-typed variable, see createVariable(Class, String)
for details.public final List<org.drools.model.RuleItemBuilder<?>> finish(org.drools.model.consequences.ConsequenceBuilder.AbstractValidBuilder<?> consequence)
public LongSupplier getVariableIdSupplier()
public abstract DroolsPatternBuilder<PatternVar> getPrimaryPatternBuilder()
$person: Person() $lesson: Lesson($person in people)Here, Lesson is the primary pattern of this rule. We can use filters to restrict matched Lesson instances, and we can use $person variable in those filters. But the Person() instances themselves are now fixed and the Person pattern can be found in
getPrerequisites()
and no longer modified.
The primary pattern is provided as a builder. This is necessary since the patterns are shared and modified between different classes and it would therefore be possible for one class to modify the other's pattern. This way, the pattern is only constructed when necessary, at which point it will no longer be shared.
public abstract List<org.drools.model.view.ViewItemBuilder<?>> getShelvedRuleItems()
$tuples: Set() from accumulate(...) // This is the shelved pattern. $person: Person() from $tuples // This is the prerequisite pattern, referencing the shelved pattern. $lesson: Lesson($person in people) // This is the primary pattern, referencing the prerequisite pattern.In this example, any further Person filters or joiners will still be applied on the primary pattern. Yet the rule overall would not function properly without also including the shelved pattern.
The difference between these and getPrerequisites()
is that the latter would be folded inside a
subsequent accumulate pattern, while shelved patterns (typically representing previous accumulate patterns)
wouldn't.
Consider the following example left hand side DRL:
$tuples: Set() from accumulate(...) // This is the original shelved pattern from above. $otherTuples: Set() from accumulate( and( $person: Person() from $tuples, // This is the original prerequisite pattern from above. $lesson: Lesson($person in people) // This is the original primary pattern from above. ), collectCount() ) $otherPerson: Person() from $otherTuples // This is the new primary pattern.
public abstract List<org.drools.model.view.ViewItemBuilder<?>> getPrerequisites()
getPrimaryPatternBuilder()
for a definition.public abstract List<org.drools.model.view.ViewItemBuilder<?>> getDependents()
$person: Person() // This is the primary pattern. exists Person(this != $person) // This is the dependent, immutable pattern.In this example, any further Person filters or joiners will still be applied on the primary pattern. Yet the rule overall would not function properly without also including the dependent pattern.
protected List<org.drools.model.view.ViewItemBuilder<?>> mergeShelved(org.drools.model.view.ViewItemBuilder<?>... newClosedItems)
protected List<org.drools.model.view.ViewItemBuilder<?>> mergeDependents(org.drools.model.view.ViewItemBuilder<?>... newDependents)
public <NewA> DroolsUniRuleStructure<NewA,NewA> recollect(org.drools.model.Variable<NewA> newA, org.drools.model.view.ViewItem<?> accumulatePattern)
public <NewA> DroolsUniRuleStructure<NewA,NewA> regroup(org.drools.model.Variable<Set<NewA>> newASource, org.drools.model.PatternDSL.PatternDef<Set<NewA>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)
public <NewA,NewB> DroolsBiRuleStructure<NewA,NewB,BiTuple<NewA,NewB>> regroupBi(org.drools.model.Variable<Set<BiTuple<NewA,NewB>>> newSource, org.drools.model.PatternDSL.PatternDef<Set<BiTuple<NewA,NewB>>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)
public <NewA,NewB,NewC> DroolsTriRuleStructure<NewA,NewB,NewC,TriTuple<NewA,NewB,NewC>> regroupBiToTri(org.drools.model.Variable<Set<TriTuple<NewA,NewB,NewC>>> newSource, org.drools.model.PatternDSL.PatternDef<Set<TriTuple<NewA,NewB,NewC>>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)
public <NewA,NewB,NewC,NewD> DroolsQuadRuleStructure<NewA,NewB,NewC,NewD,QuadTuple<NewA,NewB,NewC,NewD>> regroupBiToQuad(org.drools.model.Variable<Set<QuadTuple<NewA,NewB,NewC,NewD>>> newSource, org.drools.model.PatternDSL.PatternDef<Set<QuadTuple<NewA,NewB,NewC,NewD>>> collectPattern, org.drools.model.view.ViewItem<?> accumulatePattern)
public Class[] getExpectedJustificationTypes()
Example 1:
For DroolsBiRuleStructure
before regrouping, we expect this to return an array of A and B's fact type.
Example 2:
For DroolsBiRuleStructure
after regrouping, we expect this to return an array consisting of only
BiTuple
class.
protected abstract Class[] getVariableTypes()
Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.