Repository: cxf Updated Branches: refs/heads/master fdab617d8 -> 3ae986b30
[CXF-6483] Optimizing ConfigurerImpl sorting code Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3ae986b3 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3ae986b3 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3ae986b3 Branch: refs/heads/master Commit: 3ae986b30fb3d85162cb70c282478cc2d36b5db1 Parents: fdab617 Author: Sergey Beryozkin <[email protected]> Authored: Fri Jul 3 10:42:20 2015 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Jul 3 10:42:20 2015 +0100 ---------------------------------------------------------------------- .../cxf/bus/blueprint/ConfigurerImpl.java | 32 +++++++------------- .../configuration/spring/ConfigurerImpl.java | 32 +++++++------------- 2 files changed, 22 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/3ae986b3/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java b/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java index b2a09b5..a251e4d 100644 --- a/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java +++ b/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java @@ -21,11 +21,9 @@ package org.apache.cxf.bus.blueprint; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -48,15 +46,22 @@ public class ConfigurerImpl implements Configurer { BlueprintContainer container; private final Map<String, List<MatcherHolder>> wildCardBeanDefinitions - = new HashMap<String, List<MatcherHolder>>(); + = new TreeMap<String, List<MatcherHolder>>(); - static class MatcherHolder { + static class MatcherHolder implements Comparable<MatcherHolder> { Matcher matcher; String wildCardId; public MatcherHolder(String orig, Matcher matcher) { wildCardId = orig; this.matcher = matcher; } + @Override + public int compareTo(MatcherHolder mh) { + Integer literalCharsLen1 = this.wildCardId.replaceAll("\\*", "").length(); + Integer literalCharsLen2 = mh.wildCardId.replaceAll("\\*", "").length(); + // The expression with more literal characters should end up on the top of the list + return literalCharsLen1.compareTo(literalCharsLen2) * -1; + } } @@ -91,10 +96,6 @@ public class ConfigurerImpl implements Configurer { } } } - Comparator<MatcherHolder> comp = new MatcherHolderComparator(); - for (Map.Entry<String, List<MatcherHolder>> entry : wildCardBeanDefinitions.entrySet()) { - Collections.sort(entry.getValue(), comp); - } } public void configureBean(Object beanInstance) { @@ -181,16 +182,5 @@ public class ConfigurerImpl implements Configurer { return beanName; } - private static class MatcherHolderComparator implements Comparator<MatcherHolder> { - - @Override - public int compare(MatcherHolder mh1, MatcherHolder mh2) { - Integer literalCharsLen1 = mh1.wildCardId.replaceAll("\\*", "").length(); - Integer literalCharsLen2 = mh2.wildCardId.replaceAll("\\*", "").length(); - // The expression with more literal characters should end up on the top of the list - return literalCharsLen1.compareTo(literalCharsLen2) * -1; - - } - - } + } http://git-wip-us.apache.org/repos/asf/cxf/blob/3ae986b3/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java b/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java index c481de3..1e745d8 100644 --- a/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java +++ b/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java @@ -21,13 +21,11 @@ package org.apache.cxf.configuration.spring; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.concurrent.CopyOnWriteArraySet; import java.util.logging.Level; import java.util.logging.Logger; @@ -61,16 +59,23 @@ public class ConfigurerImpl extends BeanConfigurerSupport private Set<ApplicationContext> appContexts; private final Map<String, List<MatcherHolder>> wildCardBeanDefinitions - = new HashMap<String, List<MatcherHolder>>(); + = new TreeMap<String, List<MatcherHolder>>(); private BeanFactory beanFactory; - static class MatcherHolder { + static class MatcherHolder implements Comparable<MatcherHolder> { Matcher matcher; String wildCardId; public MatcherHolder(String orig, Matcher matcher) { wildCardId = orig; this.matcher = matcher; } + @Override + public int compareTo(MatcherHolder mh) { + Integer literalCharsLen1 = this.wildCardId.replaceAll("\\*", "").length(); + Integer literalCharsLen2 = mh.wildCardId.replaceAll("\\*", "").length(); + // The expression with more literal characters should end up on the top of the list + return literalCharsLen1.compareTo(literalCharsLen2) * -1; + } } public ConfigurerImpl() { @@ -120,10 +125,6 @@ public class ConfigurerImpl extends BeanConfigurerSupport } } } - Comparator<MatcherHolder> comp = new MatcherHolderComparator(); - for (Map.Entry<String, List<MatcherHolder>> entry : wildCardBeanDefinitions.entrySet()) { - Collections.sort(entry.getValue(), comp); - } } public void configureBean(Object beanInstance) { @@ -284,16 +285,5 @@ public class ConfigurerImpl extends BeanConfigurerSupport protected Set<ApplicationContext> getAppContexts() { return appContexts; } - private static class MatcherHolderComparator implements Comparator<MatcherHolder> { - - @Override - public int compare(MatcherHolder mh1, MatcherHolder mh2) { - Integer literalCharsLen1 = mh1.wildCardId.replaceAll("\\*", "").length(); - Integer literalCharsLen2 = mh2.wildCardId.replaceAll("\\*", "").length(); - // The expression with more literal characters should end up on the top of the list - return literalCharsLen1.compareTo(literalCharsLen2) * -1; - - } - - } + }
