Search code examples
javarulesdrools

Defining Collections in drl file


I'm going to do some ruling stuff with drools. This is the first time I use this tool and, for functional requirements, i've thought a need to define a weights data-structure in a drl document.

I have to use the "java-like" syntax (i don't even know if there are others types of syntaxes at this moment).

Is there any way to write down programmatically any kind of java collection in a drl file?


Solution

  • You can use MVEL or Java syntax in the Drools DRL rules.

    You can also use any Java collection. If you want to make a new collection you need to do it in the rule RHS part and if you want to use it in the rules you need to use insert for that.

    import java.util.Collection;
    import java.util.ArrayList;
    
    Rule "Example Rule"
      when
        # Your condition
      then
        Collection collection = new ArrayList();
        # add what ever you want into the collection
        insert( collection );
    end