35
35
import org .springframework .data .repository .query .parser .Part ;
36
36
import org .springframework .data .repository .query .parser .Part .IgnoreCaseType ;
37
37
import org .springframework .data .repository .query .parser .PartTree ;
38
+ import org .springframework .lang .Contract ;
38
39
import org .springframework .util .ObjectUtils ;
39
40
40
41
/**
@@ -124,7 +125,8 @@ public Predicate<Object> isFalse() {
124
125
return new ValueComparingPredicate (part .getProperty (), false );
125
126
}
126
127
127
- public Predicate <Object > isEqualTo (Object value ) {
128
+ @ Contract ("_ -> new" )
129
+ public Predicate <Object > isEqualTo (@ Nullable Object value ) {
128
130
return new ValueComparingPredicate (part .getProperty (), o -> {
129
131
130
132
if (!ObjectUtils .nullSafeEquals (IgnoreCaseType .NEVER , part .shouldIgnoreCase ())) {
@@ -145,22 +147,27 @@ public Predicate<Object> isNotNull() {
145
147
return isNull ().negate ();
146
148
}
147
149
148
- public Predicate <Object > isLessThan (Object value ) {
150
+ @ Contract ("_ -> new" )
151
+ public Predicate <Object > isLessThan (@ Nullable Object value ) {
149
152
return new ValueComparingPredicate (part .getProperty (), o -> comparator ().compare (o , value ) < 0 );
150
153
}
151
154
152
- public Predicate <Object > isLessThanEqual (Object value ) {
155
+ @ Contract ("_ -> new" )
156
+ public Predicate <Object > isLessThanEqual (@ Nullable Object value ) {
153
157
return new ValueComparingPredicate (part .getProperty (), o -> comparator ().compare (o , value ) <= 0 );
154
158
}
155
159
156
- public Predicate <Object > isGreaterThan (Object value ) {
160
+ @ Contract ("_ -> new" )
161
+ public Predicate <Object > isGreaterThan (@ Nullable Object value ) {
157
162
return new ValueComparingPredicate (part .getProperty (), o -> comparator ().compare (o , value ) > 0 );
158
163
}
159
164
160
- public Predicate <Object > isGreaterThanEqual (Object value ) {
165
+ @ Contract ("_ -> new" )
166
+ public Predicate <Object > isGreaterThanEqual (@ Nullable Object value ) {
161
167
return new ValueComparingPredicate (part .getProperty (), o -> comparator ().compare (o , value ) >= 0 );
162
168
}
163
169
170
+ @ Contract ("!null -> new" )
164
171
public Predicate <Object > matches (Pattern pattern ) {
165
172
166
173
return new ValueComparingPredicate (part .getProperty (), o -> {
@@ -172,7 +179,8 @@ public Predicate<Object> matches(Pattern pattern) {
172
179
});
173
180
}
174
181
175
- public Predicate <Object > matches (Object value ) {
182
+ @ Contract ("_ -> new" )
183
+ public Predicate <Object > matches (@ Nullable Object value ) {
176
184
return new ValueComparingPredicate (part .getProperty (), o -> {
177
185
178
186
if (o == null || value == null ) {
@@ -188,10 +196,12 @@ public Predicate<Object> matches(Object value) {
188
196
});
189
197
}
190
198
199
+ @ Contract ("!null -> new" )
191
200
public Predicate <Object > matches (String regex ) {
192
201
return matches (Pattern .compile (regex ));
193
202
}
194
203
204
+ @ Contract ("!null -> new" )
195
205
public Predicate <Object > in (Object value ) {
196
206
return new ValueComparingPredicate (part .getProperty (), o -> {
197
207
@@ -207,11 +217,11 @@ public Predicate<Object> in(Object value) {
207
217
return ObjectUtils .containsElement (ObjectUtils .toObjectArray (value ), value );
208
218
}
209
219
return false ;
210
-
211
220
});
212
221
}
213
222
214
- public Predicate <Object > contains (Object value ) {
223
+ @ Contract ("_ -> new" )
224
+ public Predicate <Object > contains (@ Nullable Object value ) {
215
225
216
226
return new ValueComparingPredicate (part .getProperty (), o -> {
217
227
@@ -245,6 +255,7 @@ public Predicate<Object> contains(Object value) {
245
255
});
246
256
}
247
257
258
+ @ Contract ("!null -> new" )
248
259
public Predicate <Object > startsWith (Object value ) {
249
260
return new ValueComparingPredicate (part .getProperty (), o -> {
250
261
@@ -261,6 +272,7 @@ public Predicate<Object> startsWith(Object value) {
261
272
262
273
}
263
274
275
+ @ Contract ("!null -> new" )
264
276
public Predicate <Object > endsWith (Object value ) {
265
277
266
278
return new ValueComparingPredicate (part .getProperty (), o -> {
@@ -281,13 +293,13 @@ public Predicate<Object> endsWith(Object value) {
281
293
static class ValueComparingPredicate implements Predicate <Object > {
282
294
283
295
private final PropertyPath path ;
284
- private final Function <Object , Boolean > check ;
296
+ private final Function <@ Nullable Object , Boolean > check ;
285
297
286
- public ValueComparingPredicate (PropertyPath path , Object expected ) {
298
+ public ValueComparingPredicate (PropertyPath path , @ Nullable Object expected ) {
287
299
this (path , (value ) -> ObjectUtils .nullSafeEquals (value , expected ));
288
300
}
289
301
290
- public ValueComparingPredicate (PropertyPath path , Function <Object , Boolean > check ) {
302
+ public ValueComparingPredicate (PropertyPath path , Function <@ Nullable Object , Boolean > check ) {
291
303
this .path = path ;
292
304
this .check = check ;
293
305
}
0 commit comments