Class DroolsVariableFactory


  • public final class DroolsVariableFactory
    extends Object
    • Method Detail

      • createVariable

        public <U,​V extends U> org.drools.model.Variable<V> createVariable​(Class<U> clz,
                                                                                 String baseName)
        Declare a new Variable with a given name and no declared source. Delegates to DSL.declarationOf(Class, String).
        Type Parameters:
        U - generic type of the input variable
        V - generic type of the output variable
        Parameters:
        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.
        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

        public <U,​V,​Result_> org.drools.model.Variable<Result_> createVariable​(String baseName,
                                                                                           org.drools.model.Variable<U> source1,
                                                                                           org.drools.model.Variable<V> source2,
                                                                                           BiFunction<U,​V,​Result_> mapping)
        Declare a new Variable with a given name, which will hold the result of applying a given mapping function on values of the provided variables.
        Type Parameters:
        U - generic type of the first input variable
        V - generic type of the second input variable
        Result_ - 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.
        source1 - never null; value of this is passed to the mapping function
        source2 - never null; value of this is passed to the mapping function
        mapping - never null
        Returns:
        never null
      • createVariable

        public <U,​V,​W,​Result_> org.drools.model.Variable<Result_> createVariable​(String baseName,
                                                                                                   org.drools.model.Variable<U> source1,
                                                                                                   org.drools.model.Variable<V> source2,
                                                                                                   org.drools.model.Variable<W> source3,
                                                                                                   TriFunction<U,​V,​W,​Result_> mapping)
      • createVariable

        public <U,​V,​W,​Y,​Result_> org.drools.model.Variable<Result_> createVariable​(String baseName,
                                                                                                           org.drools.model.Variable<U> source1,
                                                                                                           org.drools.model.Variable<V> source2,
                                                                                                           org.drools.model.Variable<W> source3,
                                                                                                           org.drools.model.Variable<Y> source4,
                                                                                                           QuadFunction<U,​V,​W,​Y,​Result_> mapping)
      • createFlattenedVariable

        public <U,​Result_> org.drools.model.Variable<Result_> createFlattenedVariable​(String baseName,
                                                                                            org.drools.model.Variable<U> source,
                                                                                            Function<U,​Iterable<Result_>> mapping)
        Declare a new Variable with a given name, which will hold the individual results of applying the given mapping function on the value of the provided variable. Each such result will trigger a single rule firing. (Default behavior of Drools' From node.)
        Type Parameters:
        U - generic type of the input variable
        Result_ - 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 - never null; value of this is passed to the mapping function
        mapping - never null
        Returns: