Interface DroolsVariableFactory
-
public interface DroolsVariableFactory
CreatesVariable
s with unique names, by adding numeric suffixes to the user-provided names. Drools executable model unfortunately doesn't enforce unique variable names, yet requires them - therefore, by unifying all access to variable creation through the factory we avoid avoiding all sorts of strange issues that are very hard to track down.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <X> org.drools.model.Variable<? extends X>
createVariable(Class<X> clz, String baseName)
Declare a newVariable
with a given name and no declared source.default <X> org.drools.model.Variable<X>
createVariable(String baseName)
Declares a newObject
-typed variable, seecreateVariable(Class, String)
for details.<In,Out>
org.drools.model.Variable<Out>createVariable(String baseName, org.drools.model.Variable<In> source, Function<In,Out> extractor)
Declare a newVariable
with a given name, the contents of which will be derived from the source variable.<X> org.drools.model.Variable<X>
createVariable(String baseName, org.drools.model.Variable<X> source)
Declare a newVariable
with a given name, the contents of which will be identical to the source variable.
-
-
-
Method Detail
-
createVariable
<X> org.drools.model.Variable<? extends X> createVariable(Class<X> clz, String baseName)
Declare a newVariable
with a given name and no declared source. Delegates toDSL.declarationOf(Class, String)
.- Type Parameters:
X
- generic type of the variable- Parameters:
clz
- type of the variable. UsingObject
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.baseName
- name of the variable, mostly useful for debugging purposes. Will be decorated by a numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.- Returns:
- new variable declaration, not yet bound to anything
-
createVariable
<X> org.drools.model.Variable<X> createVariable(String baseName, org.drools.model.Variable<X> source)
Declare a newVariable
with a given name, the contents of which will be identical to the source variable. Delegates toDSL.declarationOf(Class, String, org.drools.model.DeclarationSource)
.- Type Parameters:
X
- generic type of the variable- Parameters:
baseName
- name of the variable, mostly useful for debugging purposes. Will be decorated by a numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.source
- source of the variable- Returns:
- new variable declaration, not yet bound to anything
-
createVariable
<In,Out> org.drools.model.Variable<Out> createVariable(String baseName, org.drools.model.Variable<In> source, Function<In,Out> extractor)
Declare a newVariable
with a given name, the contents of which will be derived from the source variable. Delegates toDSL.declarationOf(Class, String, org.drools.model.DeclarationSource)
.- Type Parameters:
In
- generic type of the source variableOut
- generic type of the new variable- Parameters:
baseName
- name of the variable, mostly useful for debugging purposes. Will be decorated by a numeric identifier to prevent multiple variables of the same name to exist within left-hand side of a single rule.source
- source of the variableextractor
- function to apply on the source variable to receive the value for the new variable- Returns:
- new variable declaration, not yet bound to anything
-
createVariable
default <X> org.drools.model.Variable<X> createVariable(String baseName)
Declares a newObject
-typed variable, seecreateVariable(Class, String)
for details.
-
-