@ -19,6 +19,7 @@ import static org.springframework.data.repository.util.ReactiveWrapperConverters
@@ -19,6 +19,7 @@ import static org.springframework.data.repository.util.ReactiveWrapperConverters
import java.util.ArrayList ;
import java.util.List ;
import java.util.function.Function ;
import org.reactivestreams.Publisher ;
import org.springframework.core.ReactiveAdapterRegistry ;
@ -54,7 +55,7 @@ import rx.Single;
@@ -54,7 +55,7 @@ import rx.Single;
@UtilityClass
public class ReactiveWrapperConverters {
private static final List < Abstract ReactiveWrapper< ? > > REACTIVE_WRAPPERS = new ArrayList < > ( ) ;
private static final List < ReactiveTyp eWrapper < ? > > REACTIVE_WRAPPERS = new ArrayList < > ( ) ;
private static final GenericConversionService GENERIC_CONVERSION_SERVICE = new GenericConversionService ( ) ;
static {
@ -194,12 +195,12 @@ public class ReactiveWrapperConverters {
@@ -194,12 +195,12 @@ public class ReactiveWrapperConverters {
* @return
* /
@SuppressWarnings ( "unchecked" )
public static < T > T map ( Object stream , Converter < Object , Object > converter ) {
public static < T > T map ( Object stream , Function < Object , Object > converter ) {
Assert . notNull ( stream , "Stream must not be null!" ) ;
Assert . notNull ( converter , "Converter must not be null!" ) ;
for ( Abstract ReactiveWrapper< ? > reactiveWrapper : REACTIVE_WRAPPERS ) {
for ( ReactiveTyp eWrapper < ? > reactiveWrapper : REACTIVE_WRAPPERS ) {
if ( ClassUtils . isAssignable ( reactiveWrapper . getWrapperClass ( ) , stream . getClass ( ) ) ) {
return ( T ) reactiveWrapper . map ( stream , converter ) ;
@ -214,11 +215,12 @@ public class ReactiveWrapperConverters {
@@ -214,11 +215,12 @@ public class ReactiveWrapperConverters {
// -------------------------------------------------------------------------
/ * *
* Wrapper descriptor that can apply a { @link Converter } to map ( convert ) items inside its stream .
* Wrapper descriptor that can apply a { @link Function } to map items inside its stream .
*
* @author Mark Paluch
* @author Christoph Strobl
* /
private interface Abstract ReactiveWrapper< T > {
private interface ReactiveTyp eWrapper < T > {
/ * *
* @return the wrapper class .
@ -226,19 +228,19 @@ public class ReactiveWrapperConverters {
@@ -226,19 +228,19 @@ public class ReactiveWrapperConverters {
Class < ? super T > getWrapperClass ( ) ;
/ * *
* Apply a { @link Converter } to a reactive type .
* Apply a { @link Function } to a reactive type .
*
* @param wrapper the reactive type , must not be { @literal null } .
* @param converter the converter , must not be { @literal null } .
* @param fun cti on the converter , must not be { @literal null } .
* @return the reactive type applying conversion .
* /
Object map ( Object wrapper , Converter < Object , Object > converter ) ;
Object map ( Object wrapper , Function < Object , Object > fun cti on) ;
}
/ * *
* Wrapper for Project Reactor ' s { @link Mono } .
* /
private enum MonoWrapper implements Abstract ReactiveWrapper< Mono < ? > > {
private enum MonoWrapper implements ReactiveTyp eWrapper < Mono < ? > > {
INSTANCE ;
@ -248,15 +250,15 @@ public class ReactiveWrapperConverters {
@@ -248,15 +250,15 @@ public class ReactiveWrapperConverters {
}
@Override
public Mono < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( Mono < ? > ) wrapper ) . map ( converter : : convert ) ;
public Mono < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( Mono < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}
/ * *
* Wrapper for Project Reactor ' s { @link Flux } .
* /
private enum FluxWrapper implements Abstract ReactiveWrapper< Flux < ? > > {
private enum FluxWrapper implements ReactiveTyp eWrapper < Flux < ? > > {
INSTANCE ;
@ -265,15 +267,15 @@ public class ReactiveWrapperConverters {
@@ -265,15 +267,15 @@ public class ReactiveWrapperConverters {
return Flux . class ;
}
public Flux < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( Flux < ? > ) wrapper ) . map ( converter : : convert ) ;
public Flux < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( Flux < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}
/ * *
* Wrapper for Reactive Stream ' s { @link Publisher } .
* /
private enum PublisherWrapper implements Abstract ReactiveWrapper< Publisher < ? > > {
private enum PublisherWrapper implements ReactiveTyp eWrapper < Publisher < ? > > {
INSTANCE ;
@ -283,24 +285,24 @@ public class ReactiveWrapperConverters {
@@ -283,24 +285,24 @@ public class ReactiveWrapperConverters {
}
@Override
public Publisher < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
public Publisher < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
if ( wrapper instanceof Mono ) {
return MonoWrapper . INSTANCE . map ( wrapper , converter ) ;
return MonoWrapper . INSTANCE . map ( wrapper , fun cti on) ;
}
if ( wrapper instanceof Flux ) {
return FluxWrapper . INSTANCE . map ( wrapper , converter ) ;
return FluxWrapper . INSTANCE . map ( wrapper , fun cti on) ;
}
return FluxWrapper . INSTANCE . map ( Flux . from ( ( Publisher < ? > ) wrapper ) , converter ) ;
return FluxWrapper . INSTANCE . map ( Flux . from ( ( Publisher < ? > ) wrapper ) , fun cti on) ;
}
}
/ * *
* Wrapper for RxJava 1 ' s { @link Single } .
* /
private enum RxJava1SingleWrapper implements Abstract ReactiveWrapper< Single < ? > > {
private enum RxJava1SingleWrapper implements ReactiveTyp eWrapper < Single < ? > > {
INSTANCE ;
@ -310,15 +312,15 @@ public class ReactiveWrapperConverters {
@@ -310,15 +312,15 @@ public class ReactiveWrapperConverters {
}
@Override
public Single < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( Single < ? > ) wrapper ) . map ( converter : : convert ) ;
public Single < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( Single < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}
/ * *
* Wrapper for RxJava 1 ' s { @link Observable } .
* /
private enum RxJava1ObservableWrapper implements Abstract ReactiveWrapper< Observable < ? > > {
private enum RxJava1ObservableWrapper implements ReactiveTyp eWrapper < Observable < ? > > {
INSTANCE ;
@ -328,15 +330,15 @@ public class ReactiveWrapperConverters {
@@ -328,15 +330,15 @@ public class ReactiveWrapperConverters {
}
@Override
public Observable < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( Observable < ? > ) wrapper ) . map ( converter : : convert ) ;
public Observable < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( Observable < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}
/ * *
* Wrapper for RxJava 2 ' s { @link io . reactivex . Single } .
* /
private enum RxJava2SingleWrapper implements Abstract ReactiveWrapper< io . reactivex . Single < ? > > {
private enum RxJava2SingleWrapper implements ReactiveTyp eWrapper < io . reactivex . Single < ? > > {
INSTANCE ;
@ -346,15 +348,15 @@ public class ReactiveWrapperConverters {
@@ -346,15 +348,15 @@ public class ReactiveWrapperConverters {
}
@Override
public io . reactivex . Single < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( io . reactivex . Single < ? > ) wrapper ) . map ( converter : : convert ) ;
public io . reactivex . Single < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( io . reactivex . Single < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}
/ * *
* Wrapper for RxJava 2 ' s { @link io . reactivex . Maybe } .
* /
private enum RxJava2MaybeWrapper implements Abstract ReactiveWrapper< io . reactivex . Maybe < ? > > {
private enum RxJava2MaybeWrapper implements ReactiveTyp eWrapper < Maybe < ? > > {
INSTANCE ;
@ -364,15 +366,15 @@ public class ReactiveWrapperConverters {
@@ -364,15 +366,15 @@ public class ReactiveWrapperConverters {
}
@Override
public io . reactivex . Maybe < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( io . reactivex . Maybe < ? > ) wrapper ) . map ( converter : : convert ) ;
public io . reactivex . Maybe < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( io . reactivex . Maybe < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}
/ * *
* Wrapper for RxJava 2 ' s { @link io . reactivex . Observable } .
* /
private enum RxJava2ObservableWrapper implements Abstract ReactiveWrapper< io . reactivex . Observable < ? > > {
private enum RxJava2ObservableWrapper implements ReactiveTyp eWrapper < io . reactivex . Observable < ? > > {
INSTANCE ;
@ -382,15 +384,15 @@ public class ReactiveWrapperConverters {
@@ -382,15 +384,15 @@ public class ReactiveWrapperConverters {
}
@Override
public io . reactivex . Observable < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( io . reactivex . Observable < ? > ) wrapper ) . map ( converter : : convert ) ;
public io . reactivex . Observable < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( io . reactivex . Observable < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}
/ * *
* Wrapper for RxJava 2 ' s { @link io . reactivex . Flowable } .
* /
private enum RxJava2FlowableWrapper implements Abstract ReactiveWrapper< io . reactivex . Flowable < ? > > {
private enum RxJava2FlowableWrapper implements ReactiveTyp eWrapper < Flowable < ? > > {
INSTANCE ;
@ -400,8 +402,8 @@ public class ReactiveWrapperConverters {
@@ -400,8 +402,8 @@ public class ReactiveWrapperConverters {
}
@Override
public io . reactivex . Flowable < ? > map ( Object wrapper , Converter < Object , Object > converter ) {
return ( ( io . reactivex . Flowable < ? > ) wrapper ) . map ( converter : : convert ) ;
public io . reactivex . Flowable < ? > map ( Object wrapper , Function < Object , Object > fun cti on) {
return ( ( io . reactivex . Flowable < ? > ) wrapper ) . map ( fun cti on: : apply ) ;
}
}