有2个不同大小和对象的实体列表,例如List<BrandEntity> baseEntityList和List<BrandEntity> subEntityList,现在我想获取存储在baseEntityList中而不是subEntityList中的结果,不同的维度是brandName。我已经覆盖了 equals 方法,但它不起作用。这是我的代码。
Main.class:
findDifferenceList(baseEntityList, subEntityList)
Method:
private <T> List<T> findDifferenceList(List<T> baseBrandList, List<T> subBrandList) {
return baseBrandList.stream().filter(item -> !subBrandList.contains(item)).collect(toList());
}
BrandEntity:
@Slf4j
public class BrandEntity {
@JsonSetter("shopid")
Long shopId;
@JsonSetter("brand")
String brandName;
@JsonIgnore Long principalId;
// getter and setter
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BrandEntity that = (BrandEntity) o;
return Objects.equals(brandName, that.brandName);
}
@Override
public int hashCode() {
return Objects.hash(brandName);
}
}
四季花海
慕后森
慕田峪9158850
凤凰求蛊
相关分类