Skip to content

Commit a637213

Browse files
committed
Aligned default Map capacity
1 parent 6500018 commit a637213

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -83,34 +83,32 @@ public abstract class AbstractMethodMessageHandler<T>
8383

8484
protected final Log logger = LogFactory.getLog(getClass());
8585

86-
private final List<HandlerMethodArgumentResolver> customArgumentResolvers = new ArrayList<HandlerMethodArgumentResolver>(4);
86+
private Collection<String> destinationPrefixes = new ArrayList<String>();
87+
88+
private final List<HandlerMethodArgumentResolver> customArgumentResolvers =
89+
new ArrayList<HandlerMethodArgumentResolver>(4);
90+
91+
private final List<HandlerMethodReturnValueHandler> customReturnValueHandlers =
92+
new ArrayList<HandlerMethodReturnValueHandler>(4);
8793

88-
private final List<HandlerMethodReturnValueHandler> customReturnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>(4);
94+
private final HandlerMethodArgumentResolverComposite argumentResolvers =
95+
new HandlerMethodArgumentResolverComposite();
8996

90-
private final HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite();
97+
private final HandlerMethodReturnValueHandlerComposite returnValueHandlers =
98+
new HandlerMethodReturnValueHandlerComposite();
9199

92-
private final HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite();
100+
private ApplicationContext applicationContext;
93101

94-
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<T, HandlerMethod>();
102+
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<T, HandlerMethod>(64);
95103

96-
private final MultiValueMap<String, T> destinationLookup = new LinkedMultiValueMap<String, T>();
104+
private final MultiValueMap<String, T> destinationLookup = new LinkedMultiValueMap<String, T>(64);
97105

98106
private final Map<Class<?>, AbstractExceptionHandlerMethodResolver> exceptionHandlerCache =
99107
new ConcurrentHashMap<Class<?>, AbstractExceptionHandlerMethodResolver>(64);
100108

101109
private final Map<MessagingAdviceBean, AbstractExceptionHandlerMethodResolver> exceptionHandlerAdviceCache =
102110
new LinkedHashMap<MessagingAdviceBean, AbstractExceptionHandlerMethodResolver>(64);
103111

104-
private Collection<String> destinationPrefixes = new ArrayList<String>();
105-
106-
private ApplicationContext applicationContext;
107-
108-
/**
109-
* Return the configured destination prefixes.
110-
*/
111-
public Collection<String> getDestinationPrefixes() {
112-
return this.destinationPrefixes;
113-
}
114112

115113
/**
116114
* When this property is configured only messages to destinations matching
@@ -131,16 +129,15 @@ public void setDestinationPrefixes(Collection<String> prefixes) {
131129
}
132130

133131
/**
134-
* Return the configured custom argument resolvers, if any.
132+
* Return the configured destination prefixes, if any.
135133
*/
136-
public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers() {
137-
return this.customArgumentResolvers;
134+
public Collection<String> getDestinationPrefixes() {
135+
return this.destinationPrefixes;
138136
}
139137

140138
/**
141139
* Sets the list of custom {@code HandlerMethodArgumentResolver}s that will be used
142140
* after resolvers for supported argument type.
143-
* @param customArgumentResolvers the list of resolvers; never {@code null}.
144141
*/
145142
public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> customArgumentResolvers) {
146143
this.customArgumentResolvers.clear();
@@ -150,16 +147,15 @@ public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> custo
150147
}
151148

152149
/**
153-
* Return the configured custom return value handlers, if any.
150+
* Return the configured custom argument resolvers, if any.
154151
*/
155-
public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers() {
156-
return this.customReturnValueHandlers;
152+
public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers() {
153+
return this.customArgumentResolvers;
157154
}
158155

159156
/**
160157
* Set the list of custom {@code HandlerMethodReturnValueHandler}s that will be used
161158
* after return value handlers for known types.
162-
* @param customReturnValueHandlers the list of custom return value handlers, never {@code null}.
163159
*/
164160
public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> customReturnValueHandlers) {
165161
this.customReturnValueHandlers.clear();
@@ -169,15 +165,15 @@ public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> c
169165
}
170166

171167
/**
172-
* Return the configured argument resolvers, if any.
168+
* Return the configured custom return value handlers, if any.
173169
*/
174-
public List<HandlerMethodArgumentResolver> getArgumentResolvers() {
175-
return this.argumentResolvers.getResolvers();
170+
public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers() {
171+
return this.customReturnValueHandlers;
176172
}
177173

178174
/**
179-
* Configure the complete list of supported argument types effectively overriding
180-
* the ones configured by default. This is an advanced option. For most use cases
175+
* Configure the complete list of supported argument types, effectively overriding
176+
* the ones configured by default. This is an advanced option; for most use cases
181177
* it should be sufficient to use {@link #setCustomArgumentResolvers}.
182178
*/
183179
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
@@ -189,15 +185,15 @@ public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentRes
189185
}
190186

191187
/**
192-
* Return the configured return value handlers, if any.
188+
* Return the complete list of argument resolvers.
193189
*/
194-
public List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
195-
return this.returnValueHandlers.getReturnValueHandlers();
190+
public List<HandlerMethodArgumentResolver> getArgumentResolvers() {
191+
return this.argumentResolvers.getResolvers();
196192
}
197193

198194
/**
199-
* Configure the complete list of supported return value types effectively overriding
200-
* the ones configured by default. This is an advanced option. For most use cases
195+
* Configure the complete list of supported return value types, effectively overriding
196+
* the ones configured by default. This is an advanced option; for most use cases
201197
* it should be sufficient to use {@link #setCustomReturnValueHandlers}.
202198
*/
203199
public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
@@ -208,15 +204,23 @@ public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnV
208204
this.returnValueHandlers.addHandlers(returnValueHandlers);
209205
}
210206

211-
public ApplicationContext getApplicationContext() {
212-
return this.applicationContext;
207+
/**
208+
* Return the complete list of return value handlers.
209+
*/
210+
public List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
211+
return this.returnValueHandlers.getReturnValueHandlers();
213212
}
214213

215214
@Override
216215
public void setApplicationContext(ApplicationContext applicationContext) {
217216
this.applicationContext = applicationContext;
218217
}
219218

219+
public ApplicationContext getApplicationContext() {
220+
return this.applicationContext;
221+
}
222+
223+
220224
@Override
221225
public void afterPropertiesSet() {
222226
if (this.argumentResolvers.getResolvers().isEmpty()) {
@@ -359,7 +363,9 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) {
359363
* (e.g. to support "global" {@code @MessageExceptionHandler}).
360364
* @since 4.2
361365
*/
362-
protected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) {
366+
protected void registerExceptionHandlerAdvice(
367+
MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) {
368+
363369
this.exceptionHandlerAdviceCache.put(bean, resolver);
364370
}
365371

0 commit comments

Comments
 (0)