[rules-users] using homemade Date in Drools
Anstis, Michael (M.)
manstis1 at ford.com
Mon May 21 11:33:40 EDT 2007
Beat me to it - work always gets in the way ;-)
I was thinking of using return value operator within a predicate though:-
rule XXX
when
obj1 : A( $date1: mydate)
obj2 : A( $date2: mydate -> ($date1.isBefore($date2)) )
then
// something
obj1.doSomething();
End
Evals should not really be used unless you really do not have any other option. They cannot be optimissed in the RETE network and hence will run slower than predicates.
With kind regards,
Mike
________________________________
From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Shahad Ahmed
Sent: 21 May 2007 16:13
To: Rules Users List
Subject: Re: [rules-users] using homemade Date in Drools
How about a slight modification on Mike's solution:
rule XXX
when
obj1 : A( $date1: mydate)
obj2 : A( $date2: mydate)
eval($date1.isBefore($date2))
then
// something
obj1.doSomething();
End
I think eval allows you access to the methods in your custom Date class so you can call isBefore in there after binding $date1 and $date 2 to any custom date objects. I still new to Drools, so this may not be correct.
Regards
Shahad
On 5/21/07, Maxime Catelin <mcatelin at perinfo.com > wrote:
Thanks for your input. That seems to involve some modifications, on our
Date class and all the classes that have Date members. That's not
exactly what i thought of doing but maybe that's the only way.
What I meant was to to find a way to compare those dates eventually
using the date methods we have (isAfter() or isBefore() for exemple) and
to "keep" only the object with the latest date. So if there are several
A objects in the working memory, we will only fire the one with the
latest date.
rule XXX
when
obj : A( $date : mydate)
not A( $date.isBefore(mydate)) // does not work but that what i was thinking
then
// something
obj.doSomething();
end
Anstis, Michael (M.) a écrit :
> The simplest way could be to have your Date expose a "Time" type member
> (like java.util.Date.getTime()) that represents the number of
> seconds\milliseconds etc since a given point in time ("your absolute
> zero" for example; being day * month * year * H * M * s * ms). This
> could then be used as a simple predicate condition:-
>
> rule XXX
> when
> obj1 : A( $time : myTime)
> obj2 : A( myTime < $time )
> then
> // something
> obj.doSomething();
> End
>
> Thanks,
>
> Mike
>
> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Maxime Catelin
> Sent: 21 May 2007 14:34
> To: Rules Users List
> Subject: [rules-users] using homemade Date in Drools
>
> Hi,
>
> We are using a lot of Dates in our application but we use a homemade
> Date class for that. Therefore, we cannot use > and < provided by
> Drools. I looked through the mailing list but could not find any
> examples using Dates in Drools other than in the documentation. What
> interested me in particular in the documentation was "If more control is
>
> required, use the predicate constraint."
>
> Could someone give some examples of using predicate constraint with
> dates?
>
> Something I would like to do, for example, is the following :
>
> If there is an obj1 of class A with field of type Date d1 and another
> obj2 of class A with field Date d2, where d1 is before d2, obj2 should
> be used to fire something.
>
> rule XXX
> when
> obj : A( $date : mydate)
> // do not know how to use constraint on date here.
> then
> // something
> obj.doSomething();
> end
>
> Thanks for your input.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070521/08a2f9c0/attachment.html
More information about the rules-users
mailing list