List of usage examples for java.util Collections reverseOrder
@SuppressWarnings("unchecked") public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
From source file:org.fenixedu.ulisboa.specifications.ui.registrationsdgesexport.RegistrationDGESStateBeanController.java
public static RegistrationDGESStateBean populateBean(StudentCandidacy studentCandidacy) { String executionYear = studentCandidacy.getExecutionYear().getQualifiedName(); Person person = studentCandidacy.getPerson(); StudentCurricularPlan studentCurricularPlan = studentCandidacy.getRegistration() .getStudentCurricularPlan(studentCandidacy.getExecutionYear()); String degreeTypeName = studentCandidacy.getDegreeCurricularPlan().getDegree().getDegreeTypeName(); String degreeCode = studentCandidacy.getDegreeCurricularPlan().getDegree().getMinistryCode(); String degreeName = studentCandidacy.getDegreeCurricularPlan().getDegree().getNameI18N().getContent(); //TODO send to a bundle and to a method in Util String degreeLevel = ""; if (degreeTypeName.contains("Licenciatura")) { degreeLevel = "Licenciado"; } else if (degreeTypeName.contains("Mestrado")) { degreeLevel = "Mestre"; } else if (degreeTypeName.contains("Doutoramento")) { degreeLevel = "Doutor"; } else {//from w w w . ja va 2 s . c o m degreeLevel = "Desconhecido"; } String degreeBranch = ""; if (studentCurricularPlan != null) { degreeBranch = getPrimaryBranchName(studentCurricularPlan); } RegistrationRegimeType regimeTypeObj = studentCandidacy.getRegistration() .getRegimeType(studentCandidacy.getExecutionYear()); String regimeType = ""; if (regimeTypeObj != null) { regimeType = regimeTypeObj.getLocalizedName(); } String documentIdNumber = person.getDocumentIdNumber(); String candidacyState = BundleUtil.getString("resources/EnumerationResources", studentCandidacy.getActiveCandidacySituationType().getQualifiedName()); String name = person.getName(); String registrationStatus = ""; if (studentCandidacy.getActiveCandidacySituationType().equals(CandidacySituationType.REGISTERED)) { registrationStatus = BundleUtil.getString(BUNDLE, "label.true"); } else { registrationStatus = BundleUtil.getString(BUNDLE, "label.false"); } Country nat = person.getCountry(); String nationality = ""; if (nat != null) { nationality = nat.getCountryNationality().getContent(); } String secondNationality = ""; String birthYear = ""; if (person.getDateOfBirthYearMonthDay() != null) { birthYear += person.getDateOfBirthYearMonthDay().toString("dd-MM-yyyy"); } Country cOfBirth = person.getCountryOfBirth(); String countryOfBirth = ""; String districtOfBirth = ""; String districtSubdivisionOfBirth = ""; String parishOfBirth = ""; if (cOfBirth != null) { countryOfBirth = cOfBirth.getLocalizedName().getContent(); if (cOfBirth.isDefaultCountry()) { districtOfBirth = person.getDistrictOfBirth(); districtSubdivisionOfBirth = person.getDistrictSubdivisionOfBirth(); parishOfBirth = person.getParishOfBirth(); } } String countryOfResidence = ""; String districtOfResidence = ""; String districtSubdivisionOfResidence = ""; String parishOfResidence = ""; String addressOfResidence = ""; String areaCodeOfResidence = ""; if (person.getDefaultPhysicalAddress() != null) { countryOfResidence = person.getDefaultPhysicalAddress().getCountryOfResidenceName(); districtOfResidence = person.getDefaultPhysicalAddress().getDistrictOfResidence(); districtSubdivisionOfResidence = person.getDefaultPhysicalAddress().getDistrictSubdivisionOfResidence(); parishOfResidence = person.getDefaultPhysicalAddress().getParishOfResidence(); addressOfResidence = person.getDefaultPhysicalAddress().getAddress(); areaCodeOfResidence = person.getDefaultPhysicalAddress().getAreaCode(); } String countryOfDislocated = ""; String districtOfDislocated = ""; String districtSubdivisionOfDislocated = ""; String parishOfDislocated = ""; String addressOfDislocated = ""; String areaCodeOfDislocated = ""; PhysicalAddress dislocatedAddress = getSchoolTimePhysicalAddress(person); if (dislocatedAddress != null) { countryOfDislocated = dislocatedAddress.getCountryOfResidenceName(); districtOfDislocated = dislocatedAddress.getDistrictOfResidence(); districtSubdivisionOfDislocated = dislocatedAddress.getDistrictSubdivisionOfResidence(); parishOfDislocated = dislocatedAddress.getParishOfResidence(); addressOfDislocated = dislocatedAddress.getAddress(); areaCodeOfDislocated = dislocatedAddress.getAreaCode(); } String gender = person.getGender().getLocalizedName(); String ingressionType = studentCandidacy.getIngressionType().getLocalizedName(); Integer placingOption = studentCandidacy.getPlacingOption(); String firstOptionDegree = ""; String firstOptionInstitution = ""; String isDislocated = ""; String dislocatedResidenceType = ""; String profession = person.getProfession(); String professionTimeType = ""; String professionalCondition = ""; String professionType = ""; String fatherName = person.getNameOfFather(); String fatherSchoolLevel = ""; String fatherProfessionalCondition = ""; String fatherProfessionType = ""; String motherName = person.getNameOfMother(); String motherSchoolLevel = ""; String motherProfessionalCondition = ""; String motherProfessionType = ""; String salarySpan = ""; String disabilityType = ""; String needsDisabilitySupport = ""; String universityDiscoveryString = ""; String universityChoiceString = ""; Comparator<PersonalIngressionData> comparator = Collections .reverseOrder(PersonalIngressionData.COMPARATOR_BY_EXECUTION_YEAR); PersonalIngressionData pid = person.getStudent().getPersonalIngressionsDataSet().stream().sorted(comparator) .findFirst().orElse(null); if (pid != null) { if (pid.getProfessionalCondition() != null) { professionalCondition = pid.getProfessionalCondition().getLocalizedName(); } if (pid.getProfessionType() != null) { professionType = pid.getProfessionType().getLocalizedName(); } if (pid.getFatherSchoolLevel() != null) { fatherSchoolLevel = pid.getFatherSchoolLevel().getLocalizedName(); } if (pid.getFatherProfessionalCondition() != null) { fatherProfessionalCondition = pid.getFatherProfessionalCondition().getLocalizedName(); } if (pid.getFatherProfessionType() != null) { fatherProfessionType = pid.getFatherProfessionType().getLocalizedName(); } if (pid.getMotherSchoolLevel() != null) { motherSchoolLevel = pid.getMotherSchoolLevel().getLocalizedName(); } if (pid.getMotherProfessionalCondition() != null) { motherProfessionalCondition = pid.getMotherProfessionalCondition().getLocalizedName(); } if (pid.getMotherProfessionType() != null) { motherProfessionType = pid.getMotherProfessionType().getLocalizedName(); } } PersonUlisboaSpecifications personUl = person.getPersonUlisboaSpecifications(); if (personUl != null) { if (personUl.getSecondNationality() != null) { secondNationality = personUl.getSecondNationality().getCountryNationality().getContent(); } if (personUl.getDislocatedResidenceType() != null) { dislocatedResidenceType = personUl.getDislocatedResidenceType().getLocalizedName(); if (personUl.getDislocatedResidenceType().isOther()) { dislocatedResidenceType = personUl.getOtherDislocatedResidenceType(); } isDislocated = BundleUtil.getString(BUNDLE, "label.true"); } else { isDislocated = BundleUtil.getString(BUNDLE, "label.false"); } if (personUl.getProfessionTimeType() != null) { professionTimeType = personUl.getProfessionTimeType().getLocalizedName(); } firstOptionDegree = personUl.getFirstOptionDegreeDesignation(); if (personUl.getFirstOptionInstitution() != null) { firstOptionInstitution = personUl.getFirstOptionInstitution().getName(); } if (personUl.getHouseholdSalarySpan() != null) { salarySpan = personUl.getHouseholdSalarySpan().getLocalizedName(); } if (personUl.getHasDisabilities()) { if (personUl.getDisabilityType().isOther()) { disabilityType = personUl.getOtherDisabilityType(); } else { disabilityType = personUl.getDisabilityType().getLocalizedName(); } needsDisabilitySupport = BundleUtil.getString("resources/FenixeduUlisboaSpecificationsResources", "label." + personUl.getNeedsDisabilitySupport().toString()); } else { disabilityType = BundleUtil.getString(BUNDLE, "label.false"); needsDisabilitySupport = BundleUtil.getString(BUNDLE, "label.false"); } for (UniversityDiscoveryMeansAnswer universityDiscovery : personUl .getUniversityDiscoveryMeansAnswersSet()) { universityDiscoveryString += universityDiscovery.getDescription().getContent() + "; "; } if (personUl.getOtherUniversityDiscoveryMeans() != null) { universityDiscoveryString += personUl.getOtherUniversityDiscoveryMeans(); } for (UniversityChoiceMotivationAnswer universityChoice : personUl .getUniversityChoiceMotivationAnswersSet()) { universityChoiceString += universityChoice.getDescription().getContent() + "; "; } if (personUl.getOtherUniversityChoiceMotivation() != null) { universityChoiceString += personUl.getOtherUniversityChoiceMotivation(); } } String precedentCountry = ""; String precedentDistrict = ""; String precedentDistrictSubdivision = ""; String precedentSchoolLevel = ""; String precedentInstitution = ""; String precedentDegreeDesignation = ""; String precedentConclusionGrade = ""; String precedentConclusionYear = ""; String precedentHighSchoolType = ""; if (studentCandidacy.getPrecedentDegreeInformation() != null) { PrecedentDegreeInformation information = studentCandidacy.getPrecedentDegreeInformation(); if (information.getCountry() != null) { precedentCountry = information.getCountry().getLocalizedName().getContent(); } District district = information.getDistrict(); if (district != null) { precedentDistrict = district.getName(); } DistrictSubdivision districtSubdivision = information.getDistrictSubdivision(); if (districtSubdivision != null) { precedentDistrictSubdivision = districtSubdivision.getName(); } SchoolLevelType schoolLevelType = information.getSchoolLevel(); if (schoolLevelType != null) { precedentSchoolLevel = schoolLevelType.getLocalizedName(); if (schoolLevelType.isOther()) { precedentSchoolLevel = information.getOtherSchoolLevel(); } } precedentInstitution = information.getInstitutionName(); precedentDegreeDesignation = information.getDegreeDesignation(); precedentConclusionGrade = information.getConclusionGrade(); precedentConclusionYear = "" + information.getConclusionYear(); if (information.getPersonalIngressionData() != null && information.getPersonalIngressionData().getHighSchoolType() != null) { AcademicalInstitutionType highSchoolType = information.getPersonalIngressionData() .getHighSchoolType(); precedentHighSchoolType = BundleUtil.getString(BUNDLE, highSchoolType.getName()); } } String institutionName = studentCandidacy.getDegreeCurricularPlan().getDegree().getUnit() .getParentUnitsPath().get(0).getName(); String cycleName = studentCandidacy.getDegreeCurricularPlan().getDegree().getDegreeType().getCycleType() .getDescription(); String institutionalEmail = studentCandidacy.getPerson().getInstitutionalEmailAddressValue(); String defaultEmail = ""; if (!studentCandidacy.getPerson().getDefaultEmailAddressValue().equals(institutionalEmail)) { defaultEmail = studentCandidacy.getPerson().getDefaultEmailAddressValue(); } String phone = studentCandidacy.getPerson().getDefaultPhoneNumber(); String telephone = studentCandidacy.getPerson().getDefaultMobilePhoneNumber(); String maritalStatus = studentCandidacy.getPerson().getMaritalStatus().getLocalizedName(); String expirationDateOfIdDoc = ""; if (studentCandidacy.getPerson().getExpirationDateOfDocumentIdYearMonthDay() != null) { expirationDateOfIdDoc = studentCandidacy.getPerson().getExpirationDateOfDocumentIdYearMonthDay() .toString("dd-MM-yyyy"); } String emissionLocationOfIdDoc = ""; if (studentCandidacy.getPerson().getEmissionLocationOfDocumentId() != null) { emissionLocationOfIdDoc = studentCandidacy.getPerson().getEmissionLocationOfDocumentId(); } String vaccinationValidity = ""; if (personUl != null && personUl.getVaccinationValidity() != null) { vaccinationValidity = personUl.getVaccinationValidity().toString("dd-MM-yyyy"); } String curricularYear = "" + studentCandidacy.getRegistration().getCurricularYear(studentCandidacy.getExecutionYear()); String grantOwnerType = ""; if (studentCandidacy.getGrantOwnerType() != null) { grantOwnerType = BundleUtil.getString(BUNDLE, studentCandidacy.getGrantOwnerType().getQualifiedName()); } String grantOwnerProvider = ""; if (studentCandidacy.getGrantOwnerProvider() != null) { grantOwnerProvider = studentCandidacy.getGrantOwnerProvider().getName(); } String precendentDegreeCycle = ""; if (precedentSchoolLevel.contains("Bacharelato") || precedentSchoolLevel.contains("Licenciatura")) { precendentDegreeCycle = CycleType.FIRST_CYCLE.getDescription(); } else if (precedentSchoolLevel.contains("Mestrado")) { precendentDegreeCycle = CycleType.SECOND_CYCLE.getDescription(); } else { precendentDegreeCycle = "----"; } return new RegistrationDGESStateBean(executionYear, studentCandidacy.getExternalId(), degreeTypeName, degreeCode, degreeName, cycleName, curricularYear, degreeLevel, degreeBranch, regimeType, institutionName, documentIdNumber, expirationDateOfIdDoc, emissionLocationOfIdDoc, candidacyState, name, maritalStatus, registrationStatus, nationality, secondNationality, birthYear, countryOfBirth, districtOfBirth, districtSubdivisionOfBirth, parishOfBirth, gender, ingressionType, placingOption, firstOptionDegree, firstOptionInstitution, isDislocated, dislocatedResidenceType, countryOfResidence, districtOfResidence, districtSubdivisionOfResidence, parishOfResidence, addressOfResidence, areaCodeOfResidence, countryOfDislocated, districtOfDislocated, districtSubdivisionOfDislocated, parishOfDislocated, addressOfDislocated, areaCodeOfDislocated, profession, professionTimeType, professionalCondition, professionType, fatherName, fatherSchoolLevel, fatherProfessionalCondition, fatherProfessionType, motherName, motherSchoolLevel, motherProfessionalCondition, motherProfessionType, salarySpan, disabilityType, needsDisabilitySupport, universityDiscoveryString, universityChoiceString, precedentCountry, precedentDistrict, precedentDistrictSubdivision, precedentSchoolLevel, precedentInstitution, precedentDegreeDesignation, precedentConclusionGrade, precedentConclusionYear, precedentHighSchoolType, precendentDegreeCycle, institutionalEmail, defaultEmail, phone, telephone, vaccinationValidity, grantOwnerType, grantOwnerProvider); }
From source file:org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.PORollupH2IRGForEach.java
private long partition(long[] combineStats, int p, int l) throws IOException { Collections.sort(al.get(p), Collections.reverseOrder(new TupleComparator())); long maxSum = 0; Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); FSDataOutputStream pOut = fs.create(new Path("/tmp/partition/p" + String.valueOf(p))); // pOut.writeBytes(String.valueOf(p) + "\n"); if (p == 0) { maxSum = (Long) al.get(p).get(0).get(l); } else {/*from w w w . j av a 2s . c o m*/ maxSum = combineStats[p - 1]; long[] subSum = new long[numReducers]; for (int j = 0; j < numReducers; j++) { subSum[j] = 0; } subSum[0] = maxSum; for (int i = 0; i < al.get(p).size(); i++) { int minIndex = 0; for (int j = 1; j < numReducers; j++) { if (subSum[j] < subSum[minIndex]) { minIndex = j; } } subSum[minIndex] += (Long) al.get(p).get(i).get(l); String wrt = ""; for (int k = 0; k < l; k++) { wrt = wrt + al.get(p).get(i).get(k) + "\t"; } wrt = wrt + String.valueOf(minIndex) + "\n"; pOut.writeBytes(wrt); } pOut.close(); for (int i = 0; i < numReducers; i++) { if (maxSum < subSum[i]) { maxSum = subSum[i]; } } } return maxSum; }
From source file:org.alfresco.repo.version.Version2ServiceImpl.java
/** * Builds a version history object from the version history reference. * <p>//from ww w .jav a 2 s .c om * The node ref is passed to enable the version history to be scoped to the * appropriate branch in the version history. * * @param versionHistoryRef the node ref for the version history * @param nodeRef the node reference * @return a constructed version history object */ @Override protected VersionHistory buildVersionHistory(NodeRef versionHistoryRef, NodeRef nodeRef) { VersionHistory versionHistory = null; // List of versions with current one last and root one first. List<Version> versions = getAllVersions(versionHistoryRef); if (versionComparatorDesc != null) { Collections.sort(versions, Collections.reverseOrder(versionComparatorDesc)); } // Build the version history object boolean isRoot = true; Version preceeding = null; for (Version version : versions) { if (isRoot == true) { versionHistory = new VersionHistoryImpl(version, versionComparatorDesc); isRoot = false; } else { ((VersionHistoryImpl) versionHistory).addVersion(version, preceeding); } preceeding = version; } return versionHistory; }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.ReportSchedulingFacade.java
@Transactional(propagation = Propagation.REQUIRED) public List<ReportJobSummary> getScheduledJobSummaries(ExecutionContext context, ReportJobModel reportJobCriteria, int startIndex, int numberOfRows, ReportJobModel.ReportJobSortType sortType, boolean isAscending) throws ReportJobRuntimeInfoException { // cannot apply runtime information sorting in persistence service if ((sortType == ReportJobModel.ReportJobSortType.SORTBY_STATUS) || (sortType == ReportJobModel.ReportJobSortType.SORTBY_LASTRUN) || (sortType == ReportJobModel.ReportJobSortType.SORTBY_NEXTRUN)) { // get all the search job without apply sorting and pagination List<ReportJobSummary> jobs = persistenceService.listJobs(context, reportJobCriteria, 0, -1, null, isAscending);/*from ww w .j a va 2 s. c o m*/ setSummaryRuntimeInformation(context, jobs); if (reportJobCriteria.isRuntimeInformationModified() && reportJobCriteria.getRuntimeInformationModel() != null) jobs = filterSummaryRuntimeInformation(jobs, reportJobCriteria.getRuntimeInformationModel()); // apply runtime sorting Comparator<ReportJobSummary> comparator = getRunTimeInfoComparator(context, sortType); if (comparator != null) { if (!isAscending) comparator = Collections.reverseOrder(comparator); Collections.sort(jobs, comparator); } else if (!isAscending) { Collections.reverse(jobs); } // apply pagination int beginningIndex = 0; if (startIndex > 0) beginningIndex = startIndex; if ((beginningIndex == 0) && (numberOfRows == -1)) return jobs; List<ReportJobSummary> newList = new ArrayList<ReportJobSummary>(); if (beginningIndex >= jobs.size()) return newList; int showRowCount = numberOfRows; if ((numberOfRows < 0) || (numberOfRows > (jobs.size() - startIndex))) showRowCount = jobs.size() - beginningIndex; for (int i = beginningIndex; i < (showRowCount + beginningIndex); i++) { newList.add(jobs.get(i)); } return newList; } else { final List<ReportJobSummary> reportJobSummaries = persistenceService.listJobs(context, reportJobCriteria, startIndex, numberOfRows, sortType, isAscending); setSummaryRuntimeInformation(context, reportJobSummaries); return reportJobSummaries; } }
From source file:net.sourceforge.fenixedu.domain.phd.PhdIndividualProgramProcess.java
public PrecedentDegreeInformation getLatestPrecedentDegreeInformation() { TreeSet<PrecedentDegreeInformation> degreeInformations = new TreeSet<PrecedentDegreeInformation>( Collections.reverseOrder(PrecedentDegreeInformation.COMPARATOR_BY_EXECUTION_YEAR)); ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); for (PrecedentDegreeInformation pdi : getPrecedentDegreeInformationsSet()) { if (!pdi.getExecutionYear().isAfter(currentExecutionYear)) { degreeInformations.add(pdi); }/*from w ww .j a va2 s . c o m*/ } degreeInformations.addAll(getPrecedentDegreeInformationsSet()); return (degreeInformations.iterator().hasNext()) ? degreeInformations.iterator().next() : null; }
From source file:org.infoglue.calendar.actions.ViewEventListAction.java
private void sortEntries(List entries) { Collections.sort(entries, Collections.reverseOrder(new OrderByDate())); //Collections.sort(entries, Collections.reverseOrder(new OrderByEventDate(this.getLanguageCode()))); }
From source file:com.ephesoft.dcma.workflows.service.impl.WorkflowServiceImpl.java
private List<HistoricProcessInstance> getHistoricData(String batchInstanceIdentifier) { List<HistoricProcessInstance> historyProcessList = null; // Edited because ordered list from database is sorted on varchar process instance ids, but we need numeric descending sorting. if (!EphesoftStringUtil.isNullOrEmpty(batchInstanceIdentifier)) { historyProcessList = historyService.createHistoricProcessInstanceQuery() .variableValueEquals(WorkflowVariables.KEY, batchInstanceIdentifier).list(); }// w w w . j av a 2s .c o m if (CollectionUtils.isNotEmpty(historyProcessList)) { Comparator<HistoricProcessInstance> reverseComparator = Collections .reverseOrder(new HistoricProcessComparator()); Collections.sort(historyProcessList, reverseComparator); } return historyProcessList; }
From source file:org.apache.hadoop.yarn.client.cli.TopCLI.java
protected void showTopScreen() { List<ApplicationInformation> appsInfo = new ArrayList<>(); List<ApplicationReport> apps; try {/*from w w w . j a v a 2 s . c om*/ apps = fetchAppReports(); } catch (Exception e) { LOG.error("Unable to get application information", e); return; } for (ApplicationReport appReport : apps) { ApplicationInformation appInfo = new ApplicationInformation(appReport); appsInfo.add(appInfo); } if (ascendingSort) { Collections.sort(appsInfo, comparator); } else { Collections.sort(appsInfo, Collections.reverseOrder(comparator)); } NodesInformation nodesInfo = getNodesInfo(); QueueMetrics queueMetrics = getQueueMetrics(); String header = getHeader(queueMetrics, nodesInfo); String appsStr = getPrintableAppInformation(appsInfo); synchronized (lock) { printHeader(header); printApps(appsStr); System.out.print(SET_CURSOR_LINE_7_COLUMN_0); System.out.print(CLEAR_LINE); } }
From source file:org.slc.sli.dashboard.manager.impl.PopulationManagerImpl.java
@Override @LogExecutionTime/*from w w w. j av a 2 s .c om*/ public GenericEntity getAttendance(String token, Object studentIdObj, Config.Data config) { // get yearsBack from param String yearsBack = config.getParams() == null ? null : (String) config.getParams().get("yearsBack"); int intYearsBack = DEFAULT_YEARS_BACK; if (yearsBack != null) { try { intYearsBack = Integer.parseInt(yearsBack); } catch (NumberFormatException e) { LOG.error("params: value of yearsBack was not integer. [" + intYearsBack + "]. Using default value [" + DEFAULT_YEARS_BACK + "]"); intYearsBack = DEFAULT_YEARS_BACK; } } GenericEntity attendance = new GenericEntity(); String studentId = (String) studentIdObj; // get Enrollment History List<GenericEntity> enrollments = getApiClient().getEnrollmentForStudent(token, studentId); // creating lookup index for enrollment, key is term (yyyy-yyyy) int currentSchoolYear = 0; Map<String, LinkedHashMap<String, Object>> enrollmentsIndex = new HashMap<String, LinkedHashMap<String, Object>>(); for (LinkedHashMap<String, Object> enrollment : enrollments) { String entryDateYear = ""; String exitWithdrawDateYear = ""; String entryDate = (String) enrollment.get(Constants.ATTR_ENROLLMENT_ENTRY_DATE); String exitWithdrawDate = (String) enrollment.get(Constants.ATTR_ENROLLMENT_EXIT_WITHDRAW_DATE); // find a year for entryDate if (entryDate != null && entryDate.length() > 3) { entryDateYear = entryDate.substring(0, 4); } // find a year for exitWithdarwDate if (exitWithdrawDate != null && exitWithdrawDate.length() > 3) { exitWithdrawDateYear = exitWithdrawDate.substring(0, 4); } else { // exitWithdrawDate is null because it is in current term. // add one year to entryDateYear. currentSchoolYear = Integer.parseInt(entryDateYear); exitWithdrawDateYear = Integer.toString(currentSchoolYear + 1); } // creating index lookup key String key = entryDateYear + "-" + exitWithdrawDateYear; enrollmentsIndex.put(key, enrollment); } // Numberformat for %Present - no fraction NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setMaximumFractionDigits(0); // get attendance for the student List<GenericEntity> attendanceList = this.getStudentAttendance(token, studentId, null, null); for (Map<String, Object> targetAttendance : attendanceList) { // get schoolYearAttendance List<Map<String, Object>> schoolYearAttendances = (List<Map<String, Object>>) targetAttendance .get(Constants.ATTR_ATTENDANCE_SCHOOLYEAR_ATTENDANCE); if (schoolYearAttendances != null) { // sort by schoolYear GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_SCHOOL_YEAR, String.class); Collections.sort(schoolYearAttendances, Collections.reverseOrder(comparator)); for (Map<String, Object> schoolYearAttendance : schoolYearAttendances) { int inAttendanceCount = 0; int absenceCount = 0; int excusedAbsenceCount = 0; int unexcusedAbsenceCount = 0; int tardyCount = 0; int earlyDepartureCount = 0; int totalCount = 0; // get schoolYear String schoolYear = (String) schoolYearAttendance.get(Constants.ATTR_SCHOOL_YEAR); // if some reasons we cannot find currentSchoolYear, then // display all histories // if intYearsBack is not set to NO_LIMIT (-1) and found // currentSchoolYear, // then exam whether current loop is within user defined // yearsBack if (intYearsBack != NO_LIMIT && currentSchoolYear != 0) { int targetYear = Integer.parseInt(schoolYear.substring(0, 4)); // if yearsBack is 1, it means current schoolYear. // break from the loop if currentSchoolYear-targetYear // is over yearsBack. if ((currentSchoolYear - targetYear) >= intYearsBack) { break; } } // get target school year enrollment LinkedHashMap<String, Object> enrollment = enrollmentsIndex.get(schoolYear); GenericEntity currentTermAttendance = new GenericEntity(); // set school term currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_TERM, schoolYear); String nameOfInstitution = ""; boolean enrollmentExistsForAttendance = false; // get school name from enrollment if (enrollment != null) { Map<String, Object> school = (Map<String, Object>) enrollment.get(Constants.ATTR_SCHOOL); if (school != null) { nameOfInstitution = (String) school.get(Constants.ATTR_NAME_OF_INST); } String enrollmentSchoolId = (String) enrollment.get(Constants.ATTR_SCHOOL_ID); String attendanceSchoolId = (String) targetAttendance.get(Constants.ATTR_SCHOOL_ID); if (enrollmentSchoolId.equals(attendanceSchoolId) == true) { // only show attendances that are for the school in the // target enrollment enrollmentExistsForAttendance = true; } } // get attendanceEvent List<LinkedHashMap<String, Object>> attendanceEvents = (List<LinkedHashMap<String, Object>>) schoolYearAttendance .get(Constants.ATTR_ATTENDANCE_ATTENDANCE_EVENT); // count each attendance event if (attendanceEvents != null && enrollmentExistsForAttendance) { for (Map<String, Object> attendanceEvent : attendanceEvents) { String event = (String) attendanceEvent.get(Constants.ATTR_ATTENDANCE_EVENT_CATEGORY); if (event != null) { totalCount++; if (event.equals(Constants.ATTR_ATTENDANCE_IN_ATTENDANCE)) { inAttendanceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_ABSENCE)) { absenceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_EXCUSED_ABSENCE)) { excusedAbsenceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_UNEXCUSED_ABSENCE)) { unexcusedAbsenceCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_TARDY)) { tardyCount++; } else if (event.equals(Constants.ATTR_ATTENDANCE_EARLY_DEPARTURE)) { earlyDepartureCount++; } } } } // set school name currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_SCHOOL, nameOfInstitution); String gradeLevel = ""; // set grade level if (enrollment != null) { gradeLevel = (String) enrollment.get(Constants.ATTR_ENROLLMENT_ENTRY_GRADE_LEVEL_CODE); } currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_GRADE_LEVEL, gradeLevel); // set %Present currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_PRESENT, numberFormat.format(totalCount == 0 ? 0 : ((inAttendanceCount + tardyCount + earlyDepartureCount) / (double) totalCount) * 100)); // set In Attendance currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_IN_ATTENDANCE, inAttendanceCount); // set Total Absences currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_TOTAL_ABSENCES, absenceCount + excusedAbsenceCount + unexcusedAbsenceCount); // set Absence currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_ABSENCE, absenceCount); // set Excused Absences currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_EXCUSED, excusedAbsenceCount); // set Unexcused Absences currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_UNEXCUSED, unexcusedAbsenceCount); // set Tardy currentTermAttendance.put(Constants.ATTENDANCE_HISTORY_TARDY, tardyCount); // set Early departure currentTermAttendance.put(Constants.ATTENDANCE_EARLY_DEPARTURE, earlyDepartureCount); // Add to attendance list attendance.appendToList("attendance", currentTermAttendance); } } } return attendance; }