Example usage for org.springframework.core OrderComparator OrderComparator

List of usage examples for org.springframework.core OrderComparator OrderComparator

Introduction

In this page you can find the example usage for org.springframework.core OrderComparator OrderComparator.

Prototype

OrderComparator

Source Link

Usage

From source file:net.javacrumbs.springws.test.MockWebServiceMessageSender.java

@SuppressWarnings("unchecked")
private void autowireRequestProcessors() {
    if (isAutowireRequestProcessors()) {
        List<RequestProcessor> processors = new ArrayList<RequestProcessor>(
                applicationContext.getBeansOfType(RequestProcessor.class).values());
        if (!processors.isEmpty()) {
            processors.addAll(requestProcessors);
            Collections.sort(processors, new OrderComparator());
            requestProcessors = processors;
        }/*  w w  w . ja  va 2 s.com*/
    }
}

From source file:com.erinors.hpb.server.serviceimpl.PersistentObjectManagerImpl.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    handlers = new ArrayList<PersistentObjectHandler>(
            (Collection<? extends PersistentObjectHandler>) beanFactory
                    .getBeansOfType(PersistentObjectHandler.class).values());

    Collections.sort(handlers, new Comparator<PersistentObjectHandler>() {
        private OrderComparator orderComparator = new OrderComparator();

        @Override// www  .java  2s .com
        public int compare(PersistentObjectHandler o1, PersistentObjectHandler o2) {
            return orderComparator.compare(o1, o2);
        }
    });
}

From source file:org.jolokia.jvmagent.spring.SpringJolokiaAgent.java

/**
 * Callback used for initializing and optionally starting up the server
 *///from   w  w  w  .  j av  a2s  . c  om
public void afterPropertiesSet() throws IOException {
    Map<String, String> finalConfig = new HashMap<String, String>();
    if (systemPropertyMode == SystemPropertyMode.MODE_FALLBACK) {
        finalConfig.putAll(lookupSystemProperties());
    }
    if (config != null) {
        finalConfig.putAll(config.getConfig());
    }
    if (lookupConfig) {
        // Merge all configs in the context in the reverse order
        Map<String, SpringJolokiaConfigHolder> configsMap = context
                .getBeansOfType(SpringJolokiaConfigHolder.class);
        List<SpringJolokiaConfigHolder> configs = new ArrayList<SpringJolokiaConfigHolder>(configsMap.values());
        Collections.sort(configs, new OrderComparator());
        for (SpringJolokiaConfigHolder c : configs) {
            if (c != config) {
                finalConfig.putAll(c.getConfig());
            }
        }
    }
    if (systemPropertyMode == SystemPropertyMode.MODE_OVERRIDE) {
        finalConfig.putAll(lookupSystemProperties());
    }
    String autoStartS = finalConfig.remove("autoStart");
    boolean autoStart = true;
    if (autoStartS != null) {
        autoStart = Boolean.parseBoolean(autoStartS);
    }
    init(new JolokiaServerConfig(finalConfig), false);
    if (autoStart) {
        start();
    }
}

From source file:com.fortify.processrunner.processor.CompositeOrderedProcessor.java

/**
 * This method retrieves the currently configured {@link IProcessor} instances
 * from our superclass, and returns them in a sorted order.
 *///from   w ww .ja v  a2s. co m
@Override
protected List<IProcessor> getProcessors() {
    List<IProcessor> result = new ArrayList<IProcessor>(super.getProcessors());
    result.sort(new OrderComparator());
    return result;
}

From source file:org.jolokia.support.spring.SpringJolokiaAgent.java

private Map<String, String> lookupConfigurationFromContext() {
    // Merge all configs in the context in the reverse order
    Map<String, String> config = new HashMap<String, String>();
    Map<String, SpringJolokiaConfigHolder> configsMap = context.getBeansOfType(SpringJolokiaConfigHolder.class);
    List<SpringJolokiaConfigHolder> configs = new ArrayList<SpringJolokiaConfigHolder>(configsMap.values());
    Collections.sort(configs, new OrderComparator());
    for (SpringJolokiaConfigHolder c : configs) {
        if (c != this.configHolder) {
            config.putAll(c.getConfig());
        }//from   w w  w .ja v a  2 s  .  co m
    }
    return config;
}

From source file:biz.deinum.multitenant.aop.target.ContextSwappableTargetSource.java

