我正在尝试按最高值匹配进行规则过滤。
我有一个包含多个产品的销售,我必须对每个产品应用不同的规则。
获得此结果的最佳方法是什么?
List<Rule> rules = listOfRules();
String system = "MySystem1";
Map<Product, Rule> mapOfProductRule = new HashMap<Product, Rule>();
sale.getProducts().forEach(product -> {
int points = 0;
Rule matchedRule = null;
for (Rule rule : rules) {
if (system == rule.getSystem()) {
int countMatchs = 0;
if (sale.getValue1() == rule.getValue1()) countMatchs++;
if (sale.getValue2() == rule.getValue2()) countMatchs++;
if (product.getPvalue1() == rule.getPvalue1()) countMatchs++;
if (product.getPvalue2() == rule.getPvalue2()) countMatchs++;
if (countMatchs!= 0 && points < countMatchs)
{
points = countMatchs;
matchedRule = rule;
}
}
}
mapOfProductRule.put(product, matchedRule);
});
return mapOfProductRule;
德玛西亚99
相关分类