The following code works, but I think it's ugly.
the classes are:
DescribedAddress is a base class for addresses
VendorAddress extends DescribedAddress and implements method abcScore()
Step getLocations() is defined as a list of DescribedAddress objects but it
can also contain VendorAddress objects since they are a kind of
DescribedAddress
the LHS of the rule below extracts the VendorAddress with the highest
abcScore from step.locations
if I omit the eval(), i get ClassCastException on any DescribedAddress in
locations, since DescribedAddress cannot be cast to VendorAddress.
is there a more elegant / clean / efficient way to get only the
VendorAddress objects from locations?
rule "Find highest scored address"
dialect "mvel"
when
$step : Step()
$location : VendorAddress (eval($location instanceof VendorAddress ),
abcScore>9) from $step.getLocations()
not $addr : VendorAddress (eval($addr instanceof VendorAddress
),abcScore > $location.abcScore) from $step.getLocations()
then
System.out.println("high score is: " + $location.getAbcScore());
end
--
View this message in context:
http://drools.46999.n3.nabble.com/Getting-one-type-from-a-collection-of-m...
Sent from the Drools: User forum mailing list archive at
Nabble.com.