This content has been marked as final.
Show 1 reply
-
1. Re: Use Drools for the Bundle Resolver
tirelli Nov 10, 2009 1:20 PM (in response to thomas.diesler)If you want to check that there is no other WireCandidate besides the one matched, you could use "not":
rule "Use WireCandidate" when $import : ImportPackage( exporter == null ) $wc : WireCandidate( importPackage == $import ) not( WireCandidate( this != $wc, importPackage == $import ) ) then System.out.println("Use WireCandidate " + $wc.getImportPackage() + " --> " + $wc.getExportPackage()); modify ( $wc.getImportPackage() ) { setExporter( $wc.getExportPackage() ) }; retract ( $wc ); end
Now, if you want a more general way of counting instances, use the count() function on accumulate:rule "Use WireCandidate" when $import : ImportPackage( exporter == null ) $wc : WireCandidate( importPackage == $import ) // checks if the is exactly 1 instance Number( intValue == 1 ) from accumulate( $c : WireCandidate( importPackage == $import ), count($c) ) then System.out.println("Use WireCandidate " + $wc.getImportPackage() + " --> " + $wc.getExportPackage()); modify ( $wc.getImportPackage() ) { setExporter( $wc.getExportPackage() ) }; retract ( $wc ); end