流口水:不区分大小写比较?
我需要以不区分大小写的方式比较两个字段。我有一个类似这样的规则:
foo : ObjectTypeA()
bar : ObjectTypeB( name == foo.name )
这适用于大小写相同的字符串。我需要的是这样的东西,但它似乎不起作用:
foo : ObjectTypeA()
bar : ObjectTypeB( name.equalsIgnoreCase( foo.name ) )
关于如何让它发挥作用有什么建议吗?谷歌搜索找到了使用“匹配”的建议,但匹配运算符似乎只适用于硬编码模式。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用评估。 equalsIgnoreCase 方法在您的示例代码中也有一个拼写错误。
如果你想使用类似的东西:
你可以看看 Drools 自定义运算符。例子:
http://members.inode.at/w.laun/drools/CustomOperatorHowTo。 html
Use eval. equalsIgnoreCase method also had a typo in your example code.
If you want to use something like:
You can take a look at Drools custom operators. Example:
http://members.inode.at/w.laun/drools/CustomOperatorHowTo.html
如果您想使用托尼提到的自定义运算符,您可以复制 &粘贴并调整此类以支持
equalsIgnoreCase
方法:https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/ core/base/evaluators/StrEvaluatorDefinition.java
埃德森
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
== :表示比较对象引用,而
name.equalsIgnoresCase( foo.name ) :表示比较内容。
假设
soo.name = "内存"; foo.name = "ram";
if(soo.name == foo.name) 返回 false
因为只有内容相同而不是对象。
如果我们说 foo.name = "ram";
soo.name = foo.name;
if(soo.name == foo.name) ** 返回 **true
== : 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