[rules-users] Lists and enums in Drools

Greg Barton greg_barton at yahoo.com
Thu May 14 11:46:01 EDT 2009


One observation: use EnumSet instead of List if you have java 1.5 or later available. You'll get about a 40% speed increase between EnumSet.contains() and ArrayList.contains(), and it'll be even more if the List is a LinkedList.  Just fyi.

--- On Thu, 5/14/09, Armaghan Mahmud <mahmud.armaghan at gmail.com> wrote:

> From: Armaghan Mahmud <mahmud.armaghan at gmail.com>
> Subject: [rules-users] Lists and enums in Drools
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Thursday, May 14, 2009, 4:56 AM
> Hi,
> 
> I need help with constructing rules for my scenario.
> 
> I started off by creating enum values in the main java file
> and comparing
> them with the rules to get different responses for
> different enum values.
> That was easy.
> 
> This time, I'm constructing a list of enum values and
> passing them into the
> rules engine as well. I would like to configure my rules in
> such a way that
> when they look for the different enum values, they should
> also look in the
> list to test if the enum value passed into the rules engine
> is a member of
> the list or not.  My old rules looked like this:
> 
> rule "Testing for Alpha"
> salience 100
> when
>     alpha : AlphaWrapperClass(type == Class.ALPHA)
> then
>     System.out.println("Found Alpha");
>     alpha.isFound(true);
> end
> 
> I tweaked the above rule to :
> 
> rule "Testing for Alpha"
> salience 100
> when
>     $test: AlphaEnumCollectionsWrapperClass(alphaList :
> alphaList)
>     alpha : AlphaWrapperClass(type == Class.ALPHA
> && $test contains type )
> then
>     System.out.println("Found Loudspeaker Equipment.
> Who wants to jam that?
> Must resist... Jamming sequence in progress... ");
>     materiel.setJam(true);
> end
> 
> But I'm seeing the following error:
> 
> org.drools.rule.InvalidRulePackage: Unable to create Field
> Extractor for
> '$test' of '[ClassObjectType
> classAlphaEnumCollectionsWrapperClass]' in rule
> "Testing for Alpha": [Rule name=Testing for
> Alpha, agendaGroup=MAIN,
> salience=100, no-loop=false]
> 
> I'd greatly appreciate your help.
> 
> Thanks,
> Armaghan
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


      



More information about the rules-users mailing list