[rules-users] using homemade Date in Drools

Mark Proctor mproctor at codehaus.org
Mon May 21 12:24:34 EDT 2007


Why not just make your class implement Comparable, and then it will work 
with > and <.

Mark
Edson Tirelli wrote:
>
>    Yes, Shahad's suggestion shall work, but answering your first 
> question, a predicate would be like:
>
> rule XXX
> when
>    obj1 : A( $date1: mydate)
>    obj2 : A( $date2: mydate -> ( $date1.isBefore($date2) ) )
> then
>    // something
>    obj1.doSomething();
> End
>
>    Remember that predicates and evals use plain java code inside it.
>
>    []s
>    Edson
>
>
> 2007/5/21, Shahad Ahmed < shahad.ahmed2 at gmail.com 
> <mailto:shahad.ahmed2 at gmail.com>>:
>
>     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
>     <mailto: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>
>         > [mailto: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 <mailto:rules-users at lists.jboss.org>
>         > https://lists.jboss.org/mailman/listinfo/rules-users
>         <https://lists.jboss.org/mailman/listinfo/rules-users>
>         >
>         > _______________________________________________
>         > rules-users mailing list
>         > rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>         > https://lists.jboss.org/mailman/listinfo/rules-users
>         <https://lists.jboss.org/mailman/listinfo/rules-users>
>         >
>         >
>         >
>         _______________________________________________
>         rules-users mailing list
>         rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>         https://lists.jboss.org/mailman/listinfo/rules-users
>         <https://lists.jboss.org/mailman/listinfo/rules-users>
>
>
>
>     _______________________________________________
>     rules-users mailing list
>     rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> -- 
>   Edson Tirelli
>   Software Engineer - JBoss Rules Core Developer
>   Office: +55 11 3529-6000
>   Mobile: +55 11 9287-5646
>   JBoss, a division of Red Hat @ www.jboss.com <http://www.jboss.com>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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/3bbb2ef5/attachment.html 


More information about the rules-users mailing list