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@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@lists.jboss.org
> [mailto:rules-users-bounces@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@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
>
rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users