@SuppressWarnings("unchecked")
private void initTargetRegistries() {
    if (this.registries.isEmpty()) {
        final Map<String, ? extends TargetRegistry> matchingBeans = BeanFactoryUtils
                .beansOfTypeIncludingAncestors(this.context, TargetRegistry.class, true, false);
        if (!matchingBeans.isEmpty()) {
            this.registries.addAll((Collection<? extends TargetRegistry<?>>) matchingBeans.values());
            Collections.sort(this.registries, new OrderComparator());
        } else {//from  w ww .j a va2 s .co  m
            @SuppressWarnings("rawtypes")
            final BeanFactoryTargetRegistry<?> registry = new BeanFactoryTargetRegistry();
            registry.setBeanFactory(this.context);
            this.registries.add(registry);
        }
    }
}

From source file:grails.plugin.searchable.internal.compass.config.DefaultGrailsDomainClassMappingSearchableCompassConfigurator.java

public void setClassMappingStrategies(
        SearchableGrailsDomainClassMappingConfigurator[] classMappingConfigurators) {
    Arrays.sort(classMappingConfigurators, new OrderComparator());
    this.classMappingConfigurators = classMappingConfigurators;
}

From source file:co.paralleluniverse.springframework.web.servlet.mvc.method.annotation.FiberRequestMappingHandlerAdapter.java

private void initControllerAdviceCache() {
    if (getApplicationContext() == null) {
        return;//from   w  ww  . j  a  va2 s.com
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Looking for controller advice: " + getApplicationContext());
    }

    List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
    Collections.sort(beans, new OrderComparator());

    for (ControllerAdviceBean bean : beans) {
        Set<Method> attrMethods = HandlerMethodSelector.selectMethods(bean.getBeanType(),
                MODEL_ATTRIBUTE_METHODS);
        if (!attrMethods.isEmpty()) {
            this.modelAttributeAdviceCache.put(bean, attrMethods);
            logger.info("Detected @ModelAttribute methods in " + bean);
        }
        Set<Method> binderMethods = HandlerMethodSelector.selectMethods(bean.getBeanType(),
                INIT_BINDER_METHODS);
        if (!binderMethods.isEmpty()) {
            this.initBinderAdviceCache.put(bean, binderMethods);
            logger.info("Detected @InitBinder methods in " + bean);
        }
    }
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Performs sorting logic of the given list of <code>Ordered</code>
 * instances by its order property/* w ww. j  a v  a  2s.  com*/
 *
 * <p>
 * Items list is sorted based on its order property. Lower order values are
 * placed higher in the list. If a item does not have a value assigned for
 * the order (or is equal to the default order of 0), it will be assigned
 * the a value based on the given order sequence integer. If two or more
 * items share the same order value, all but the last item found in the list
 * will be removed.
 * </p>
 * 
 * @param <T> ordered type
 * @param <T> ordered type
 * @param items
 * @param defaultOrderSequence
 * @return List<Ordered> sorted items
 * @see org.kuali.rice.krad.uif.component.Component#getOrder()
 * @see org.springframework.core.Ordered
 */
public static <T extends Ordered> List<T> sort(List<T> items, int defaultOrderSequence) {
    if (items == null) {
        return null;
    }

    List<T> orderedItems = new ArrayList<T>(items.size());

    // do replacement for items with the same order property value
    Set<Integer> foundOrders = new HashSet<Integer>();

    // reverse the list, so items later in the list win
    for (int i = items.size() - 1; i >= 0; i--) {
        T component = items.get(i);
        int order = component.getOrder();

        // if order not set just add to list
        if (order == 0) {
            orderedItems.add(component);
        }
        // check if the order value has been used already
        else if (!foundOrders.contains(Integer.valueOf(order))) {
            orderedItems.add(component);
            foundOrders.add(Integer.valueOf(order));
        }
    }

    // now reverse the list back so we can assign defaults for items without
    // an order value
    for (int i = 0; i < items.size(); i++) {
        Ordered component = items.get(i);
        int order = component.getOrder();

        // if order property not set assign default
        if (order == 0) {
            defaultOrderSequence++;
            while (foundOrders.contains(Integer.valueOf(defaultOrderSequence))) {
                defaultOrderSequence++;
            }
            component.setOrder(defaultOrderSequence);
        }
    }

    // now sort the list by its order property
    Collections.sort(orderedItems, new OrderComparator());

    return orderedItems;
}

From source file:org.springframework.aop.support.AopUtils.java

/**
 * Sort the given list of advisors by order value
 * @param advisors Spring AOP advisors to sort
 * @return sorted list of advisors/* w w w. ja v  a2s.  co  m*/
 */
public static List sortAdvisorsByOrder(List advisors) {
    Collections.sort(advisors, new OrderComparator());
    return advisors;
}