开发者

Drools: case insensitive compare?

I need to compare two fields in a case insensitive way. I have a rule something like this:

foo : ObjectTypeA()
bar : ObjectTypeB( name == foo.name )

And that works for strings that are the same case. What I need is something like this, but it doesn't seem to work:

foo : ObjectTypeA()开发者_运维技巧
bar : ObjectTypeB( name.equalsIgnoreCase( foo.name ) )

Any suggestions on how to get that to work? Googling hits on suggestions to use "matches", but the matches operator only seems to work against a hard coded pattern.


Use eval. equalsIgnoreCase method also had a typo in your example code.

bar : ObjectTypeB(  eval( name.equalsIgnoreCase( foo.name ) ) )

If you want to use something like:

ObjectType( name equalsIgnoreCase foo.name )

You can take a look at Drools custom operators. Example: http://members.inode.at/w.laun/drools/CustomOperatorHowTo.html


If you want to use a custom operator as Toni mentioned you can copy & paste and adjust this class to support the equalsIgnoreCase method:

https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/base/evaluators/StrEvaluatorDefinition.java

Edson


== : mean to compare the object reference while

name.equalsIgnoresCase( foo.name ) : mean to compare the contents.

let suppose
soo.name = "ram"; foo.name = "ram";
if(soo.name == foo.name) return false
because of the only content is same not the object.

if we say like foo.name = "ram";
soo.name = foo.name;
if(soo.name == foo.name) ** return **true

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