Example usage for org.aspectj.util PartialOrder sort

List of usage examples for org.aspectj.util PartialOrder sort

Introduction

In this page you can find the example usage for org.aspectj.util PartialOrder sort.

Prototype

public static <T extends PartialComparable> List<T> sort(List<T> objects) 

Source Link

Usage

From source file:org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.java

License:Apache License

/**
 * Sort the rest by AspectJ precedence. If two pieces of advice have
 * come from the same aspect they will have the same order.
 * Advice from the same aspect is then further ordered according to the
 * following rules:/*from w  ww.ja va2 s.  co  m*/
 * <ul>
 * <li>if either of the pair is after advice, then the advice declared
 * last gets highest precedence (runs last)</li>
 * <li>otherwise the advice declared first gets highest precedence (runs first)</li>
 * </ul>
 * <p><b>Important:</b> Advisors are sorted in precedence order, from highest
 * precedence to lowest. "On the way in" to a join point, the highest precedence
 * advisor should run first. "On the way out" of a join point, the highest precedence
 * advisor should run last.
 */
@Override
@SuppressWarnings("unchecked")
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
    List<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors = new ArrayList<PartiallyComparableAdvisorHolder>(
            advisors.size());
    for (Advisor element : advisors) {
        partiallyComparableAdvisors
                .add(new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
    }
    List<PartiallyComparableAdvisorHolder> sorted = PartialOrder.sort(partiallyComparableAdvisors);
    if (sorted != null) {
        List<Advisor> result = new ArrayList<Advisor>(advisors.size());
        for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
            result.add(pcAdvisor.getAdvisor());
        }
        return result;
    } else {
        return super.sortAdvisors(advisors);
    }
}