Interface DroolsVariableFactory


  • public interface DroolsVariableFactory
    Creates Variables 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 Detail

      • createVariable

        <U> org.drools.model.Variable<? extends U> 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 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

        <U> org.drools.model.Variable<U> createVariable​(String baseName,
                                                        org.drools.model.Variable<U> source,
                                                        boolean flatten)
        Declare a new Variable with a given name, where the value of the variable will be read from the provided source variable. If the value is Iterable, the final argument to this method controls whether the elements will be treated individually or not.
        Type Parameters:
        U - 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 - the variable the value of which will be set to the new variable
        flatten - if true, we will flatten the collection and return one element after another
        Returns:
        never null
      • createVariable

        <U,​Result_> org.drools.model.Variable<Result_> createVariable​(String baseName,
                                                                            org.drools.model.Variable<U> source,
                                                                            Function<U,​Result_> mapping,
                                                                            boolean flatten)
        Declare a new Variable with a given name, where the value of the variable will be computed from the provided source variable. If the computed value is Iterable, the final argument to this method controls whether the elements will be treated individually or not.
        Type Parameters:
        U - 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 - the variable the value of which will be set to the new variable
        mapping - the function to apply on the source variable
        flatten - if true, we will flatten the collection and return one element after another
        Returns:
        never null
      • createVariable

        <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,
                                                                                            boolean flatten)
      • createVariable

        <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,
                                                                                                    boolean flatten)