Java Reflection Annotation getAnnotations(Class annotationClass, Annotation[] annotations)

Here you can find the source of getAnnotations(Class annotationClass, Annotation[] annotations)

Description

get Annotations

License

Open Source License

Declaration

public static List<Annotation> getAnnotations(Class<? extends Annotation> annotationClass,
            Annotation[] annotations) 

Method Source Code

//package com.java2s;
/**************************************************************************************
 * Copyright (C) 2008 EsperTech, Inc. All rights reserved.                            *
 * http://esper.codehaus.org                                                          *
 * http://www.espertech.com                                                           *
 * ---------------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the GPL license       *
 * a copy of which has been included with this distribution in the license.txt file.  *
 **************************************************************************************/

import java.lang.annotation.Annotation;

import java.util.*;

public class Main {
    public static List<Annotation> getAnnotations(Class<? extends Annotation> annotationClass,
            Annotation[] annotations) {
        List<Annotation> result = null;
        for (Annotation annotation : annotations) {
            if (annotation.annotationType() == annotationClass) {
                if (result == null) {
                    result = new ArrayList<Annotation>();
                }//ww  w.  java2 s  .co m
                result.add(annotation);
            }
        }
        if (result == null) {
            return Collections.emptyList();
        }
        return result;
    }
}

Related

  1. getAnnotationRecursive(Class cls, Class annotationClass)
  2. getAnnotations(AnnotatedElement ae, Class annotationType)
  3. getAnnotations(AnnotatedElement annotated)
  4. getAnnotations(Annotation[][] annotations)
  5. getAnnotations(Class cls)
  6. getAnnotations(Class c, Class annotationClass)
  7. getAnnotations(Class annotation, Collection annotations)
  8. getAnnotations(Class ann, Object o, Method m, int param)
  9. getAnnotations(Enum targetEnum, Class targetAnnotationClass)