DRL, followed by results from 5.2.0,5.3.0, 5.4.0
Cheers
Wolfgang
declare Cont
val:Integer
end
rule makeFacts
salience 999999
when
then
insert( new Cont() );
end
rule "val <= Integer.MAX_VALUE"
when
$c: Cont( val <= Integer.MAX_VALUE )
then
System.out.println( drools.getRule().getName() + " fires" );
end
rule "Integer.MIN_VALUE <= val <= Integer.MAX_VALUE"
when
$c: Cont( Integer.MIN_VALUE <= val <= Integer.MAX_VALUE )
then
System.out.println( drools.getRule().getName() + " fires" );
end
rule "1 < val < 10"
when
$c: Cont( 1 < val < 10 )
then
System.out.println( drools.getRule().getName() + " fires" );
end
rule "1 < val < 1"
when
$c: Cont( 1 < val < 1 )
then
System.out.println( drools.getRule().getName() + " fires" );
end
rule "val > 1 && val < 10"
when
$c: Cont( val > 1 && val < 10 )
then
System.out.println( drools.getRule().getName() + " fires" );
end
rule "val > 1 && < 10"
when
$c: Cont( val > 1 && < 10)
then
System.out.println( drools.getRule().getName() + " fires" );
end
rule "val > 1, val < 10"
when
$c: Cont( val > 1, val < 10)
then
System.out.println( drools.getRule().getName() + " fires" );
end
For comparison reasons, one run with val == 5:
================================
val > 1, val < 10 fires
val > 1 && < 10 fires
1 < val && val < 10 fires
1 < val < 10 fires
Integer.MIN_VALUE <= val <= Integer.MAX_VALUE fires
val <= Integer.MAX_VALUE fires
================================
Below: val == null
================================
5.4.0:
1 < val < 10 fires
Integer.MIN_VALUE <= val <= Integer.MAX_VALUE fires
val <= Integer.MAX_VALUE fires
--------------------------------
5.3.0:
1 < val < 10 fires
Integer.MIN_VALUE <= val <= Integer.MAX_VALUE fires
val <= Integer.MAX_VALUE fires
--------------------------------
5.2.0:
Unable to build constraint as '1' is invalid : [Rule name='1 < val
&&
val < 10']
==> Change constraint to val > 1 && val < 10
1 < val < 10 fires
Integer.MIN_VALUE <= val <= Integer.MAX_VALUE fires
val <= Integer.MAX_VALUE fires
--------------------------------
5.1.1 doesn't accept several of these expressions, so not run.
On 27/09/2012, Wolfgang Laun <wolfgang.laun(a)gmail.com> wrote:
On 27/09/2012, Mario Fusco <mario.fusco(a)gmail.com> wrote:
> Hi,
>
> this is definitively a bug and I will start working asap to fix it. By
> the
> way which version of Drools are you using?
I'll report this in detail ASAP, using a simple example.
>
> I think that in your case null has exactly the same semantic of NaN. It
> means that any comparison against it ( even currentLateCount <=
> Integer.MAX_VALUE ) shouldn't match.
Yeah.
>
> As a side note let me underline that in my opinion something like the
> following:
>
>
> mpgong wrote
>> currentLateCount is an Integer type because i want to be able to store
>> null. 0 means something different in my app.
Note, however, that (e.g.) unmarshalling XML where an element has a
child with type xs:int and minOccurs="0", you'll have null as the
field value. So, the "different meaning" is that the value is
absent/not provided/...
>
> is profoundly wrong and there's no reason that could drive me to model
> something in that way. That is true also and especially in plain Java:
> try
> to use a condition like
>
> if ( currentLateCount < 100 ) { ... }
>
> in your Java code when currentLateCount is null and you will see that the
> only result you will get is a shining NullPointerException.
>
> Of course, since the LHS part of Drools rules is a declarative language,
> I
> wouldn't do the same there (even if I am tempted to), but as I said only
> end
> up with a non matching pattern.
Yes, as long as it defined and documented that way.
-W
>
> Thanks for having reported that.
> Mario
>
>
>
> --
> View this message in context:
>
http://drools.46999.n3.nabble.com/how-is-Integer-converted-when-comparing...
> Sent from the Drools: User forum mailing list archive at
Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>