package TestDG;
import java.util.ArrayList;
import java.util.List;
public class collection {
/**
* 移除的原来记录中已经删除的旧ID
* @param newlist
* @param oldlist
* @return
*/
public List removeOldRecordList(List newlist,List oldlist){
oldlist.removeAll(newlist);
return oldlist;
}
/**
* 新增的原来记录中没有的ID
* @param newlist
* @param oldlist
* @return
*/
public List addNewRecordList(List newlist,List oldlist){
newlist.removeAll(oldlist);
return newlist;
}
/**
* 更新原有的记录
* @param args
*/
public List updatePublcRecordList(List newlist,List oldlist){
newlist.retainAll(oldlist);
return newlist;
}
public static void main(String[] args) {
collection c = new collection();
List newlist = new ArrayList() ;
newlist.add("a");
newlist.add("b");
newlist.add("c");
newlist.add("d");
newlist.add("e");
List oldlist = new ArrayList() ;
oldlist.add("aa");
oldlist.add("ba");
oldlist.add("c");
oldlist.add("d");
oldlist.add("e");
List oldLista = new ArrayList() ;
List newLista = new ArrayList() ;
List updateLista = new ArrayList() ;
List list = null;
int newsize = newlist.size();
int oldsize = oldlist.size();
for (int i = 0; i < oldsize; i++) {
oldLista.add(oldlist.get(i).toString());
}
for (int i = 0; i < newsize; i++) {
newLista.add(newlist.get(i).toString());
}
for (int i = 0; i < newsize; i++) {
updateLista.add(newlist.get(i).toString());
}
List updateList = null;
updateList = c.updatePublcRecordList (updateLista, oldLista);
System.err.println("updateList:"+updateList);
List oldList = null;
oldlist = c.removeOldRecordList (newlist, oldlist);
System.err.println("removeOldList"+oldlist);
List newList = null;
newlist = c.addNewRecordList (newLista, oldLista);
System.err.println("AddNewList:"+newlist);
}
}