2011-10-20 7 views
0

私は同じタイプの2つのコレクションを持っています。コレクション内の各オブジェクトはIDによってキーとなります。私の目標は、両方のコレクションで同じオブジェクトを見つけ、フィールドを互いに比較することです。同じフィールドでない場合は、差異を保存します。Drools Collection Effiency

私の問題はパフォーマンスです。すべてのルールで同じオブジェクトのコレクションを再スキャンします。コレクション内のアイテムを複数回検索するのではなく、オブジェクトが一致してすべてのフィールド検証を実行する方法はありますか?

ファクトコード:

public class ReconcilerFact 
{ 
    private List<Security> securitySystem1; 
    private List<Security> securitySystem2; 

    public ReconcilerFact(List<Security> securities1, List<Security> securities2) 
    { 
     this.securitySystem1 = securities1; 
     this.securitySystem2 = securities2; 
    } 

    public List<Security> getSecuritySystem1() 
    { 
     return securitySystem1; 
    } 

    public List<Security> getSecuritySystem2() 
    { 
     return securitySystem2; 
    } 
} 

のDroolsコード:

rule "ISIN Rule"   
    no-loop 
    when 
     ## conditions   
     ##       
     $recon : ReconcilerFact() 
     $security1 : Security() from $recon.securitySystem1 
     $security2 : Security(sSecId == $security1.sSecId, sISIN != $security1.sISIN) from $recon.securitySystem2  
    then 
     ## For the valid condition 
     ##  
     result.add($security1, SecurityFields.ISIN, $security1.getsISIN(), $security2.getsISIN());   
end 

rule "Cusip Rule"  
    no-loop 
    when 
     ## conditions   
     ##       
     $recon : ReconcilerFact() 
     $security1 : Security() from $recon.securitySystem1 
     $security2 : Security(sSecId == $security1.sSecId, sCusip != $security1.sCusip) from $recon.securitySystem2  
    then 
     ## For the valid condition 
     ##  
     result.add($security1, SecurityFields.CUSIP, $security1.getsCusip(), $security2.getsCusip());   
end 

rule "Sedol Rule"  
    no-loop 
    when 
     ## conditions   
     ##       
     $recon : ReconcilerFact() 
     $security1 : Security() from $recon.securitySystem1 
     $security2 : Security(sSecId == $security1.sSecId, sSedol != $security1.sSedol) from $recon.securitySystem2  
    then 
     ## For the valid condition 
     ##  
     result.add($security1, SecurityFields.SEDOL, $security1.getsSedol(), $security2.getsSedol());   
end 

答えて

0

代わりの条件要素から使用して、あなただけのすべてのセキュリティオブジェクトを挿入し、グループのフィールドでそれらをタグ付けすることができます。あなたが持つことになりますので: $ S1:セキュリティ(グループ== "グループ1") $ S2:セキュリティ(グループ== "グループ2"、sSecId == $ security1.sSecId)各セキュリティを扱います

事実として、単一のインスタンスを変更した場合、そのインスタンスだけが再評価されます。

乾杯