口水收集效率
我有 2 个相同类型的集合,集合中的每个对象都是一个 id 的键。我的目标是在两个集合中找到相同的对象,然后将字段相互比较。如果它们不是同一字段,则存储差异。
我的问题是性能,对于每条规则,我都会重新扫描集合中的同一对象。有没有一种方法,如果对象匹配,然后运行所有字段验证,而不是多次查找集合中的项目?
事实代码:
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;
}
}
流口水代码:
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
I have 2 collections of the same type and each object in the collection is key by an id. My goal is to find the same object in both collections and then compare a field against each other. If they are not the same field then store the differences.
My issue is performance, for every rule I re-scan the collection for the same object. Is there a way if the object matches then run all field validations instead of finding the item in the collection multiple times?
Fact Code:
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 Code:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以插入所有安全对象并使用组字段标记它们,而不是使用条件元素。所以你最终会得到:
$s1:安全性(组==“组1”)
$s2: Security(group == "Group2", sSecId == $security1.sSecId)
这会将每个安全视为一个事实,如果您修改一个实例,则只会重新评估该实例。
干杯
Instead of using the from Conditional Element you can just insert all the security objects and tag them with a Group field. So you will end up having:
$s1: Security(group == "Group1")
$s2: Security(group == "Group2", sSecId == $security1.sSecId)
That will treat each security as a fact and if you modify one single instance, only that instance will be reevaluated.
Cheers