Collections.sort(detailedProfessorships, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
DetailedProfessorship detailedProfessorship1 = (DetailedProfessorship) o1;
DetailedProfessorship detailedProfessorship2 = (DetailedProfessorship) o2;
int result =
detailedProfessorship1
.getInfoProfessorship()
.getInfoExecutionCourse()
.getExternalId()
.compareTo(detailedProfessorship2.getInfoProfessorship().getInfoExecutionCourse().getExternalId());
if (result == 0
&& (detailedProfessorship1.getResponsibleFor().booleanValue() || detailedProfessorship2
.getResponsibleFor().booleanValue())) {
if (detailedProfessorship1.getResponsibleFor().booleanValue()) {
return -1;
}
if (detailedProfessorship2.getResponsibleFor().booleanValue()) {
return 1;
}
}
return result;
}
});
List result = new ArrayList();
Iterator iter = detailedProfessorships.iterator();
List temp = new ArrayList();
while (iter.hasNext()) {
DetailedProfessorship detailedProfessorship = (DetailedProfessorship) iter.next();
if (temp.isEmpty()
|| ((DetailedProfessorship) temp.get(temp.size() - 1)).getInfoProfessorship().getInfoExecutionCourse()
.equals(detailedProfessorship.getInfoProfessorship().getInfoExecutionCourse())) {
temp.add(detailedProfessorship);
} else {
result.add(temp);
temp = new ArrayList();
temp.add(detailedProfessorship);