Refine search
// Sort on "phone" field of the Contact bean. Collections.sort(contacts, new BeanComparator("phone"));
/** * Constructs a property-based comparator for beans. * This constructor creates * a BeanComparator that uses the supplied Comparator to compare * the property values. * * @param property Name of a bean property, can contain the name * of a simple, nested, indexed, mapped, or combined * property. See {@link PropertyUtilsBean} for property query language * syntax. * @param comparator BeanComparator will pass the values of the * specified bean property to this Comparator. * If your bean property is not a comparable or * contains null values, a suitable comparator * may be supplied in this constructor. */ public BeanComparator( final String property, final Comparator<?> comparator ) { setProperty( property ); if (comparator != null) { this.comparator = comparator; } else { this.comparator = ComparableComparator.getInstance(); } }
/** * Compare two JavaBeans by their shared property. * If {@link #getProperty} is null then the actual objects will be compared. * * @param o1 Object The first bean to get data from to compare against * @param o2 Object The second bean to get data from to compare * @return int negative or positive based on order */ public int compare( final T o1, final T o2 ) { if ( property == null ) { // compare the actual objects return internalCompare( o1, o2 ); } try { final Object value1 = PropertyUtils.getProperty( o1, property ); final Object value2 = PropertyUtils.getProperty( o2, property ); return internalCompare( value1, value2 ); } catch ( final IllegalAccessException iae ) { throw new RuntimeException( "IllegalAccessException: " + iae.toString() ); } catch ( final InvocationTargetException ite ) { throw new RuntimeException( "InvocationTargetException: " + ite.toString() ); } catch ( final NoSuchMethodException nsme ) { throw new RuntimeException( "NoSuchMethodException: " + nsme.toString() ); } }
public ActionForward listClasses(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { InfoShift infoShift = (InfoShift) request.getAttribute(PresentationConstants.SHIFT); List classes = ReadAvailableClassesForShift.run(infoShift.getExternalId()); if (classes != null && !classes.isEmpty()) { Collections.sort(classes, new BeanComparator("nome")); request.setAttribute(PresentationConstants.CLASSES, classes); } return mapping.findForward("ListClasses"); }
public ActionForward getCurricularCourses(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User userView = getUserView(request); String degreeCurricularPlanID = null; if (request.getParameter("degreeCurricularPlanID") != null) { degreeCurricularPlanID = request.getParameter("degreeCurricularPlanID"); request.setAttribute("degreeCurricularPlanID", degreeCurricularPlanID); } List result = ReadCurricularCoursesByDegree.run(degreeCurricularPlanID); BeanComparator nameComparator = new BeanComparator("name"); Collections.sort(result, nameComparator); request.setAttribute("curricularCourses", result); return mapping.findForward("ShowCourseList"); } }
/** * @param request * @param infoExecutionCourses */ private void sortList(HttpServletRequest request, List<InfoExecutionCourse> infoExecutionCourses) { String sortParameter = request.getParameter("sortBy"); if ((sortParameter != null) && (sortParameter.length() != 0)) { if (sortParameter.equals("occupancy")) { Collections.sort(infoExecutionCourses, new ReverseComparator(new BeanComparator(sortParameter))); } else { Collections.sort(infoExecutionCourses, new BeanComparator(sortParameter)); } } else { Collections.sort(infoExecutionCourses, new ReverseComparator(new BeanComparator("occupancy"))); } }
private void readAndSetExecutionCourseClasses(HttpServletRequest request, ExecutionCourse executionCourse) throws FenixServiceException { List<InfoClass> infoClasses = ReadClassesByExecutionCourse.runReadClassesByExecutionCourse(executionCourse); if (infoClasses != null && !infoClasses.isEmpty()) { Collections.sort(infoClasses, new BeanComparator("nome")); request.setAttribute(PresentationConstants.LIST_INFOCLASS, infoClasses); } }
public class QuestionComparator extends Comparator<Question> { private BeanComparator peer = new BeanComparator("questionId"); public int compare(Question o1, Question o2) { return peer.compare(o1, o2); } }
private PagedMetadata<PageDto> getPagedResult(PageSearchRequest request, List<PageDto> pages) { BeanComparator comparator = new BeanComparator(request.getSort()); if (request.getDirection().equals(FieldSearchFilter.DESC_ORDER)) { Collections.sort(pages, comparator.reversed()); } else { Collections.sort(pages, comparator); } PageSearchDto result = new PageSearchDto(request, pages); result.imposeLimits(); return result; }
public ActionForward viewStudentsEnroled(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { InfoShift infoShift = (InfoShift) request.getAttribute(PresentationConstants.SHIFT); ShiftKey shiftKey = new ShiftKey(infoShift.getNome(), infoShift.getInfoDisciplinaExecucao()); List<InfoStudent> students = LerAlunosDeTurno.run(shiftKey); Collections.sort(students, new BeanComparator("number")); if (students != null && !students.isEmpty()) { request.setAttribute(PresentationConstants.STUDENT_LIST, students); } InfoExecutionCourse infoExecutionCourse = (InfoExecutionCourse) request.getAttribute(PresentationConstants.EXECUTION_COURSE); List<InfoShift> shifts = LerTurnosDeDisciplinaExecucao.run(infoExecutionCourse); if (shifts != null && !shifts.isEmpty()) { request.setAttribute(PresentationConstants.SHIFTS, shifts); } return mapping.findForward("ViewStudentsEnroled"); }
public ActionForward getStudentsFromDCP(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String degreeCurricularPlanID = null; if (request.getParameter("degreeCurricularPlanID") != null) { degreeCurricularPlanID = request.getParameter("degreeCurricularPlanID"); request.setAttribute("degreeCurricularPlanID", degreeCurricularPlanID); } List result = null; try { result = ReadStudentsFromDegreeCurricularPlan.runReadStudentsFromDegreeCurricularPlan(degreeCurricularPlanID); } catch (NotAuthorizedException e) { return mapping.findForward("NotAuthorized"); } catch (NonExistingServiceException e) { throw new NonExistingActionException("error.exception.noStudents", ""); } BeanComparator numberComparator = new BeanComparator("infoStudent.number"); Collections.sort(result, numberComparator); request.setAttribute(PresentationConstants.STUDENT_LIST, result); String value = request.getParameter("viewPhoto"); if (value != null && value.equals("true")) { request.setAttribute("viewPhoto", Boolean.TRUE); } else { request.setAttribute("viewPhoto", Boolean.FALSE); } return mapping.findForward("PrepareSuccess"); }
private Comparator getComparator(HttpServletRequest request) { final String orderParameter = request.getParameter(ORDER_PARAMETER); final String orderGetter = StringUtils.isEmpty(orderParameter) ? DEFAULT_ORDER_GETTER : orderParameter.substring(0, orderParameter.indexOf(ORDER_MARKER)); final String orderDir = StringUtils.isEmpty(orderParameter) ? DEFAULT_ORDER_DIR : orderParameter.substring( orderParameter.indexOf(ORDER_MARKER) + 1, orderParameter.length()); final boolean orderAsc = Arrays.asList(ASC_ORDER_DIR).contains(orderDir); if (orderGetter.equals(REQUEST_NUMBER_YEAR)) { return orderAsc ? AcademicServiceRequest.COMPARATOR_BY_NUMBER : new ReverseComparator( AcademicServiceRequest.COMPARATOR_BY_NUMBER); } else if (orderGetter.equals(EXECUTION_YEAR)) { return orderAsc ? AcademicServiceRequest.EXECUTION_YEAR_AND_OID_COMPARATOR : new ReverseComparator( AcademicServiceRequest.EXECUTION_YEAR_AND_OID_COMPARATOR); } else if (orderGetter.equals(REGISTRATION_NUMBER) || orderGetter.equals(DESCRIPTION) || orderGetter.equals(URGENT_REQUEST) || orderGetter.equals(REGISTRATION_NUMBER) || orderGetter.equals(REQUEST_DATE) || orderGetter.equals(ACTIVE_SITUATION_DATE)) { final ComparatorChain chain = new ComparatorChain(); chain.addComparator(orderAsc ? new BeanComparator(orderGetter) : new ReverseComparator( new BeanComparator(orderGetter))); chain.addComparator(DomainObjectUtil.COMPARATOR_BY_ID); return chain; } return null; }
private void setAllDepartmentsSummaryResume(HttpServletRequest request, String executionPeriodOID) throws FenixServiceException { final ExecutionSemester executionSemester = FenixFramework.getDomainObject(executionPeriodOID); List<DepartmentSummaryElement> allDepartmentsSummariesResume = new ArrayList<DepartmentSummaryElement>(); for (Department department : Bennu.getInstance().getDepartmentsSet()) { DepartmentSummaryElement departmentSummariesElement = getDepartmentSummaryResume(executionSemester, department); allDepartmentsSummariesResume.add(departmentSummariesElement); } if (executionSemester.isCurrent()) { LocalDate oneWeekBeforeDate = new LocalDate(); request.setAttribute("currentSemester", "true"); request.setAttribute("oneWeekBeforeDate", oneWeekBeforeDate.minusDays(8)); } Collections.sort(allDepartmentsSummariesResume, new BeanComparator("department.realName")); request.setAttribute("summariesResumeMap", allDepartmentsSummariesResume); }
return new BeanComparator(property).compare(sourceOjbect, objectToCompare);
public ActionForward listClasses(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { AcademicInterval academicInterval = AcademicInterval.getAcademicIntervalFromResumedString((String) request .getAttribute(PresentationConstants.ACADEMIC_INTERVAL)); InfoCurricularYear infoCurricularYear = (InfoCurricularYear) request.getAttribute(PresentationConstants.CURRICULAR_YEAR); InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) request.getAttribute(PresentationConstants.EXECUTION_DEGREE); final ExecutionDegree executionDegree = FenixFramework.getDomainObject(infoExecutionDegree.getExternalId()); final Set<SchoolClass> classes; Integer curricularYear = infoCurricularYear.getYear(); if (curricularYear != null) { classes = executionDegree.findSchoolClassesByAcademicIntervalAndCurricularYear(academicInterval, curricularYear); } else { classes = executionDegree.findSchoolClassesByAcademicInterval(academicInterval); } final List<InfoClass> infoClassesList = new ArrayList<InfoClass>(); for (final SchoolClass schoolClass : classes) { InfoClass infoClass = InfoClass.newInfoFromDomain(schoolClass); infoClassesList.add(infoClass); } if (infoClassesList != null && !infoClassesList.isEmpty()) { BeanComparator nameComparator = new BeanComparator("nome"); Collections.sort(infoClassesList, nameComparator); request.setAttribute(PresentationConstants.CLASSES, infoClassesList); } request.setAttribute("executionDegreeD", executionDegree); return mapping.findForward("ShowClassList"); }
@EntryPoint @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { User userView = getUserView(request); Student student = userView.getPerson().getStudent(); ArrayList<StudentStatute> studentStatutes = new ArrayList<StudentStatute>(student.getStudentStatutesSet()); Collections.sort(studentStatutes, new BeanComparator("beginExecutionPeriod.beginDateYearMonthDay")); request.setAttribute("studentStatutes", studentStatutes); return mapping.findForward("studentStatutes"); }
ComparatorChain chain = new ComparatorChain(Arrays.asList( new BeanComparator("size"), new BeanComparator("nrOfToppings"), new BeanComparator("name"))); Collections.sort(pizzas, chain);
for (final Object key : beanDescription.keySet()) final BeanComparator comparator = new BeanComparator(key.toString()); if (comparator.compare(sourceOjbect, objectToCompare) != 0)
/** * Constructs a property-based comparator for beans. * This constructor creates * a BeanComparator that uses the supplied Comparator to compare * the property values. * * @param property Name of a bean property, can contain the name * of a simple, nested, indexed, mapped, or combined * property. See {@link PropertyUtilsBean} for property query language * syntax. * @param comparator BeanComparator will pass the values of the * specified bean property to this Comparator. * If your bean property is not a comparable or * contains null values, a suitable comparator * may be supplied in this constructor. */ public BeanComparator( final String property, final Comparator<?> comparator ) { setProperty( property ); if (comparator != null) { this.comparator = comparator; } else { this.comparator = ComparableComparator.getInstance(); } }
/** * Compare two JavaBeans by their shared property. * If {@link #getProperty} is null then the actual objects will be compared. * * @param o1 Object The first bean to get data from to compare against * @param o2 Object The second bean to get data from to compare * @return int negative or positive based on order */ public int compare( final T o1, final T o2 ) { if ( property == null ) { // compare the actual objects return internalCompare( o1, o2 ); } try { final Object value1 = PropertyUtils.getProperty( o1, property ); final Object value2 = PropertyUtils.getProperty( o2, property ); return internalCompare( value1, value2 ); } catch ( final IllegalAccessException iae ) { throw new RuntimeException( "IllegalAccessException: " + iae.toString() ); } catch ( final InvocationTargetException ite ) { throw new RuntimeException( "InvocationTargetException: " + ite.toString() ); } catch ( final NoSuchMethodException nsme ) { throw new RuntimeException( "NoSuchMethodException: " + nsme.toString() ); } }