You'll have to roll your own, but it's a small one. Use accumulate steps:
$maxVa: VendorAddress() from accumulate(
$location : VendorAddress () from $step.job.scorableLocations,
init( VendorAddress maxVa = null; int maxScore = 0; ),
action( if( $location.getAbcScore() > maxScore ){
maxVa = $location;
maxScore = $location.getAbcScore(); } ),
result( maxVa ) )
The scope of a binding within accumulate(...) is this parenthesis.
-W
Thank you for the hints. I have implemented a method to hide the instanceof
code, and tried using the accumulate CE. The LHS of my rule is now:
$step : Step()
$highScore : Number() from accumulate ( $location : VendorAddress () from
$step.job.scorableLocations,
max($location.abcScore) )
in my RHS I can display the score this way:
System.out.println(" MAX SCORE IS: " + $highScore );
and verify that the accumulate is indeed choosing the max score. HOWEVER,
what I really want is not the max score, but the ADDRESS with the max score.
if I try to use $location in my RHS like this:
I get compile time exception:
System.out.println("high score is: " + $location.getAbcScore());
[Error: unable to resolve method using strict-mode:
org.drools.spi.KnowledgeHelper.$location()]
It looks like my $location variable is usable in the LHS but does not get
scope to the RHS.
--
View this message in context: http://drools.46999.n3.nabble.com/Getting-one-type-from-a-collection-of-multiple-types-tp3287877p3293744.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users