1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
36
36
* <li>{@link HeadersRequestCondition}
37
37
* <li>{@link ConsumesRequestCondition}
38
38
* <li>{@link ProducesRequestCondition}
39
- * <li>{@code RequestCondition<?> } (optional, custom request condition)
39
+ * <li>{@code RequestCondition} (optional, custom request condition)
40
40
* </ol>
41
41
*
42
42
* @author Arjen Poutsma
@@ -59,24 +59,20 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
59
59
60
60
private final RequestConditionHolder customConditionHolder ;
61
61
62
- private int hash ;
63
62
64
63
/**
65
64
* Creates a new instance with the given request conditions.
66
65
*/
67
- public RequestMappingInfo (PatternsRequestCondition patterns ,
68
- RequestMethodsRequestCondition methods ,
69
- ParamsRequestCondition params ,
70
- HeadersRequestCondition headers ,
71
- ConsumesRequestCondition consumes ,
72
- ProducesRequestCondition produces ,
73
- RequestCondition <?> custom ) {
74
- this .patternsCondition = patterns != null ? patterns : new PatternsRequestCondition ();
75
- this .methodsCondition = methods != null ? methods : new RequestMethodsRequestCondition ();
76
- this .paramsCondition = params != null ? params : new ParamsRequestCondition ();
77
- this .headersCondition = headers != null ? headers : new HeadersRequestCondition ();
78
- this .consumesCondition = consumes != null ? consumes : new ConsumesRequestCondition ();
79
- this .producesCondition = produces != null ? produces : new ProducesRequestCondition ();
66
+ public RequestMappingInfo (PatternsRequestCondition patterns , RequestMethodsRequestCondition methods ,
67
+ ParamsRequestCondition params , HeadersRequestCondition headers , ConsumesRequestCondition consumes ,
68
+ ProducesRequestCondition produces , RequestCondition <?> custom ) {
69
+
70
+ this .patternsCondition = (patterns != null ? patterns : new PatternsRequestCondition ());
71
+ this .methodsCondition = (methods != null ? methods : new RequestMethodsRequestCondition ());
72
+ this .paramsCondition = (params != null ? params : new ParamsRequestCondition ());
73
+ this .headersCondition = (headers != null ? headers : new HeadersRequestCondition ());
74
+ this .consumesCondition = (consumes != null ? consumes : new ConsumesRequestCondition ());
75
+ this .producesCondition = (produces != null ? produces : new ProducesRequestCondition ());
80
76
this .customConditionHolder = new RequestConditionHolder (custom );
81
77
}
82
78
@@ -88,61 +84,63 @@ public RequestMappingInfo(RequestMappingInfo info, RequestCondition<?> customReq
88
84
info .consumesCondition , info .producesCondition , customRequestCondition );
89
85
}
90
86
87
+
91
88
/**
92
89
* Returns the URL patterns of this {@link RequestMappingInfo};
93
- * or instance with 0 patterns, never {@code null}
90
+ * or instance with 0 patterns, never {@code null}.
94
91
*/
95
92
public PatternsRequestCondition getPatternsCondition () {
96
- return patternsCondition ;
93
+ return this . patternsCondition ;
97
94
}
98
95
99
96
/**
100
97
* Returns the HTTP request methods of this {@link RequestMappingInfo};
101
- * or instance with 0 request methods, never {@code null}
98
+ * or instance with 0 request methods, never {@code null}.
102
99
*/
103
100
public RequestMethodsRequestCondition getMethodsCondition () {
104
- return methodsCondition ;
101
+ return this . methodsCondition ;
105
102
}
106
103
107
104
/**
108
105
* Returns the "parameters" condition of this {@link RequestMappingInfo};
109
- * or instance with 0 parameter expressions, never {@code null}
106
+ * or instance with 0 parameter expressions, never {@code null}.
110
107
*/
111
108
public ParamsRequestCondition getParamsCondition () {
112
- return paramsCondition ;
109
+ return this . paramsCondition ;
113
110
}
114
111
115
112
/**
116
113
* Returns the "headers" condition of this {@link RequestMappingInfo};
117
- * or instance with 0 header expressions, never {@code null}
114
+ * or instance with 0 header expressions, never {@code null}.
118
115
*/
119
116
public HeadersRequestCondition getHeadersCondition () {
120
- return headersCondition ;
117
+ return this . headersCondition ;
121
118
}
122
119
123
120
/**
124
121
* Returns the "consumes" condition of this {@link RequestMappingInfo};
125
- * or instance with 0 consumes expressions, never {@code null}
122
+ * or instance with 0 consumes expressions, never {@code null}.
126
123
*/
127
124
public ConsumesRequestCondition getConsumesCondition () {
128
- return consumesCondition ;
125
+ return this . consumesCondition ;
129
126
}
130
127
131
128
/**
132
129
* Returns the "produces" condition of this {@link RequestMappingInfo};
133
- * or instance with 0 produces expressions, never {@code null}
130
+ * or instance with 0 produces expressions, never {@code null}.
134
131
*/
135
132
public ProducesRequestCondition getProducesCondition () {
136
- return producesCondition ;
133
+ return this . producesCondition ;
137
134
}
138
135
139
136
/**
140
- * Returns the "custom" condition of this {@link RequestMappingInfo}; or {@code null}
137
+ * Returns the "custom" condition of this {@link RequestMappingInfo}; or {@code null}.
141
138
*/
142
139
public RequestCondition <?> getCustomCondition () {
143
- return customConditionHolder .getCondition ();
140
+ return this . customConditionHolder .getCondition ();
144
141
}
145
142
143
+
146
144
/**
147
145
* Combines "this" request mapping info (i.e. the current instance) with another request mapping info instance.
148
146
* <p>Example: combine type- and method-level request mappings.
@@ -168,61 +166,62 @@ public RequestMappingInfo combine(RequestMappingInfo other) {
168
166
* @return a new instance in case all conditions match; or {@code null} otherwise
169
167
*/
170
168
public RequestMappingInfo getMatchingCondition (HttpServletRequest request ) {
171
- RequestMethodsRequestCondition methods = methodsCondition .getMatchingCondition (request );
172
- ParamsRequestCondition params = paramsCondition .getMatchingCondition (request );
173
- HeadersRequestCondition headers = headersCondition .getMatchingCondition (request );
174
- ConsumesRequestCondition consumes = consumesCondition .getMatchingCondition (request );
175
- ProducesRequestCondition produces = producesCondition .getMatchingCondition (request );
169
+ RequestMethodsRequestCondition methods = this . methodsCondition .getMatchingCondition (request );
170
+ ParamsRequestCondition params = this . paramsCondition .getMatchingCondition (request );
171
+ HeadersRequestCondition headers = this . headersCondition .getMatchingCondition (request );
172
+ ConsumesRequestCondition consumes = this . consumesCondition .getMatchingCondition (request );
173
+ ProducesRequestCondition produces = this . producesCondition .getMatchingCondition (request );
176
174
177
175
if (methods == null || params == null || headers == null || consumes == null || produces == null ) {
178
176
return null ;
179
177
}
180
178
181
- PatternsRequestCondition patterns = patternsCondition .getMatchingCondition (request );
179
+ PatternsRequestCondition patterns = this . patternsCondition .getMatchingCondition (request );
182
180
if (patterns == null ) {
183
181
return null ;
184
182
}
185
183
186
- RequestConditionHolder custom = customConditionHolder .getMatchingCondition (request );
184
+ RequestConditionHolder custom = this . customConditionHolder .getMatchingCondition (request );
187
185
if (custom == null ) {
188
186
return null ;
189
187
}
190
188
191
189
return new RequestMappingInfo (patterns , methods , params , headers , consumes , produces , custom .getCondition ());
192
190
}
193
191
192
+
194
193
/**
195
194
* Compares "this" info (i.e. the current instance) with another info in the context of a request.
196
- * <p>Note: it is assumed both instances have been obtained via
195
+ * <p>Note: It is assumed both instances have been obtained via
197
196
* {@link #getMatchingCondition(HttpServletRequest)} to ensure they have conditions with
198
197
* content relevant to current request.
199
198
*/
200
199
public int compareTo (RequestMappingInfo other , HttpServletRequest request ) {
201
- int result = patternsCondition .compareTo (other .getPatternsCondition (), request );
200
+ int result = this . patternsCondition .compareTo (other .getPatternsCondition (), request );
202
201
if (result != 0 ) {
203
202
return result ;
204
203
}
205
- result = paramsCondition .compareTo (other .getParamsCondition (), request );
204
+ result = this . paramsCondition .compareTo (other .getParamsCondition (), request );
206
205
if (result != 0 ) {
207
206
return result ;
208
207
}
209
- result = headersCondition .compareTo (other .getHeadersCondition (), request );
208
+ result = this . headersCondition .compareTo (other .getHeadersCondition (), request );
210
209
if (result != 0 ) {
211
210
return result ;
212
211
}
213
- result = consumesCondition .compareTo (other .getConsumesCondition (), request );
212
+ result = this . consumesCondition .compareTo (other .getConsumesCondition (), request );
214
213
if (result != 0 ) {
215
214
return result ;
216
215
}
217
- result = producesCondition .compareTo (other .getProducesCondition (), request );
216
+ result = this . producesCondition .compareTo (other .getProducesCondition (), request );
218
217
if (result != 0 ) {
219
218
return result ;
220
219
}
221
- result = methodsCondition .compareTo (other .getMethodsCondition (), request );
220
+ result = this . methodsCondition .compareTo (other .getMethodsCondition (), request );
222
221
if (result != 0 ) {
223
222
return result ;
224
223
}
225
- result = customConditionHolder .compareTo (other .customConditionHolder , request );
224
+ result = this . customConditionHolder .compareTo (other .customConditionHolder , request );
226
225
if (result != 0 ) {
227
226
return result ;
228
227
}
@@ -249,30 +248,22 @@ public boolean equals(Object obj) {
249
248
250
249
@ Override
251
250
public int hashCode () {
252
- int result = hash ;
253
- if (result == 0 ) {
254
- result = patternsCondition .hashCode ();
255
- result = 31 * result + methodsCondition .hashCode ();
256
- result = 31 * result + paramsCondition .hashCode ();
257
- result = 31 * result + headersCondition .hashCode ();
258
- result = 31 * result + consumesCondition .hashCode ();
259
- result = 31 * result + producesCondition .hashCode ();
260
- result = 31 * result + customConditionHolder .hashCode ();
261
- hash = result ;
262
- }
263
- return result ;
251
+ return (this .patternsCondition .hashCode () * 31 + // primary differentiation
252
+ this .methodsCondition .hashCode () + this .paramsCondition .hashCode () +
253
+ this .headersCondition .hashCode () + this .consumesCondition .hashCode () +
254
+ this .producesCondition .hashCode () + this .customConditionHolder .hashCode ());
264
255
}
265
256
266
257
@ Override
267
258
public String toString () {
268
259
StringBuilder builder = new StringBuilder ("{" );
269
- builder .append (patternsCondition );
270
- builder .append (",methods=" ).append (methodsCondition );
271
- builder .append (",params=" ).append (paramsCondition );
272
- builder .append (",headers=" ).append (headersCondition );
273
- builder .append (",consumes=" ).append (consumesCondition );
274
- builder .append (",produces=" ).append (producesCondition );
275
- builder .append (",custom=" ).append (customConditionHolder );
260
+ builder .append (this . patternsCondition );
261
+ builder .append (",methods=" ).append (this . methodsCondition );
262
+ builder .append (",params=" ).append (this . paramsCondition );
263
+ builder .append (",headers=" ).append (this . headersCondition );
264
+ builder .append (",consumes=" ).append (this . consumesCondition );
265
+ builder .append (",produces=" ).append (this . producesCondition );
266
+ builder .append (",custom=" ).append (this . customConditionHolder );
276
267
builder .append ('}' );
277
268
return builder .toString ();
278
269
}
0 commit comments