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.
@@ -170,62 +168,63 @@ public RequestMappingInfo combine(RequestMappingInfo other) {
170
168
*/
171
169
@ Override
172
170
public RequestMappingInfo getMatchingCondition (HttpServletRequest request ) {
173
- RequestMethodsRequestCondition methods = methodsCondition .getMatchingCondition (request );
174
- ParamsRequestCondition params = paramsCondition .getMatchingCondition (request );
175
- HeadersRequestCondition headers = headersCondition .getMatchingCondition (request );
176
- ConsumesRequestCondition consumes = consumesCondition .getMatchingCondition (request );
177
- ProducesRequestCondition produces = producesCondition .getMatchingCondition (request );
171
+ RequestMethodsRequestCondition methods = this . methodsCondition .getMatchingCondition (request );
172
+ ParamsRequestCondition params = this . paramsCondition .getMatchingCondition (request );
173
+ HeadersRequestCondition headers = this . headersCondition .getMatchingCondition (request );
174
+ ConsumesRequestCondition consumes = this . consumesCondition .getMatchingCondition (request );
175
+ ProducesRequestCondition produces = this . producesCondition .getMatchingCondition (request );
178
176
179
177
if (methods == null || params == null || headers == null || consumes == null || produces == null ) {
180
178
return null ;
181
179
}
182
180
183
- PatternsRequestCondition patterns = patternsCondition .getMatchingCondition (request );
181
+ PatternsRequestCondition patterns = this . patternsCondition .getMatchingCondition (request );
184
182
if (patterns == null ) {
185
183
return null ;
186
184
}
187
185
188
- RequestConditionHolder custom = customConditionHolder .getMatchingCondition (request );
186
+ RequestConditionHolder custom = this . customConditionHolder .getMatchingCondition (request );
189
187
if (custom == null ) {
190
188
return null ;
191
189
}
192
190
193
191
return new RequestMappingInfo (patterns , methods , params , headers , consumes , produces , custom .getCondition ());
194
192
}
195
193
194
+
196
195
/**
197
196
* Compares "this" info (i.e. the current instance) with another info in the context of a request.
198
- * <p>Note: it is assumed both instances have been obtained via
197
+ * <p>Note: It is assumed both instances have been obtained via
199
198
* {@link #getMatchingCondition(HttpServletRequest)} to ensure they have conditions with
200
199
* content relevant to current request.
201
200
*/
202
201
@ Override
203
202
public int compareTo (RequestMappingInfo other , HttpServletRequest request ) {
204
- int result = patternsCondition .compareTo (other .getPatternsCondition (), request );
203
+ int result = this . patternsCondition .compareTo (other .getPatternsCondition (), request );
205
204
if (result != 0 ) {
206
205
return result ;
207
206
}
208
- result = paramsCondition .compareTo (other .getParamsCondition (), request );
207
+ result = this . paramsCondition .compareTo (other .getParamsCondition (), request );
209
208
if (result != 0 ) {
210
209
return result ;
211
210
}
212
- result = headersCondition .compareTo (other .getHeadersCondition (), request );
211
+ result = this . headersCondition .compareTo (other .getHeadersCondition (), request );
213
212
if (result != 0 ) {
214
213
return result ;
215
214
}
216
- result = consumesCondition .compareTo (other .getConsumesCondition (), request );
215
+ result = this . consumesCondition .compareTo (other .getConsumesCondition (), request );
217
216
if (result != 0 ) {
218
217
return result ;
219
218
}
220
- result = producesCondition .compareTo (other .getProducesCondition (), request );
219
+ result = this . producesCondition .compareTo (other .getProducesCondition (), request );
221
220
if (result != 0 ) {
222
221
return result ;
223
222
}
224
- result = methodsCondition .compareTo (other .getMethodsCondition (), request );
223
+ result = this . methodsCondition .compareTo (other .getMethodsCondition (), request );
225
224
if (result != 0 ) {
226
225
return result ;
227
226
}
228
- result = customConditionHolder .compareTo (other .customConditionHolder , request );
227
+ result = this . customConditionHolder .compareTo (other .customConditionHolder , request );
229
228
if (result != 0 ) {
230
229
return result ;
231
230
}
@@ -252,30 +251,22 @@ public boolean equals(Object obj) {
252
251
253
252
@ Override
254
253
public int hashCode () {
255
- int result = hash ;
256
- if (result == 0 ) {
257
- result = patternsCondition .hashCode ();
258
- result = 31 * result + methodsCondition .hashCode ();
259
- result = 31 * result + paramsCondition .hashCode ();
260
- result = 31 * result + headersCondition .hashCode ();
261
- result = 31 * result + consumesCondition .hashCode ();
262
- result = 31 * result + producesCondition .hashCode ();
263
- result = 31 * result + customConditionHolder .hashCode ();
264
- hash = result ;
265
- }
266
- return result ;
254
+ return (this .patternsCondition .hashCode () * 31 + // primary differentiation
255
+ this .methodsCondition .hashCode () + this .paramsCondition .hashCode () +
256
+ this .headersCondition .hashCode () + this .consumesCondition .hashCode () +
257
+ this .producesCondition .hashCode () + this .customConditionHolder .hashCode ());
267
258
}
268
259
269
260
@ Override
270
261
public String toString () {
271
262
StringBuilder builder = new StringBuilder ("{" );
272
- builder .append (patternsCondition );
273
- builder .append (",methods=" ).append (methodsCondition );
274
- builder .append (",params=" ).append (paramsCondition );
275
- builder .append (",headers=" ).append (headersCondition );
276
- builder .append (",consumes=" ).append (consumesCondition );
277
- builder .append (",produces=" ).append (producesCondition );
278
- builder .append (",custom=" ).append (customConditionHolder );
263
+ builder .append (this . patternsCondition );
264
+ builder .append (",methods=" ).append (this . methodsCondition );
265
+ builder .append (",params=" ).append (this . paramsCondition );
266
+ builder .append (",headers=" ).append (this . headersCondition );
267
+ builder .append (",consumes=" ).append (this . consumesCondition );
268
+ builder .append (",produces=" ).append (this . producesCondition );
269
+ builder .append (",custom=" ).append (this . customConditionHolder );
279
270
builder .append ('}' );
280
271
return builder .toString ();
281
272
}
0 commit comments