[rules-users] Trying to compare int and String objects
Manuel Ortiz
manuel.ortizramos at gmail.com
Tue Apr 19 07:27:40 EDT 2011
Hello everybody:
I'm trying to write rules in which fact int attributes and fact String
attributes should be compared in condition elements. When I compare them,
let's say from int to String,
rule
when
Fact1($intAttr : attrInt1)
Fact2(attrString == $intAttr)
....
the rule seems to behave OK, whereas when I compare them from String to int,
rule
when
Fact1($stringAttr : attrString1)
Fact2(attrInt == $stringAttr)
....
I get a RuntimeDroolsException( "Conversion to long not supported from
java.lang.String").
I've taken a look at the code which throws the exception,
BaseObjectClassField.getLongValue() and found that it only accepts Number
and Date objects to be converted to long.
...
if ( value instanceof Number ) {
return ((Number) value).longValue();
} else if ( value instanceof Date ) {
return ((Date) value).getTime();
}
...
Is it possible to add String to long conversion via Long.parseLong(str) or
is there any reason not to allow this conversion?.
Thank you again for your time.
Best regards,
Manuel Ortiz.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110419/a319662a/attachment.html
More information about the rules-users
mailing list