Skip to content

Commit 8cd82a8

Browse files
committed
DATACMNS-836 - Expose ReactiveWrappers.isAvailable() and .supports() methods.
1 parent 1b53ce9 commit 8cd82a8

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

src/main/java/org/springframework/data/repository/query/ReactiveWrappers.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,37 +97,55 @@ public class ReactiveWrappers {
9797
}
9898

9999
/**
100-
* Returns {@literal true} if {@code theClass} is a reactive wrapper type for single element emission.
100+
* Returns {@literal true} if reactive support is available. More specifically, whether RxJava1/2 or Project Reactor
101+
* libraries are on the class path.
101102
*
102-
* @param theClass must not be {@literal null}.
103-
* @return {@literal true} if {@code theClass} is a reactive wrapper type for single element emission
103+
* @return {@literal true} if reactive support is available.
104104
*/
105-
public static boolean isSingleType(Class<?> theClass) {
105+
public static boolean isAvailable() {
106+
return RXJAVA1_PRESENT || RXJAVA2_PRESENT || PROJECT_REACTOR_PRESENT;
107+
}
108+
109+
/**
110+
* Returns {@literal true} if the {@code type} is a supported reactive wrapper type.
111+
*
112+
* @param type must not be {@literal null}.
113+
* @return {@literal true} if the {@code type} is a supported reactive wrapper type.
114+
*/
115+
public static boolean supports(Class<?> type) {
116+
return isSingleType(type) || isMultiType(type);
117+
}
118+
119+
/**
120+
* Returns {@literal true} if {@code type} is a reactive wrapper type for single element emission.
121+
*
122+
* @param type must not be {@literal null}.
123+
* @return {@literal true} if {@code type} is a reactive wrapper type for single element emission
124+
*/
125+
public static boolean isSingleType(Class<?> type) {
106126

107-
Assert.notNull(theClass, "Class type must not be null!");
127+
Assert.notNull(type, "Class type must not be null!");
108128

109-
return isAssignable(SINGLE_TYPES, theClass);
129+
return isAssignable(SINGLE_TYPES, type);
110130
}
111131

112132
/**
113-
* Returns {@literal true} if {@code theClass} is a reactive wrapper type supporting emission of {@code 0..N}
114-
* elements.
133+
* Returns {@literal true} if {@code type} is a reactive wrapper type supporting emission of {@code 0..N} elements.
115134
*
116-
* @param theClass must not be {@literal null}.
117-
* @return {@literal true} if {@code theClass} is a reactive wrapper type supporting emission of {@code 0..N}
118-
* elements.
135+
* @param type must not be {@literal null}.
136+
* @return {@literal true} if {@code type} is a reactive wrapper type supporting emission of {@code 0..N} elements.
119137
*/
120-
public static boolean isMultiType(Class<?> theClass) {
138+
public static boolean isMultiType(Class<?> type) {
121139

122-
Assert.notNull(theClass, "Class type must not be null!");
140+
Assert.notNull(type, "Class type must not be null!");
123141

124142
// Prevent single-types with a multi-hierarchy supertype to be reported as multi type
125143
// See Mono implements Publisher
126-
if (isSingleType(theClass)) {
144+
if (isSingleType(type)) {
127145
return false;
128146
}
129147

130-
return isAssignable(MULTI_TYPES, theClass);
148+
return isAssignable(MULTI_TYPES, type);
131149
}
132150

133151
private static boolean isAssignable(Iterable<Class<?>> lhsTypes, Class<?> rhsType) {

0 commit comments

Comments
 (0)