1818import reactor .core .publisher .Flux ;
1919import reactor .core .publisher .Mono ;
2020
21- import java .util .Arrays ;
22- import java .util .Map ;
23- import java .util .Optional ;
24-
25- import org .springframework .core .ReactiveAdapter ;
26- import org .springframework .core .ReactiveAdapterRegistry ;
27- import org .springframework .core .ReactiveTypeDescriptor ;
28- import org .springframework .data .util .ProxyUtils ;
29- import org .springframework .data .util .ReflectionUtils ;
3021import org .springframework .util .Assert ;
31- import org .springframework .util .ClassUtils ;
32- import org .springframework .util .ConcurrentReferenceHashMap ;
3322
3423/**
3524 * Utility class to expose details about reactive wrapper types. This class exposes whether a reactive wrapper is
5443 * @see io.smallrye.mutiny.Uni
5544 * @see Mono
5645 * @see Flux
46+ * @deprecated since 3.0, use {@link org.springframework.data.util.ReactiveWrappers} instead as the utility was moved
47+ * into the {@code org.springframework.data.util} package.
5748 */
49+ @ Deprecated (since = "3.0" , forRemoval = true )
5850public abstract class ReactiveWrappers {
5951
60- private static final boolean PROJECT_REACTOR_PRESENT = ClassUtils .isPresent ("reactor.core.publisher.Flux" ,
61- ReactiveWrappers .class .getClassLoader ());
62-
63- private static final boolean RXJAVA3_PRESENT = ClassUtils .isPresent ("io.reactivex.rxjava3.core.Flowable" ,
64- ReactiveWrappers .class .getClassLoader ());
65-
66- private static final boolean KOTLIN_COROUTINES_PRESENT = ClassUtils .isPresent ("kotlinx.coroutines.reactor.MonoKt" ,
67- ReactiveWrappers .class .getClassLoader ());
68-
69- private static final boolean MUTINY_PRESENT = ClassUtils .isPresent ("io.smallrye.mutiny.Multi" ,
70- ReactiveWrappers .class .getClassLoader ());
71-
72- private static final Map <Class <?>, Boolean > IS_REACTIVE_TYPE = new ConcurrentReferenceHashMap <>();
73-
74- private static final boolean IS_REACTIVE_AVAILABLE = Arrays .stream (ReactiveLibrary .values ())
75- .anyMatch (ReactiveWrappers ::isAvailable );
76-
7752 private ReactiveWrappers () {}
7853
7954 /**
8055 * Enumeration of supported reactive libraries.
8156 *
8257 * @author Mark Paluch
58+ * @deprecated use {@link org.springframework.data.util.ReactiveWrappers.ReactiveLibrary} instead.
8359 */
60+ @ Deprecated (since = "3.0" , forRemoval = true )
8461 public enum ReactiveLibrary {
8562
8663 PROJECT_REACTOR , RXJAVA3 , KOTLIN_COROUTINES , MUTINY ;
@@ -93,7 +70,7 @@ public enum ReactiveLibrary {
9370 * @return {@literal true} if reactive support is available.
9471 */
9572 public static boolean isAvailable () {
96- return IS_REACTIVE_AVAILABLE ;
73+ return org . springframework . data . util . ReactiveWrappers . isAvailable () ;
9774 }
9875
9976 /**
@@ -108,13 +85,14 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
10885
10986 switch (reactiveLibrary ) {
11087 case PROJECT_REACTOR :
111- return PROJECT_REACTOR_PRESENT ;
88+ return org . springframework . data . util . ReactiveWrappers . PROJECT_REACTOR_PRESENT ;
11289 case RXJAVA3 :
113- return RXJAVA3_PRESENT ;
90+ return org . springframework . data . util . ReactiveWrappers . RXJAVA3_PRESENT ;
11491 case KOTLIN_COROUTINES :
115- return PROJECT_REACTOR_PRESENT && KOTLIN_COROUTINES_PRESENT ;
92+ return org .springframework .data .util .ReactiveWrappers .PROJECT_REACTOR_PRESENT
93+ && org .springframework .data .util .ReactiveWrappers .KOTLIN_COROUTINES_PRESENT ;
11694 case MUTINY :
117- return MUTINY_PRESENT ;
95+ return org . springframework . data . util . ReactiveWrappers . MUTINY_PRESENT ;
11896 default :
11997 throw new IllegalArgumentException (String .format ("Reactive library %s not supported" , reactiveLibrary ));
12098 }
@@ -127,7 +105,7 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
127105 * @return {@literal true} if the {@code type} is a supported reactive wrapper type.
128106 */
129107 public static boolean supports (Class <?> type ) {
130- return isAvailable () && IS_REACTIVE_TYPE . computeIfAbsent ( type , key -> isWrapper ( ProxyUtils . getUserClass ( key )) );
108+ return org . springframework . data . util . ReactiveWrappers . supports ( type );
131109 }
132110
133111 /**
@@ -140,9 +118,7 @@ public static boolean usesReactiveType(Class<?> type) {
140118
141119 Assert .notNull (type , "Type must not be null" );
142120
143- return Arrays .stream (type .getMethods ())//
144- .flatMap (ReflectionUtils ::returnTypeAndParameters )//
145- .anyMatch (ReactiveWrappers ::supports );
121+ return org .springframework .data .util .ReactiveWrappers .usesReactiveType (type );
146122 }
147123
148124 /**
@@ -155,7 +131,7 @@ public static boolean isNoValueType(Class<?> type) {
155131
156132 Assert .notNull (type , "Candidate type must not be null" );
157133
158- return findDescriptor ( type ). map ( ReactiveTypeDescriptor :: isNoValue ). orElse ( false );
134+ return org . springframework . data . util . ReactiveWrappers . isNoValueType ( type );
159135 }
160136
161137 /**
@@ -168,7 +144,7 @@ public static boolean isSingleValueType(Class<?> type) {
168144
169145 Assert .notNull (type , "Candidate type must not be null" );
170146
171- return findDescriptor ( type ). map ( it -> ! it . isMultiValue () && ! it . isNoValue ()). orElse ( false );
147+ return org . springframework . data . util . ReactiveWrappers . isSingleValueType ( type );
172148 }
173149
174150 /**
@@ -183,46 +159,7 @@ public static boolean isMultiValueType(Class<?> type) {
183159
184160 Assert .notNull (type , "Candidate type must not be null" );
185161
186- // Prevent single-types with a multi-hierarchy supertype to be reported as multi type
187- // See Mono implements Publisher
188- return isSingleValueType (type ) ? false
189- : findDescriptor (type ).map (ReactiveTypeDescriptor ::isMultiValue ).orElse (false );
162+ return org .springframework .data .util .ReactiveWrappers .isMultiValueType (type );
190163 }
191164
192- /**
193- * Returns whether the given type is a reactive wrapper type.
194- *
195- * @param type must not be {@literal null}.
196- * @return
197- */
198- private static boolean isWrapper (Class <?> type ) {
199-
200- Assert .notNull (type , "Candidate type must not be null" );
201-
202- return isNoValueType (type ) || isSingleValueType (type ) || isMultiValueType (type );
203- }
204-
205- /**
206- * Looks up a {@link ReactiveTypeDescriptor} for the given wrapper type.
207- *
208- * @param type must not be {@literal null}.
209- * @return
210- */
211- private static Optional <ReactiveTypeDescriptor > findDescriptor (Class <?> type ) {
212-
213- Assert .notNull (type , "Wrapper type must not be null" );
214-
215- ReactiveAdapterRegistry adapterRegistry = ReactiveWrapperConverters .RegistryHolder .REACTIVE_ADAPTER_REGISTRY ;
216-
217- if (adapterRegistry == null ) {
218- return Optional .empty ();
219- }
220-
221- ReactiveAdapter adapter = adapterRegistry .getAdapter (type );
222- if (adapter != null && adapter .getDescriptor ().isDeferred ()) {
223- return Optional .of (adapter .getDescriptor ());
224- }
225-
226- return Optional .empty ();
227- }
228165}
0 commit comments