Enum Problem with DRL Rule

827 views
Skip to first unread message

Stu R

unread,
Aug 8, 2016, 4:58:09 PM8/8/16
to Drools Usage
Hi everyone.

Im trying to use a value in an enum class to compare to the value found in a event in my rules. But it does not print any output when i've done the following in my enum class and rule.

Here is the enum class.

package com.sample;


public enum VelocityEvent {

     VEL_1(" Vel : 0.00-6.01 km/h : "),

     VEL_2(" Vel : 18.00-20.99 km/h : "),

     VEL_3(" Vel : 20.99-23.98 km/h : "),

     VEL_4(" Vel : 23.98-1080.00 km/h : ");

     private final String vel;

     VelocityEvent(String velocity) {

       vel = velocity;

     }

     public String getVel() {

     return vel;

     }

}


And here is my rule. (Just the LHS)

rule "Overlap"

         when

         $i1 : Instance ($e1 : event == VelocityEvent.VEL_1 && $name1 : name) from entry-point "Stream"

         $i2 : Instance ($e2 : event && $name2 : name && $e2 == $e1 && $name2 != $name1

         && this overlaps $i1) from entry-point "Stream"


The part in red is where I am wanting to call the string value. If I just input the string it does work. But I am wanting these variables from the enum just for quick testing purposes and to avoid typos when copying and pasting the string every time.

Any help would be appreciated.

Thanks!

Stuart.

Mario Fusco

unread,
Aug 9, 2016, 6:08:58 AM8/9/16
to Drools Usage
Hi Stuart,

Can you please clarify which version of Drools you're using? Also can you please send a complete reproducer of your problem or at least the classes of your domain and how you're inserting their instances into the KieSession so I could check on my side what's going wrong there?

Thanks,
Mario

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/eeeea666-33b3-4e9a-aef1-6d447e7a1347%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stu R

unread,
Aug 9, 2016, 6:49:26 AM8/9/16
to drools...@googlegroups.com
Hi Mario. Thanks for getting back to me.

I am using Drools 6.4.0.

I have compressed all the classes and the rule file into a zip.

Thanks a lot.

Stuart.

--
You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/zeXmhW9vIVA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.
mscprojectclasses.zip

Stu R

unread,
Aug 9, 2016, 7:10:15 AM8/9/16
to drools...@googlegroups.com

Mario Fusco

unread,
Aug 11, 2016, 4:55:59 AM8/11/16
to Drools Usage
Hi Stuart,

I finally had time to give a look at your reproducer. The problem there is that the method getEvent() of the Instance class returns a String. The constraint 'event == VelocityEvent.VEL_1' is then comparing for equality a String with a the value of the enumeration and then always returns false, exactly in the same way as plain Java would do if you attempt to do instance.getEvent().equals(VelocityEvent.VEL_1).

Let me know if this makes sense or you think that I'm missing something.

Regards,
Mario

Stu R

unread,
Aug 12, 2016, 2:29:43 PM8/12/16
to drools...@googlegroups.com
Hi Mario.

Thanks a lot for taking the time to check out my problem.

The code I just sent you is for my masters thesis. I have a fair amount of write up to do over the weekend as I need to hand in a draft copy on Monday, so taking time away from development just now to get the writing done. I'll most likely get back to you around Tuesday to let you know.

Thanks again.

Regards,

Stuart.

Stu R

unread,
Aug 17, 2016, 10:25:58 AM8/17/16
to Drools Usage
Hi Mario.

I know what you mean. I had to call VelocityEvent.VEL_1.val to actually get the value. Thanks for realising this.

I dont mean to be a pain, I released another problem on the forum regarding another problem im having with accumulation and collecting instances on temporal operators. Would you mind having a look?

Thanks a lot.

Stuart.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/eeeea666-33b3-4e9a-aef1-6d447e7a1347%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Drools Usage" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-usage/zeXmhW9vIVA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages