List of usage examples for org.apache.commons.collections.comparators ComparatorChain addComparator
public void addComparator(Comparator comparator)
From source file:org.fenixedu.academic.presentationTier.Action.gep.TeachingStaffDispatchAction.java
@EntryPoint public ActionForward selectExecutionYear(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws FenixServiceException { final ExecutionYear executionYear = ExecutionYear.readCurrentExecutionYear(); String executionYearID = executionYear.getExternalId(); List degreeCurricularPlans = readActiveDegreeCurricularPlansByExecutionYear(executionYearID); final ComparatorChain comparatorChain = new ComparatorChain(); comparatorChain.addComparator(new BeanComparator("infoDegree.tipoCurso")); comparatorChain.addComparator(new BeanComparator("infoDegree.nome")); Collections.sort(degreeCurricularPlans, comparatorChain); request.setAttribute("degreeCurricularPlans", degreeCurricularPlans); request.setAttribute("executionYears", ReadNotClosedExecutionYears.run()); request.setAttribute("executionYear", executionYear); return mapping.findForward("chooseExecutionYearAndDegreeCurricularPlan"); }
From source file:org.fenixedu.academic.service.services.commons.curriculumHistoric.ReadActiveCurricularCourseScopeByDegreeCurricularPlanAndExecutionYear.java
@Atomic public static SortedSet<DegreeModuleScope> run(String degreeCurricularPlanID, AcademicInterval academicInterval) throws FenixServiceException { final DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID); final ComparatorChain comparator = new ComparatorChain(); comparator.addComparator(new BeanComparator("curricularYear")); comparator.addComparator(new BeanComparator("curricularSemester")); comparator.addComparator(new BeanComparator("curricularCourse.externalId")); comparator.addComparator(new BeanComparator("branch")); final SortedSet<DegreeModuleScope> scopes = new TreeSet<DegreeModuleScope>(comparator); for (DegreeModuleScope degreeModuleScope : degreeCurricularPlan.getDegreeModuleScopes()) { if (degreeModuleScope.isActiveForAcademicInterval(academicInterval)) { scopes.add(degreeModuleScope); }/*from w w w .j a v a 2 s. c o m*/ } return scopes; }
From source file:org.fenixedu.academic.service.services.commons.curriculumHistoric.ReadActiveCurricularCourseScopeByDegreeCurricularPlanAndExecutionYear.java
@Atomic @Deprecated/*from w w w.j av a 2s. c o m*/ public static SortedSet<DegreeModuleScope> run(String degreeCurricularPlanID, String executioYearID) throws FenixServiceException { final DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID); final ExecutionYear executionYear = FenixFramework.getDomainObject(executioYearID); final ComparatorChain comparator = new ComparatorChain(); comparator.addComparator(new BeanComparator("curricularYear")); comparator.addComparator(new BeanComparator("curricularSemester")); comparator.addComparator(new BeanComparator("curricularCourse.externalId")); comparator.addComparator(new BeanComparator("branch")); final SortedSet<DegreeModuleScope> scopes = new TreeSet<DegreeModuleScope>(comparator); for (DegreeModuleScope degreeModuleScope : degreeCurricularPlan.getDegreeModuleScopes()) { if (degreeModuleScope.isActiveForExecutionYear(executionYear)) { scopes.add(degreeModuleScope); } } return scopes; }
From source file:org.fenixedu.academic.ui.renderers.providers.EmployeesForGivenUnit.java
@Override public Object provide(Object source, Object currentValue) { VigilantGroupBean bean = (VigilantGroupBean) source; ExecutionYear currentYear = ExecutionYear.readCurrentExecutionYear(); Unit unit = bean.getSelectedUnit();/*from w ww. j av a 2 s . c o m*/ List<Employee> employees = null; if (unit != null) { employees = Employee.getAllWorkingEmployees(unit, currentYear.getBeginDateYearMonthDay(), currentYear.getEndDateYearMonthDay()); } else { Department department = bean.getSelectedDepartment(); if (department != null) { employees = Employee.getAllWorkingEmployees(department.getDepartmentUnit(), currentYear.getBeginDateYearMonthDay(), currentYear.getEndDateYearMonthDay()); } } VigilantGroup group = bean.getSelectedVigilantGroup(); if (group != null) { Collection<VigilantWrapper> vigilants = group.getVigilants(); for (VigilantWrapper vigilant : vigilants) { Employee employee = vigilant.getPerson().getEmployee(); if (employee != null) { employees.remove(employee); } } } ComparatorChain chain = new ComparatorChain(); chain.addComparator(new CategoryComparator()); chain.addComparator(new ReverseComparator(new BeanComparator("person.username"))); Collections.sort(employees, chain); return employees; }
From source file:org.fenixedu.academic.ui.struts.action.teacher.ListVigilanciesForEvaluationDispatchAction.java
private void setState(HttpServletRequest request) { String executionCourseID = request.getParameter("executionCourseID"); request.setAttribute("executionCourseID", executionCourseID); String writtenEvaluationID = request.getParameter("evaluationOID"); WrittenEvaluation evaluation = (WrittenEvaluation) FenixFramework.getDomainObject(writtenEvaluationID); ComparatorChain comparator = new ComparatorChain(); comparator.addComparator(Vigilancy.COMPARATOR_BY_VIGILANT_CATEGORY); comparator.addComparator(Vigilancy.COMPARATOR_BY_VIGILANT_USERNAME); List<Vigilancy> vigilancies = new ArrayList<Vigilancy>(Vigilancy.getOthersVigilancies(evaluation)); Collections.sort(vigilancies, comparator); List<Vigilancy> ownVigilancies = new ArrayList<Vigilancy>(Vigilancy.getTeachersVigilancies(evaluation)); Collections.sort(ownVigilancies, comparator); request.setAttribute("evaluation", evaluation); request.setAttribute("ownVigilancies", ownVigilancies); request.setAttribute("vigilancies", vigilancies); }
From source file:org.jmesa.core.sort.ComparableAwareColumnSort.java
@SuppressWarnings("unchecked") @Override// www . jav a 2s.c o m public Collection<?> sortItems(Collection<?> items, Limit limit) { if (items.isEmpty()) { return items; } ComparatorChain chain = new ComparatorChain(); SortSet sortSet = limit.getSortSet(); for (Sort sort : sortSet.getSorts()) { Class<?> type = null; try { type = getPropertyClassType(items, sort.getProperty()); } catch (Exception e) { logger.error("Had problems getting the column sort type.", e); } if (type != null && Comparable.class.isAssignableFrom(type)) { if (sort.getOrder() == Order.ASC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator(ComparableComparator.getInstance()))); } else if (sort.getOrder() == Order.DESC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator(ComparableComparator.getInstance())), true); } } else if (sort.getOrder() == Order.ASC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator())); } else if (sort.getOrder() == Order.DESC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator()), true); } } if (chain.size() > 0) { Collections.sort((List<?>) items, chain); } return items; }
From source file:org.jmesa.core.sort.ComparatorTest.java
@SuppressWarnings("unchecked") @Test/* ww w . ja v a 2 s. c om*/ public void go() { List<BeanComparator> sortFields = new ArrayList<BeanComparator>(); sortFields.add(new BeanComparator("name", new NullComparator())); sortFields.add(new BeanComparator("zipCode", new NullComparator())); ComparatorChain multiSort = new ComparatorChain(sortFields); multiSort.setReverseSort(1); ComparatorChain compChain = new ComparatorChain(); compChain.addComparator(new BeanComparator("name")); compChain.addComparator(new BeanComparator("zipCode"), true); Vector<MyClass> entries = new Vector<MyClass>(); entries.add(new MyClass("Robert", 34547)); entries.add(new MyClass("Albert", 57334)); entries.add(new MyClass("Robert", 78425)); Collections.<MyClass>sort(entries, multiSort); assertNotNull(entries); }
From source file:org.jmesa.core.sort.MultiColumnSort.java
@SuppressWarnings("unchecked") @Override//from w w w.j a v a 2 s .co m public Collection<?> sortItems(Collection<?> items, Limit limit) { ComparatorChain chain = new ComparatorChain(); SortSet sortSet = limit.getSortSet(); for (Sort sort : sortSet.getSorts()) { if (sort.getOrder() == Order.ASC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator())); } else if (sort.getOrder() == Order.DESC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator()), true); } } if (chain.size() > 0) { Collections.sort((List<?>) items, chain); } return items; }
From source file:org.lockss.exporter.biblio.BibliographicUtil.java
/** * Sort a set of {@link BibliographicItem} objects for a single title by * start date, volume and finally name. There is no guaranteed way to order * chronologically due to the frequent problem of missing or inconsistent * metadata. This sorting is provided as a second choice when volume ordering * fails to provide a consistent enough sequence of years or volumes. This * often happens if the formats occurring in the volume field are mixed - see * in particular BMJ.//from ww w . j av a2s.co m * * @param items a list of <code>BibliographicItem</code>s */ public static void sortByYearVolume(List<? extends BibliographicItem> items) { ComparatorChain cc = new ComparatorChain(); cc.addComparator(BibliographicComparatorFactory.getStartDateComparator()); cc.addComparator(BibliographicComparatorFactory.getVolumeComparator()); cc.addComparator(BibliographicComparatorFactory.getNameComparator()); Collections.sort(items, cc); }
From source file:org.lockss.exporter.biblio.BibliographicUtil.java
/** * Sort a set of {@link BibliographicItem} objects for a single title by * volume, start date and finally name. There is no guaranteed way to order * chronologically due to the frequent problem of missing or inconsistent * metadata, but in general sorting by volumes tends to give the most correct * ordering.//from w ww .ja v a 2s . co m * * @param items a list of <code>BibliographicItem</code>s */ public static void sortByVolumeYear(List<? extends BibliographicItem> items) { ComparatorChain cc = new ComparatorChain(); cc.addComparator(BibliographicComparatorFactory.getVolumeComparator()); cc.addComparator(BibliographicComparatorFactory.getStartDateComparator()); cc.addComparator(BibliographicComparatorFactory.getNameComparator()); Collections.sort(items, cc); }