signed

QiShunwang

“诚信为本、客户至上”

判断 list 集合是否含有重复对象

2021/4/26 15:26:05   来源:
    /**
     *  true 重复
     * @param orderList
     * @return
     */
    private  boolean containsRepeatAttachment(List<DesignSoftwareUnifiedEngineeringAttachmentDTO> orderList) {
        if(org.springframework.util.CollectionUtils.isEmpty(orderList)){
            return false;
        }
        if(orderList.size() == 1){
            return false;
        }
        Set<String> keys = new HashSet<>(orderList.size());
        for (int i = 0; i < orderList.size(); i++) {
            final String key = new StringBuffer(orderList.get(i).getName()).append(orderList.get(i).getSuffix()).toString();
            if(keys.contains(key)){
                return true;
            }else{
                keys.add(key);
            }
        }
        return false;
    }