Collections.sort(allStudentsGroups, new BeanComparator( "groupNumber")); Integer lastGroupNumber = ((IStudentGroup) allStudentsGroups .get(allStudentsGroups.size() - 1)).getGroupNumber(); groupNumber = new Integer(lastGroupNumber.intValue() + 1);
final IStudentGroup studentGroup = (IStudentGroup) Collections.max(allStudentsGroups, new BeanComparator("groupNumber")); Integer lastGroupNumber = studentGroup.getGroupNumber(); groupNumber = Integer.valueOf(lastGroupNumber.intValue() + 1);
    public ISiteComponent run(Integer executionCourseCode,            Integer groupPropertiesCode) throws FenixServiceException {        List frequentas = new ArrayList();        List infoStudentInformationList = new ArrayList();        InfoSiteStudentGroup infoSiteStudentGroup = new InfoSiteStudentGroup();        Integer groupNumber = null;        IGroupProperties groupProperties;        try {            ISuportePersistente ps = PersistenceSupportFactory.getDefaultPersistenceSupport();                     groupProperties = (IGroupProperties) ps                    .getIPersistentGroupProperties().readByOID(                            GroupProperties.class, groupPropertiesCode);             if(groupProperties == null){            	throw new ExistingServiceException();             }                         frequentas.addAll(groupProperties.getAttendsSet().getAttends());                                    IAttendsSet attendsSet = groupProperties.getAttendsSet();                        List allStudentsGroups = attendsSet.getStudentGroups();                        groupNumber = new Integer(1);                        if(allStudentsGroups!=null){            	if (allStudentsGroups.size() != 0) {            		Collections.sort(allStudentsGroups, new BeanComparator(            		"groupNumber"));            		Integer lastGroupNumber = ((IStudentGroup) allStudentsGroups            				.get(allStudentsGroups.size() - 1)).getGroupNumber();            		groupNumber = new Integer(lastGroupNumber.intValue() + 1);            	}            	Iterator iterator = allStudentsGroups.iterator();            	List allStudentGroupAttend;                        	while (iterator.hasNext()) {                    IStudentGroup studentGroup = (IStudentGroup) iterator.next();            		allStudentGroupAttend =  studentGroup.getStudentGroupAttends();                        		Iterator iterator2 = allStudentGroupAttend.iterator();            		IAttends frequenta = null;            		while (iterator2.hasNext()) {            			frequenta = ((IStudentGroupAttend) iterator2.next())						.getAttend();            			if (frequentas.contains(frequenta)) {            				frequentas.remove(frequenta);            			}            		}            	}            }                        IStudent student = null;            Iterator iterator3 = frequentas.iterator();            while (iterator3.hasNext()) {                student = ((IAttends) iterator3.next()).getAluno();                InfoSiteStudentInformation infoSiteStudentInformation = new InfoSiteStudentInformation();                infoSiteStudentInformation.setEmail(student.getPerson()                        .getEmail());                infoSiteStudentInformation.setName(student.getPerson()                        .getNome());                infoSiteStudentInformation.setNumber(student.getNumber());                infoSiteStudentInformation.setUsername(student.getPerson()                        .getUsername());                infoStudentInformationList.add(infoSiteStudentInformation);            }                    } catch (ExcepcaoPersistencia excepcaoPersistencia) {            throw new FenixServiceException(excepcaoPersistencia.getMessage());        }        Collections.sort(infoStudentInformationList, new BeanComparator(                "number"));        infoSiteStudentGroup                .setInfoSiteStudentInformationList(infoStudentInformationList);        infoSiteStudentGroup.setNrOfElements(groupNumber);                return infoSiteStudentGroup;    }