对比两个list集合中对象不同的属性,并取出不同的地方

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DifferenceWapper implements Serializable {
    private static final long serialVersionUID = -3369182406683473741L;
    private String column;
    private Difference difference;
    private String cloumnName;
}
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Difference  {
    private static final long serialVersionUID = 2478199484126795290L;

    private  Object oldValue; //对应的旧值
    private String oldChangeValue; //旧值转换之后的值
    private Object newValue; //对应的新值
    private String newChangeValue; //新值转变之后的值
}
public class PosInfoVo {
   // pos型号
   private String trmMod;
   // pos数量(台)
   private Integer trmQuantity;
   public PosInfoVo() {

   }

   public PosInfoVo(String trmMod, Integer trmQuantity) {
      this.trmMod = trmMod;
      this.trmQuantity = trmQuantity;
   }
   public void setTrmMod(String trmMod) {
      this.trmMod = trmMod;
   }

   /**
    * pos型号
    * 
    * @return
    */
   public String getTrmMod() {
      return trmMod;
   }

   public void setTrmQuantity(Integer trmQuantity) {
      this.trmQuantity = trmQuantity;
   }

   public Integer getTrmQuantity() {
      return trmQuantity;
   }

  
}
public List<DifferenceWapper> comparePosInfoVo(List<PosInfoVo> first,List<PosInfoVo> second, List<DifferenceWapper> list){
    HashMap<String, Integer> firstHashMap = new HashMap();
    if (null!=first &&!first.isEmpty()){
        for (PosInfoVo posInfoVo : first) {
            if (posInfoVo.getTrmMod() != null) {
                posInfoVo.setTrmQuantity(posInfoVo.getTrmQuantity() == null ? 0 : posInfoVo.getTrmQuantity());
                if (null != firstHashMap.get(posInfoVo.getTrmMod())) {
                    firstHashMap.put(posInfoVo.getTrmMod(),
                            firstHashMap.get(posInfoVo.getTrmMod()) + posInfoVo.getTrmQuantity());
                } else {
                    firstHashMap.put(posInfoVo.getTrmMod(), posInfoVo.getTrmQuantity());
                }
            }
        }
    }
    HashMap<String, Integer> secondHashMap = new HashMap();

    if (null!=second && !second.isEmpty()){
        for (PosInfoVo posInfoVo : second) {
            if (posInfoVo.getTrmMod() != null) {
                posInfoVo.setTrmQuantity(posInfoVo.getTrmQuantity() == null ? 0 : posInfoVo.getTrmQuantity());
                if (null != secondHashMap.get(posInfoVo.getTrmMod())) {
                    secondHashMap.put(posInfoVo.getTrmMod(),
                            secondHashMap.get(posInfoVo.getTrmMod()) + posInfoVo.getTrmQuantity());
                } else {
                    secondHashMap.put(posInfoVo.getTrmMod(), posInfoVo.getTrmQuantity());
                }
            }
        }
    }


    HashSet hashSet = new HashSet();
    hashSet.addAll(firstHashMap.keySet());
    hashSet.addAll(secondHashMap.keySet());
    Iterator<String> it = hashSet.iterator();
    while (it.hasNext()) {
        DifferenceWapper differenceWapper = new DifferenceWapper();
        String next = it.next();
        int secondFi = secondHashMap.get(next) == null ? 0 : secondHashMap.get(next);
        int firstFi = firstHashMap.get(next) == null ? 0 : firstHashMap.get(next);
        if (secondFi != firstFi) {
            differenceWapper.setColumn(next);
            differenceWapper.setCloumnName(next);
            Difference difference = new Difference();
            difference.setOldChangeValue(Integer.valueOf(firstFi).toString());
            difference.setOldValue(Integer.valueOf(firstFi).toString());
            difference.setNewValue(Integer.valueOf(secondFi).toString());
            difference.setNewChangeValue(Integer.valueOf(secondFi).toString());
            differenceWapper.setDifference(difference);
            list.add(differenceWapper);
        }

    }
    return list;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值