optimized OrderComparator usage
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj.annotation;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -121,7 +120,7 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
|
||||
List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory);
|
||||
advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass());
|
||||
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
|
||||
Collections.sort(advisors, new OrderComparator());
|
||||
OrderComparator.sort(advisors);
|
||||
addAdvisors(advisors);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,14 +55,14 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||
private static final int LOWER_PRECEDENCE = 1;
|
||||
private static final int NOT_COMPARABLE = 0;
|
||||
|
||||
private final Comparator advisorComparator;
|
||||
private final Comparator<? super Advisor> advisorComparator;
|
||||
|
||||
|
||||
/**
|
||||
* Create a default AspectJPrecedenceComparator.
|
||||
*/
|
||||
public AspectJPrecedenceComparator() {
|
||||
this.advisorComparator = new OrderComparator();
|
||||
this.advisorComparator = OrderComparator.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||
* for comparing {@link org.springframework.aop.Advisor} instances.
|
||||
* @param advisorComparator the Comparator to use for Advisors
|
||||
*/
|
||||
public AspectJPrecedenceComparator(Comparator advisorComparator) {
|
||||
public AspectJPrecedenceComparator(Comparator<? super Advisor> advisorComparator) {
|
||||
Assert.notNull(advisorComparator, "Advisor comparator must not be null");
|
||||
this.advisorComparator = advisorComparator;
|
||||
}
|
||||
@@ -138,12 +138,8 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||
}
|
||||
|
||||
private boolean declaredInSameAspect(Advisor advisor1, Advisor advisor2) {
|
||||
if (!(hasAspectName(advisor1) && hasAspectName(advisor2))) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return getAspectName(advisor1).equals(getAspectName(advisor2));
|
||||
}
|
||||
return (hasAspectName(advisor1) && hasAspectName(advisor2) &&
|
||||
getAspectName(advisor1).equals(getAspectName(advisor2)));
|
||||
}
|
||||
|
||||
private boolean hasAspectName(Advisor anAdvisor) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,9 +21,7 @@ import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -474,7 +472,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
* We need to do this every time a new prototype instance is returned,
|
||||
* to return distinct instances of prototype Advisors and Advices.
|
||||
*/
|
||||
private List freshAdvisorChain() {
|
||||
private List<Advisor> freshAdvisorChain() {
|
||||
Advisor[] advisors = getAdvisors();
|
||||
List<Advisor> freshAdvisors = new ArrayList<Advisor>(advisors.length);
|
||||
for (Advisor advisor : advisors) {
|
||||
@@ -521,7 +519,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
beans.add(bean);
|
||||
names.put(bean, name);
|
||||
}
|
||||
Collections.sort(beans, new OrderComparator());
|
||||
OrderComparator.sort(beans);
|
||||
for (Object bean : beans) {
|
||||
String name = names.get(bean);
|
||||
if (name.startsWith(prefix)) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.Advisor;
|
||||
@@ -141,7 +140,7 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
|
||||
* @see org.springframework.core.OrderComparator
|
||||
*/
|
||||
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
|
||||
Collections.sort(advisors, new OrderComparator());
|
||||
OrderComparator.sort(advisors);
|
||||
return advisors;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user