岗位管理
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.adc.da.utils.util;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* List操作
|
||||
* @author zxy
|
||||
*/
|
||||
public class ListUtil {
|
||||
|
||||
/**
|
||||
* 获得targetList和referList中不同的元素
|
||||
* @param targetList:目标List
|
||||
* @param referList:参照List
|
||||
*/
|
||||
public static Map<String,List<String>> difList(List<String> targetList, List<String> referList){
|
||||
targetList.sort(String::compareTo);
|
||||
referList.sort(String::compareTo);
|
||||
//targetList多的节点
|
||||
List<String> insertList=new ArrayList<>();
|
||||
//referList多的节点
|
||||
List<String> deleteList=new ArrayList<>();
|
||||
//最后一个相等的节点
|
||||
int endEqual=-1;
|
||||
//referList第一个与当前targetList节点不相等的节点坐标
|
||||
int index=0;
|
||||
for(String node:targetList){
|
||||
//判断referList是否已遍历完成
|
||||
if(index<referList.size()){
|
||||
//判断是否相等
|
||||
if(node.equals(referList.get(index))){
|
||||
endEqual=index;
|
||||
index++;
|
||||
}else {
|
||||
//循环referList,寻找是否有与当前targetList节点相等的节点
|
||||
int i=index;
|
||||
for(i++;i<referList.size();i++){
|
||||
//找到相等节点,则相等之前的(endEqual之后)所有节点都是targetList所没有的节点
|
||||
if(node.equals(referList.get(i))){
|
||||
for(int j=endEqual+1;j<i;j++){
|
||||
deleteList.add(referList.get(j));
|
||||
}
|
||||
endEqual=i;
|
||||
index=i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//没找到相等节点,则该targetList节点在referList中不存在
|
||||
if(i==referList.size()){
|
||||
insertList.add(node);
|
||||
i=index;
|
||||
}
|
||||
}
|
||||
//遍历完成直接插入insertList
|
||||
}else {
|
||||
insertList.add(node);
|
||||
}
|
||||
}
|
||||
//referList中未遍历到的节点,直接插入deleteList
|
||||
if(index<referList.size()){
|
||||
for(;index<referList.size();index++){
|
||||
deleteList.add(referList.get(index));
|
||||
}
|
||||
}
|
||||
Map<String,List<String>> result=new HashMap<>();
|
||||
result.put("insert",insertList);
|
||||
result.put("delete",deleteList);
|
||||
System.out.println(insertList);
|
||||
System.out.println(deleteList);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user