Package org.apache.commons.collections.comparators

Examples of org.apache.commons.collections.comparators.ComparatorChain


                }
            }

            // Ordering
            if (filter.getOrders() != null) {
                ComparatorChain cchain = new ComparatorChain();
                for (String key : filter.getOrders()) {
                    boolean ascending = true;
                    String orderKey = key;
                    if (key.startsWith("+") || key.startsWith("-")) {
                        orderKey = key.substring(1, key.length());
                        if (key.startsWith("-"))
                            ascending = false;
                    }

                    Comparator c;
                    if ("name".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                return o1.getProcessId().getLocalPart().compareTo(o2.getProcessId().getLocalPart());
                            }
                        };
                    else if ("namespace".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                String ns1 = o1.getProcessId().getNamespaceURI() == null ? "" : o1.getProcessId()
                                        .getNamespaceURI();
                                String ns2 = o2.getProcessId().getNamespaceURI() == null ? "" : o2.getProcessId()
                                        .getNamespaceURI();
                                return ns1.compareTo(ns2);
                            }
                        };
                    else if ("version".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                // TODO: implement version comparisons.
                                return 0;
                            }
                        };
                    else if ("deployed".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                return o1.getDeployDate().compareTo(o2.getDeployDate());
                            }

                        };

                    else {
                        // unrecognized
                        __log.debug("unrecognized order key" + orderKey);
                        continue;
                    }

                    cchain.addComparator(c, !ascending);
                }

                Collections.sort(confs, cchain);
            }
View Full Code Here


        }

        Comparator<SystemNotificationModel> notificationTypeComparator = new BeanComparator("notificationType", new SystemNotificationTypeComparator());
        Comparator<SystemNotificationModel> notificationSeverityComparator = new BeanComparator("notificationSeverity", new SystemNotificationSeverityComparator());

        ComparatorChain chain = new ComparatorChain();
        chain.addComparator(notificationTypeComparator);
        chain.addComparator(notificationSeverityComparator);

        Collections.sort(models, chain);

        return models;
    }
View Full Code Here

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public String displayPage(Model model, UserAgentInfo userAgentInfo) {
        User user = userService.getUserFromSecurityContext();
        List<Application> applications = userService.getApplicationsForUser(user, userAgentInfo.getApplicationType());

        ComparatorChain chain = new ComparatorChain();
        chain.addComparator(new ApplicationNameComparator());
        chain.addComparator(new ApplicationDescriptionComparator());

        Collections.sort(applications, chain);

        List<ApplicationModel> applicationModels = applicationService.createApplicationModels(applications, false);
        model.addAttribute("applications", applicationModels);
View Full Code Here

            for (Application application : userApplications) {
                if ((application.getName().toLowerCase().contains(criteria) || application.getDescription().toLowerCase().contains(criteria)) && !applications.contains(application)) {
                    applications.add(application);
                }
            }
            ComparatorChain chain = new ComparatorChain();
            chain.addComparator(new ApplicationNameComparator());
            chain.addComparator(new ApplicationDescriptionComparator());

            Collections.sort(applications, chain);
        }

        return applications;
View Full Code Here

                }
            }

            // Ordering
            if (filter.getOrders() != null) {
                ComparatorChain cchain = new ComparatorChain();
                for (String key : filter.getOrders()) {
                    boolean ascending = true;
                    String orderKey = key;
                    if (key.startsWith("+") || key.startsWith("-")) {
                        orderKey = key.substring(1, key.length());
                        if (key.startsWith("-"))
                            ascending = false;
                    }

                    Comparator c;
                    if ("name".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                return o1.getProcessId().getLocalPart().compareTo(o2.getProcessId().getLocalPart());
                            }
                        };
                    else if ("namespace".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                String ns1 = o1.getProcessId().getNamespaceURI() == null ? "" : o1.getProcessId()
                                        .getNamespaceURI();
                                String ns2 = o2.getProcessId().getNamespaceURI() == null ? "" : o2.getProcessId()
                                        .getNamespaceURI();
                                return ns1.compareTo(ns2);
                            }
                        };
                    else if ("version".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                // TODO: implement version comparisons.
                                return 0;
                            }
                        };
                    else if ("deployed".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                return o1.getDeployDate().compareTo(o2.getDeployDate());
                            }

                        };

                    else {
                        // unrecognized
                        __log.debug("unrecognized order key" + orderKey);
                        continue;
                    }

                    cchain.addComparator(c, !ascending);
                }

                Collections.sort(confs, cchain);
            }
           
View Full Code Here

                }
            }

            // Ordering
            if (filter.getOrders() != null) {
                ComparatorChain cchain = new ComparatorChain();
                for (String key : filter.getOrders()) {
                    boolean ascending = true;
                    String orderKey = key;
                    if (key.startsWith("+") || key.startsWith("-")) {
                        orderKey = key.substring(1, key.length());
                        if (key.startsWith("-"))
                            ascending = false;
                    }

                    Comparator c;
                    if ("name".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                return o1.getProcessId().getLocalPart().compareTo(o2.getProcessId().getLocalPart());
                            }
                        };
                    else if ("namespace".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                String ns1 = o1.getProcessId().getNamespaceURI() == null ? "" : o1.getProcessId()
                                        .getNamespaceURI();
                                String ns2 = o2.getProcessId().getNamespaceURI() == null ? "" : o2.getProcessId()
                                        .getNamespaceURI();
                                return ns1.compareTo(ns2);
                            }
                        };
                    else if ("version".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                // TODO: implement version comparisons.
                                return 0;
                            }
                        };
                    else if ("deployed".equals(orderKey))
                        c = new Comparator<ProcessConf>() {
                            public int compare(ProcessConf o1, ProcessConf o2) {
                                return o1.getDeployDate().compareTo(o2.getDeployDate());
                            }

                        };

                    else {
                        // unrecognized
                        __log.debug("unrecognized order key" + orderKey);
                        continue;
                    }

                    cchain.addComparator(c, !ascending);
                }

                Collections.sort(confs, cchain);
            }
View Full Code Here

                }
            }
            if (comps == null)
                comp = null;
            else
                comp = new ComparatorChain(comps);
        }

        if (comp == null)
            return val;
View Full Code Here

     * @param iterators  the comparators to use, not null or empty or contain nulls
     * @return a combination comparator over the comparators
     * @throws NullPointerException if comparators array is null or contains a null
     */
    public static Comparator chainedComparator(Comparator[] comparators) {
        ComparatorChain chain = new ComparatorChain();
        for (int i = 0; i < comparators.length; i++) {
            if (comparators[i] == null) {
                throw new NullPointerException("Comparator cannot be null");
            }
            chain.addComparator(comparators[i]);
        }
        return chain;
    }
View Full Code Here

   
    public static final ExternalAggregatedGroupMappingComparator INSTANCE = new ExternalAggregatedGroupMappingComparator();
   
    @SuppressWarnings("unchecked")
    private ExternalAggregatedGroupMappingComparator() {
        chain = new ComparatorChain(Arrays.asList(
                new ComparableExtractingComparator<ExternalAggregatedGroupMapping, String>() {
                    @Override
                    protected String getComparable(ExternalAggregatedGroupMapping o) {
                        return o.getGroupService();
                    }
View Full Code Here

                }
            }
            if (comps == null)
                comp = null;
            else
                comp = new ComparatorChain(comps);
        }

        if (comp == null)
            return val;
View Full Code Here

TOP

Related Classes of org.apache.commons.collections.comparators.ComparatorChain

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.