|
1 | 1 | /* |
2 | | - * Copyright 2016-2021 the original author or authors. |
| 2 | + * Copyright 2016-2022 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
21 | 21 | import java.util.Arrays; |
22 | 22 | import java.util.Collection; |
23 | 23 | import java.util.Collections; |
| 24 | +import java.util.Map; |
24 | 25 | import java.util.Optional; |
25 | 26 |
|
26 | 27 | import org.springframework.core.ReactiveAdapter; |
|
30 | 31 | import org.springframework.data.util.ReflectionUtils; |
31 | 32 | import org.springframework.util.Assert; |
32 | 33 | import org.springframework.util.ClassUtils; |
| 34 | +import org.springframework.util.ConcurrentReferenceHashMap; |
33 | 35 |
|
34 | 36 | /** |
35 | 37 | * Utility class to expose details about reactive wrapper types. This class exposes whether a reactive wrapper is |
@@ -89,6 +91,11 @@ public abstract class ReactiveWrappers { |
89 | 91 | private static final boolean MUTINY_PRESENT = ClassUtils.isPresent("io.smallrye.mutiny.Multi", |
90 | 92 | ReactiveWrappers.class.getClassLoader()); |
91 | 93 |
|
| 94 | + private static final Map<Class<?>, Boolean> IS_REACTIVE_TYPE = new ConcurrentReferenceHashMap<>(); |
| 95 | + |
| 96 | + private static final boolean IS_REACTIVE_AVAILABLE = Arrays.stream(ReactiveLibrary.values()) |
| 97 | + .anyMatch(ReactiveWrappers::isAvailable); |
| 98 | + |
92 | 99 | private ReactiveWrappers() {} |
93 | 100 |
|
94 | 101 | /** |
@@ -120,7 +127,7 @@ public enum ReactiveLibrary { |
120 | 127 | * @return {@literal true} if reactive support is available. |
121 | 128 | */ |
122 | 129 | public static boolean isAvailable() { |
123 | | - return Arrays.stream(ReactiveLibrary.values()).anyMatch(ReactiveWrappers::isAvailable); |
| 130 | + return IS_REACTIVE_AVAILABLE; |
124 | 131 | } |
125 | 132 |
|
126 | 133 | /** |
@@ -158,7 +165,7 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) { |
158 | 165 | * @return {@literal true} if the {@code type} is a supported reactive wrapper type. |
159 | 166 | */ |
160 | 167 | public static boolean supports(Class<?> type) { |
161 | | - return isAvailable() && isWrapper(ProxyUtils.getUserClass(type)); |
| 168 | + return isAvailable() && IS_REACTIVE_TYPE.computeIfAbsent(type, key -> isWrapper(ProxyUtils.getUserClass(key))); |
162 | 169 | } |
163 | 170 |
|
164 | 171 | /** |
|
0 commit comments