IIRC, there has been some discussion among Drools developers<br>to add this instanceof test automatically. But right now, the<br>instanceof is required - not necessarily in the posted way.<br><br>(1) Whether a Step object contains L as a subset<br>
of its List&lt;DescribedAddress&gt; or in any other way should not be<br>exposed to the clients of this class. So, add a<br>   List&lt;VendorAddress&gt; getVendorAddresses() <br>to Step and hide the dirty details where they belong.<br>
<br>(2) With or without (1), in this particular situation, an accumulate<br>would be indicated which determines the VendorAddress with<br>maximum abcScore in one pass over all objects.<br><br>-W<br><br><div class="gmail_quote">
On 26 August 2011 22:04, lhorton <span dir="ltr">&lt;<a href="mailto:LHorton@abclegal.com">LHorton@abclegal.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The following code works, but I think it&#39;s ugly.<br>
<br>
the classes are:<br>
DescribedAddress is a base class for addresses<br>
VendorAddress extends DescribedAddress and implements method abcScore()<br>
Step getLocations() is defined as a list of DescribedAddress objects but it<br>
can also contain VendorAddress objects since they are a kind of<br>
DescribedAddress<br>
<br>
the LHS of the rule below extracts the VendorAddress with the highest<br>
abcScore from step.locations<br>
<br>
if I omit the eval(), i get ClassCastException on any DescribedAddress in<br>
locations, since DescribedAddress cannot be cast to VendorAddress.<br>
<br>
is there a more elegant / clean / efficient way to get only the<br>
VendorAddress objects from locations?<br>
<br>
rule &quot;Find highest scored address&quot;<br>
dialect &quot;mvel&quot;<br>
when<br>
        $step : Step()<br>
        $location : VendorAddress (eval($location instanceof VendorAddress ),<br>
abcScore&gt;9) from $step.getLocations()<br>
<br>
        not $addr : VendorAddress (eval($addr instanceof VendorAddress<br>
),abcScore &gt; $location.abcScore) from $step.getLocations()<br>
<br>
then<br>
        System.out.println(&quot;high score is: &quot; + $location.getAbcScore());<br>
end<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Getting-one-type-from-a-collection-of-multiple-types-tp3287877p3287877.html" target="_blank">http://drools.46999.n3.nabble.com/Getting-one-type-from-a-collection-of-multiple-types-tp3287877p3287877.html</a><br>

Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>