@Override public boolean equals(Object obj) { if (Objects.equals(obj.getClass().getName(), this.getClass().getName())) { BuyerAttribute s = (BuyerAttribute) obj; boolean same = Objects.equals(s.getBuyerNo(), this.getBuyerNo()) && Objects.equals(s.getAttribDefId(), this.getAttribDefId()); return same; } else { return super.equals(obj); } }
/** * 当same为true时获取 serverList 和 clientList中都存在的数组 * 当same为false时 获取在clientList中存在而在serverList中不存在的数组 * 使用这个方法需要重写T的equals方法,具体判断逻辑视具体的情况而定 * * @param same * @param serverList * @param clientList * @param <T> * @return */ public static <T> List<T> getSameOrDiffList(List<T> serverList, List<T> clientList, boolean same) { if (ListUtil.isBlank(serverList) || ListUtil.isBlank(clientList)) { return clientList; } List<T> result = new ArrayList<>(); for (T t : clientList) { if (same && serverList.contains(t)) { result.add(t); } else if (!same && !serverList.contains(t)) { result.add(t); } } return result; }