/**
* 相似排行 越多相似越靠前
* 有排序属性的TreeSet为目标结果集
*
* @param trades
*/
public void sameSort(TreeMap<Integer, List> sms, List<Trade> trades, String str, String keyType) {
if (StrUtil.isEmpty(str)) return;
Map<Long, Trade> srcs = convertListToMap(trades, keyType);
Set<String> sets = Sets.newHashSet(str.split(","));
for (Long key : srcs.keySet()) {
Set<String> sets2 = new HashSet<>();
if ("functionId".equals(keyType)) {
sets2 = Sets.newHashSet(srcs.get(key).getFunctionIds().split(","));
} else if ("consumerBenefit".equals(keyType)) {
sets2 = Sets.newHashSet(srcs.get(key).getConsumerBenefitIds().split(","));
} else if ("incis".equals(keyType)) {
sets2 = Sets.newHashSet(srcs.get(key).getInciIds().split(","));
}
Sets.SetView<String> intersection = Sets.intersection(sets, sets2);
int n = intersection.size();
if (n > 0) {
List<Trade> allList;
if (sms.get(n) == null) {
allList = new ArrayList<>();
sms.put(n, allList);
} else {
allList = sms.get(n);
}
allList.add(srcs.get(key));
}
}
}
根据实体类的某些List属性求交集 越多相似越靠前
最新推荐文章于 2023-06-07 19:30:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)