Assuming you want to keep Start end Stop events (you could retract them)
and also assuming that times aren't equal (or else you don't care which one
matches) you can do:
rule match
when
$start: Start( matched == false, $startTime: time )
$stop: Stop( matched == false, $stopTime: time > $startTime )
not Stop( matched == false, time < $stopTime && > $startTime )
not Start( matched == false, time > $startTime && < $stopTime )
then
System.out.println( $start.getId() + " - " + $stop.getId() );
modify( $start ){ setMatched( true ) }
modify( $stop ){ setMatched( true ) }
end
-W
2011/6/24 Wouter De Borger <w.deborger(a)gmail.com>:
Hi all,
I'm new to drools and I have the following problem:
A stream of Start and Stop events comes into the engine.
The start and stop events should be paired and transformed into ranged
events.
Each start event should be paired to the first next stop event that is not
part of a pair already, with precedence for the last start event that came
in.
The problem is comparable to what a parser would do to match nested braces.
A sequence of the form
1: Start
2: Start
3: Start
4: End
5: Start
6: End
7: End
8: End
should form the following pairs
3-4
5-6
2-7
1-8
I checked the documentation but I still have two problems:
how can I find the next stop event (or previous start)
how can I make sure the pairs are formed innermost first?
Thanks in advance,
Wouter
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users