generics - 如何为两个或三个属性或属性数量制作下面的代码泛型
问题描述
"pmStudent": [
{
"id": 31506,
"name": "sushant",
"collageId": 12,
"collageName": "PVP Baramati",
"hodId": 114,
"hodName": "Yogesh"
},
{
"id": 31506,
"name": "sushant",
"collageId": 12,
"collageName": "SCSV murti",
"hodId": 114,
"hodName": "Yogesh"
},
{
"id": 41507,
"name": "mahesh",
"collageId": 12,
"collageName": "SCSV murti",
"hodId": 114,
"hodName": "Yogesh"
}
]
我有以下代码,它根据三个字段检查重复项,如何使此代码通用?所以可以用于另一个对象,如教师。重复检查可以基于对象学生三个字段,对象教师两个字段,其他对象多个字段?
protected List<Student> extractStudentDuplicates(final List<Student> studentList) {
return studentList.stream().flatMap(i -> {
final AtomicInteger count = new AtomicInteger();
final List<Student> duplicatedStu = new ArrayList<>();
studentList.forEach(p -> {
if (null != p.getId() && null != p.getCollageId() && null != p.getHodId()) {
if (p.getId().equals(i.p.getId()) && p.getCollageId().equals(i.getCollageId())
&& p.getCollageId().equals(i.getCollageId())) {
count.getAndIncrement();
}
if (count.get() == 2) {
duplicatedStu.add(i);
}
}
});
return duplicatedStu.stream();
}).distinct().collect(Collectors.toList());
}
解决方案
推荐阅读
- javascript - 单击按钮将背景视频(环境视频)转换为可播放的视频
- cmake - 如何避免对标头的不必要依赖
- validation - 有没有办法对机器人框架测试数据进行错误检查
- android - 带有 office 域 ID 的 Google Play 商店访问邀请
- javascript - 带有隐藏/显示 div 的表格移动了错误的 div
- javascript - 有什么方法可以将 Blob 数组保存到 txt 文件中,并在读取并作为视频播放后
- php - 添加到导航自定义类型帖子 WordPress
- multidimensional-array - 如何从视图中有效地克隆 Rust ndarray?
- r - 通过 GA Management API & R 更新 Google Analytics 自定义维度
- c# - .editorconfig 中的 add_imports_to_deepest_scope 设置是否与 .DotSettings 中的 AddImportsToDeepestScope 设置相同?