83 lines
1.6 KiB
Java
83 lines
1.6 KiB
Java
package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
|
|
|
/**
|
|
*
|
|
* @author Francesco Mangiacrapa Feb 25, 2014
|
|
*
|
|
*/
|
|
public class DiffereceBeetweenInfoContactModel {
|
|
|
|
private List<InfoContactModel> listOne;
|
|
private List<InfoContactModel> listTwo;
|
|
|
|
/**
|
|
* Get difference between listA and listB
|
|
*
|
|
* @param listA
|
|
* List A
|
|
* @param listB
|
|
* List B
|
|
*/
|
|
public DiffereceBeetweenInfoContactModel(List<InfoContactModel> listA, List<InfoContactModel> listB) {
|
|
|
|
this.listOne = listA;
|
|
this.listTwo = listB;
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return what is in listA that is not in listB.
|
|
*/
|
|
public List<InfoContactModel> getDifferentsContacts() {
|
|
|
|
if (this.listOne == null)
|
|
return new ArrayList<InfoContactModel>();
|
|
|
|
if (this.listTwo == null || this.listTwo.size() == 0)
|
|
return this.listOne;
|
|
|
|
List<InfoContactModel> difference = new ArrayList<InfoContactModel>();
|
|
|
|
boolean found;
|
|
|
|
for (InfoContactModel o1 : listOne) {
|
|
found = false;
|
|
for (InfoContactModel o2 : listTwo) {
|
|
if (compare(o1, o2) == 0) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!found)
|
|
difference.add(o1);
|
|
}
|
|
|
|
return difference;
|
|
|
|
}
|
|
|
|
public int compare(InfoContactModel o1, InfoContactModel o2) {
|
|
|
|
if (o1 == null) {
|
|
return -1;
|
|
} else if (o2 == null) {
|
|
return 1;
|
|
}
|
|
|
|
if (o1.getName().compareTo(o2.getName()) == 0 && (o1.getLogin().compareTo(o2.getLogin()) == 0))
|
|
return 0;
|
|
else
|
|
return -2;
|
|
}
|
|
|
|
|
|
|
|
}
|