/** * 计算列表aList相对于bList的增加的数据 * @param aList 本列表 * @param bList 对照列表 * @return 返回增加的元素组成的列表 */ public List<RulePassagewayEntity> getAddaListThanbList(List<RulePassagewayEntity> aList, List<RulePassagewayEntity> bList){ List<RulePassagewayEntity> addList = new ArrayList<RulePassagewayEntity>(); for (int i = 0; i < aList.size(); i++){ if(!myListContains(bList, aList.get(i))){ addList.add(aList.get(i)); } } return addList; } /** * 计算列表aList相对于bList的减少的数据 * @param aList 本列表 * @param bList 对照列表 * @return 返回减少的元素组成的列表 */ public List<RulePassagewayEntity> getReduceaListThanbList(List<RulePassagewayEntity> aList, List<RulePassagewayEntity> bList){ List<RulePassagewayEntity> reduceaList = new ArrayList<RulePassagewayEntity>(); for (int i = 0; i < bList.size(); i++){ if(!myListContains(aList, bList.get(i))){ reduceaList.add(bList.get(i)); } } return reduceaList; } /** * 判断元素element是否是sourceList列表中的一个子元素 * @param sourceList 源列表 * @param element 待判断的包含元素 * @return 包含返回 true,不包含返回 false */ private boolean myListContains(List<RulePassagewayEntity> sourceList, RulePassagewayEntity element) { if (sourceList == null || element == null){ return false; } if (sourceList.isEmpty()){ return false; } for (RulePassagewayEntity rulePassageway : sourceList){ if(element.getPassagewayId().intValue()==rulePassageway.getPassagewayId().intValue()){ return true; } } return false; }
两个list 比较差异部分
最新推荐文章于 2024-04-10 12:58:37 发布