package moe.banana.jsonapi2;

import com.squareup.moshi.JsonQualifier;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

final class AnnotationUtils {

    public static final Set<Annotation> NO_ANNOTATIONS = Collections.emptySet();

    public static Set<? extends Annotation> jsonAnnotations(AnnotatedElement annotatedElement) {
        return jsonAnnotations(annotatedElement.getAnnotations());
    }

    public static Set<? extends Annotation> jsonAnnotations(Annotation[] annotations) {
        Set<Annotation> result = null;
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().isAnnotationPresent(JsonQualifier.class)) {
                if (result == null) result = new LinkedHashSet<>();
                result.add(annotation);
            }
        }
        return result != null ? Collections.unmodifiableSet(result) : NO_ANNOTATIONS;
    }

    public static boolean isAnnotationPresent(
            Set<? extends Annotation> annotations, Class<? extends Annotation> annotationClass) {
        if (annotations.isEmpty()) return false; // Save an iterator in the common case.
        for (Annotation annotation : annotations) {
            if (annotation.annotationType() == annotationClass) return true;
        }
        return false;
    }

    /** Returns true if {@code annotations} has any annotation whose simple name is Nullable. */
    public static boolean hasNullable(Annotation[] annotations) {
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().getSimpleName().equals("Nullable")) {
                return true;
            }
        }
        return false;
    }
}

@@ -109,51 +109,8 @@
 on;%0A
-import java.lang.reflect.AnnotatedElement;%0A
 impo
@@ -135,16 +135,16 @@
 ctions;%0A
+
 import j
@@ -307,179 +307,8 @@
 );%0A%0A
-    public static Set%3C? extends Annotation%3E jsonAnnotations(AnnotatedElement annotatedElement) %7B%0A        return jsonAnnotations(annotatedElement.getAnnotations());%0A    %7D%0A%0A
     
@@ -694,32 +694,32 @@
     %7D%0A        %7D%0A
+
         return r
@@ -797,788 +797,7 @@
    %7D
-%0A%0A    public static boolean isAnnotationPresent(%0A            Set%3C? extends Annotation%3E annotations, Class%3C? extends Annotation%3E annotationClass) %7B%0A        if (annotations.isEmpty()) return false; // Save an iterator in the common case.%0A        for (Annotation annotation : annotations) %7B%0A            if (annotation.annotationType() == annotationClass) return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    /** Returns true if %7B@code annotations%7D has any annotation whose simple name is Nullable. */%0A    public static boolean hasNullable(Annotation%5B%5D annotations) %7B%0A        for (Annotation annotation : annotations) %7B%0A            if (annotation.annotationType().getSimpleName().equals(%22Nullable%22)) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D
 %0A%7D%0A

remove unused utility functions