26
26
import java .util .concurrent .CompletableFuture ;
27
27
import java .util .concurrent .ConcurrentHashMap ;
28
28
import java .util .concurrent .Future ;
29
+ import java .util .function .Function ;
29
30
import java .util .stream .Stream ;
30
31
31
32
import org .springframework .core .convert .ConversionService ;
38
39
import org .springframework .data .domain .Page ;
39
40
import org .springframework .data .domain .Slice ;
40
41
import org .springframework .data .geo .GeoResults ;
42
+ import org .springframework .data .util .CustomCollections ;
41
43
import org .springframework .data .util .NullableWrapper ;
42
44
import org .springframework .data .util .NullableWrapperConverters ;
43
45
import org .springframework .data .util .StreamUtils ;
44
46
import org .springframework .data .util .Streamable ;
45
47
import org .springframework .data .util .TypeInformation ;
46
- import org .springframework .data . util . VavrCollectionConverters ;
48
+ import org .springframework .lang . NonNull ;
47
49
import org .springframework .lang .Nullable ;
48
50
import org .springframework .scheduling .annotation .AsyncResult ;
49
51
import org .springframework .util .Assert ;
@@ -80,7 +82,7 @@ public abstract class QueryExecutionConverters {
80
82
81
83
private static final Set <WrapperType > WRAPPER_TYPES = new HashSet <>();
82
84
private static final Set <WrapperType > UNWRAPPER_TYPES = new HashSet <WrapperType >();
83
- private static final Set <Converter <Object , Object >> UNWRAPPERS = new HashSet <>();
85
+ private static final Set <Function <Object , Object >> UNWRAPPERS = new HashSet <>();
84
86
private static final Set <Class <?>> ALLOWED_PAGEABLE_TYPES = new HashSet <>();
85
87
private static final Map <Class <?>, ExecutionAdapter > EXECUTION_ADAPTER = new HashMap <>();
86
88
private static final Map <Class <?>, Boolean > supportsCache = new ConcurrentReferenceHashMap <>();
@@ -98,16 +100,19 @@ public abstract class QueryExecutionConverters {
98
100
99
101
WRAPPER_TYPES .add (NullableWrapperToCompletableFutureConverter .getWrapperType ());
100
102
101
- if (VAVR_PRESENT ) {
103
+ UNWRAPPERS .addAll (CustomCollections .getUnwrappers ());
104
+
105
+ CustomCollections .getCustomTypes ().stream ()
106
+ .map (WrapperType ::multiValue )
107
+ .forEach (WRAPPER_TYPES ::add );
102
108
103
- WRAPPER_TYPES .add (VavrTraversableUnwrapper .INSTANCE .getWrapperType ());
104
- UNWRAPPERS .add (VavrTraversableUnwrapper .INSTANCE );
109
+ CustomCollections .getPaginationReturnTypes ().forEach (ALLOWED_PAGEABLE_TYPES ::add );
110
+
111
+ if (VAVR_PRESENT ) {
105
112
106
113
// Try support
107
114
WRAPPER_TYPES .add (WrapperType .singleValue (io .vavr .control .Try .class ));
108
115
EXECUTION_ADAPTER .put (io .vavr .control .Try .class , it -> io .vavr .control .Try .of (it ::get ));
109
-
110
- ALLOWED_PAGEABLE_TYPES .add (io .vavr .collection .Seq .class );
111
116
}
112
117
}
113
118
@@ -195,10 +200,7 @@ public static void registerConvertersIn(ConfigurableConversionService conversion
195
200
conversionService .removeConvertible (Collection .class , Object .class );
196
201
197
202
NullableWrapperConverters .registerConvertersIn (conversionService );
198
-
199
- if (VAVR_PRESENT ) {
200
- conversionService .addConverter (VavrCollectionConverters .FromJavaConverter .INSTANCE );
201
- }
203
+ CustomCollections .registerConvertersIn (conversionService );
202
204
203
205
conversionService .addConverter (new NullableWrapperToCompletableFutureConverter ());
204
206
conversionService .addConverter (new NullableWrapperToFutureConverter ());
@@ -220,9 +222,9 @@ public static Object unwrap(@Nullable Object source) {
220
222
return source ;
221
223
}
222
224
223
- for (Converter <Object , Object > converter : UNWRAPPERS ) {
225
+ for (Function <Object , Object > converter : UNWRAPPERS ) {
224
226
225
- Object result = converter .convert (source );
227
+ Object result = converter .apply (source );
226
228
227
229
if (result != source ) {
228
230
return result ;
@@ -310,7 +312,7 @@ private static abstract class AbstractWrapperTypeConverter implements GenericCon
310
312
* (non-Javadoc)
311
313
* @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
312
314
*/
313
-
315
+ @ NonNull
314
316
@ Override
315
317
public Set <ConvertiblePair > getConvertibleTypes () {
316
318
@@ -399,40 +401,6 @@ static WrapperType getWrapperType() {
399
401
}
400
402
}
401
403
402
- /**
403
- * Converter to unwrap Vavr {@link io.vavr.collection.Traversable} instances.
404
- *
405
- * @author Oliver Gierke
406
- * @since 2.0
407
- */
408
- private enum VavrTraversableUnwrapper implements Converter <Object , Object > {
409
-
410
- INSTANCE ;
411
-
412
- private static final TypeDescriptor OBJECT_DESCRIPTOR = TypeDescriptor .valueOf (Object .class );
413
-
414
- /*
415
- * (non-Javadoc)
416
- * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
417
- */
418
- @ Nullable
419
- @ Override
420
- @ SuppressWarnings ("null" )
421
- public Object convert (Object source ) {
422
-
423
- if (source instanceof io .vavr .collection .Traversable ) {
424
- return VavrCollectionConverters .ToJavaConverter .INSTANCE //
425
- .convert (source , TypeDescriptor .forObject (source ), OBJECT_DESCRIPTOR );
426
- }
427
-
428
- return source ;
429
- }
430
-
431
- public WrapperType getWrapperType () {
432
- return WrapperType .multiValue (io .vavr .collection .Traversable .class );
433
- }
434
- }
435
-
436
404
private static class IterableToStreamableConverter implements ConditionalGenericConverter {
437
405
438
406
private static final TypeDescriptor STREAMABLE = TypeDescriptor .valueOf (Streamable .class );
@@ -446,6 +414,7 @@ private static class IterableToStreamableConverter implements ConditionalGeneric
446
414
* (non-Javadoc)
447
415
* @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
448
416
*/
417
+ @ NonNull
449
418
@ Override
450
419
public Set <ConvertiblePair > getConvertibleTypes () {
451
420
return Collections .singleton (new ConvertiblePair (Iterable .class , Object .class ));
@@ -514,7 +483,7 @@ public Cardinality getCardinality() {
514
483
* @see java.lang.Object#equals(java.lang.Object)
515
484
*/
516
485
@ Override
517
- public boolean equals (Object o ) {
486
+ public boolean equals (@ Nullable Object o ) {
518
487
519
488
if (this == o ) {
520
489
return true ;
0 commit comments