[rules-users] Newbie question on accessing predecessor and successor in a list

Greg Barton greg_barton at yahoo.com
Tue Nov 4 10:12:51 EST 2008


Use $this. (Note the $ at the beginning)  

Yes, inline evals are allowed.  See section 6.5.2.1.2 in the docs:

http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.html

--- On Tue, 11/4/08, CSchr <christian.schrinner at sbb.ch> wrote:

> From: CSchr <christian.schrinner at sbb.ch>
> Subject: Re: [rules-users] Newbie question on accessing predecessor and successor in a list
> To: rules-users at lists.jboss.org
> Date: Tuesday, November 4, 2008, 1:45 AM
> Thanks Greg for your fast reply. Unfortunately I do not get
> this to work:
> 
> $preSegment : Segment ( 
>                        $journey.segmentList.indexOf(this)
> ==
> ($journey.segmentList.indexOf($segment) - 1), 
>                        countries not contains
> Country.Switzerland && ...
>  		     ) from $journey.segmentList
> 
> Compiler throws:
> 
> [36,48]: unknown:36:48 Unexpected token
> 'this'[36,98]: unknown:36:98
> Unexpected token '$segment'
> 
> Is it possible to use eval() inside Segment ()? 
> 
> With eval the compiler throws something like this:
> 
> $journey.segmentList cannot be resolved to a type
> Cannot use this in a static context
> 
> I don't know how matching works in drools, but
> wouldn't this also be very
> expensive? As for every match of Segment ( ) the
> segmentList has to be
> iterated two times. These lists can get very long. A cheap
> approach would be
> if the from statement would "know" the index of
> the Segment () matched. I
> was hoping this would be possible.
> 
> 
> Regards,
> 
> Chris
> 
> 
> Greg Barton wrote:
> > 
> > You can't do $journey.segmentList.indexOf(this)
> and
> > $journey.segmentList.indexOf($segment), even in an
> eval?
> > 
> > --- On Mon, 11/3/08, CSchr
> <christian.schrinner at sbb.ch> wrote:
> > 
> >> From: CSchr <christian.schrinner at sbb.ch>
> >> Subject: [rules-users] Newbie question on
> accessing predecessor and
> >> successor in a list
> >> To: rules-users at lists.jboss.org
> >> Date: Monday, November 3, 2008, 9:56 AM
> >> Hi everyone!
> >> 
> >> I'm relatively new to Drools and rule
> languages.
> >> 
> >> I'm wondering if it is possible to access the
> >> predecessor and successor in a
> >> match using from operator on an (Array)List. I
> have
> >> something like this
> >> (simplified):
> >> 
> >> ...
> >> $segment : Segment( countries contains
> Country.Switzerland
> >> && ... ) from
> >> $journey.segmentList
> >> 
> >> $preSegment : Segment ( indexOf(this) ==
> indexOf($segment)
> >> - 1, 
> >> 			           countries not contains
> Country.Switzerland
> >> && ...
> >> 		    ) from $journey.segmentList
> >> 
> >> I need something like indexOf() for the exact
> predecessor
> >> of the matched
> >> segment.
> >> 
> >> If the matched business object was an element of a
> double
> >> linked list it
> >> would be easy. Unfortunately I don't have the
> luxury to
> >> change the business
> >> object into knowing it's predecessor or
> successor. I
> >> have to prove that we
> >> could write our java coded business rules in
> Drools rule
> >> language without
> >> changing the business object model.
> >> 
> >> Thanks in advance,
> >> 
> >> Chris
> >> 
> >> 
> >> -- 
> >> View this message in context:
> >>
> http://www.nabble.com/Newbie-question-on-accessing-predecessor-and-successor-in-a-list-tp20302694p20302694.html
> >> Sent from the drools - user mailing list archive
> at
> >> Nabble.com.
> >> 
> >> _______________________________________________
> >> 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
> > 
> > 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Newbie-question-on-accessing-predecessor-and-successor-in-a-list-tp20302694p20317549.html
> Sent from the drools - user mailing list archive at
> Nabble.com.
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


      



More information about the rules-users mailing list