/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jdbi.v3.core.qualifier;

import static java.util.stream.Collectors.toSet;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;

import org.jdbi.v3.meta.Beta;

/**
 * Utility class for type qualifiers supported by Jdbi core.
 */
@Beta
public class Qualifiers {
    private Qualifiers() {}

    /**
     * Returns the set of qualifying annotations on the given elements.
     * @param elements the annotated elements. Null elements are ignored.
     * @return the set of qualifying annotations on the given elements.
     */
    public static Set<Annotation> getQualifiers(AnnotatedElement... elements) {
        return Arrays.stream(elements)
            .filter(Objects::nonNull)
            .map(AnnotatedElement::getAnnotations)
            .flatMap(Arrays::stream)
            .filter(anno -> anno.annotationType().isAnnotationPresent(Qualifier.class))
            .collect(toSet());
    }
}

@@ -592,58 +592,8 @@
 r;%0A%0A
-import static java.util.stream.Collectors.toSet;%0A%0A
 impo
@@ -748,140 +748,433 @@
 et;%0A
-%0Aimport org.jdbi.v3.meta.Beta;%0A%0A/**%0A * Utility class for type qualifiers supported by Jdbi core.%0A */%0A@Beta%0Apublic class Qualifiers %7B
+import java.util.concurrent.TimeUnit;%0A%0Aimport net.jodah.expiringmap.ExpiringMap;%0Aimport org.jdbi.v3.meta.Beta;%0A%0Aimport static java.util.stream.Collectors.toSet;%0A%0A/**%0A * Utility class for type qualifiers supported by Jdbi core.%0A */%0A@Beta%0Apublic class Qualifiers %7B%0A    private static final ExpiringMap%3CClass%3C?%3E, Set%3CAnnotation%3E%3E ANNOS = ExpiringMap.builder()%0A            .expiration(10, TimeUnit.MINUTES)%0A            .build();%0A
 %0A   
@@ -1802,11 +1802,175 @@
 );%0A    %7D
+%0A%0A    public static Set%3CAnnotation%3E getQualifiers(Class%3C?%3E clazz) %7B%0A        return ANNOS.computeIfAbsent(clazz, x -%3E getQualifiers((AnnotatedElement) clazz));%0A    %7D
 %0A%7D%0A

Add qualifier cache