11/*
2- * Copyright 2016-2021 the original author or authors.
2+ * Copyright 2016-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1919import reactor .core .publisher .Mono ;
2020
2121import java .util .Arrays ;
22+ import java .util .Collection ;
23+ import java .util .Collections ;
24+ import java .util .Map ;
2225import java .util .Optional ;
2326
2427import org .springframework .core .ReactiveTypeDescriptor ;
2528import org .springframework .data .util .ProxyUtils ;
2629import org .springframework .data .util .ReflectionUtils ;
2730import org .springframework .util .Assert ;
2831import org .springframework .util .ClassUtils ;
32+ import org .springframework .util .ConcurrentReferenceHashMap ;
2933
3034/**
3135 * Utility class to expose details about reactive wrapper types. This class exposes whether a reactive wrapper is
@@ -65,6 +69,11 @@ public abstract class ReactiveWrappers {
6569 private static final boolean MUTINY_PRESENT = ClassUtils .isPresent ("io.smallrye.mutiny.Multi" ,
6670 ReactiveWrappers .class .getClassLoader ());
6771
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+
6877 private ReactiveWrappers () {}
6978
7079 /**
@@ -84,7 +93,7 @@ public enum ReactiveLibrary {
8493 * @return {@literal true} if reactive support is available.
8594 */
8695 public static boolean isAvailable () {
87- return Arrays . stream ( ReactiveLibrary . values ()). anyMatch ( ReactiveWrappers :: isAvailable ) ;
96+ return IS_REACTIVE_AVAILABLE ;
8897 }
8998
9099 /**
@@ -118,7 +127,7 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
118127 * @return {@literal true} if the {@code type} is a supported reactive wrapper type.
119128 */
120129 public static boolean supports (Class <?> type ) {
121- return isAvailable () && isWrapper (ProxyUtils .getUserClass (type ));
130+ return isAvailable () && IS_REACTIVE_TYPE . computeIfAbsent ( type , key -> isWrapper (ProxyUtils .getUserClass (key ) ));
122131 }
123132
124133 /**
0 commit comments