All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.buschmais.xo.api.metadata.reflection.AbstractAnnotatedElement Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package com.buschmais.xo.api.metadata.reflection;

import java.lang.annotation.Annotation;

/**
 * Abstract base implementation for annotated elements.
 *
 * @param 
 *            The annotated element type.
 */
public abstract class AbstractAnnotatedElement implements AnnotatedElement {

    private final AE annotated;

    /**
     * Constructor.
     *
     * @param annotated
     *            The annotated element.
     */
    protected AbstractAnnotatedElement(AE annotated) {
        this.annotated = annotated;
    }

    @Override
    public AE getAnnotatedElement() {
        return annotated;
    }

    @Override
    public  boolean isAnnotationPresent(Class annotation) {
        return annotated.isAnnotationPresent(annotation);
    }

    @Override
    public  T getAnnotation(Class type) {
        return annotated.getAnnotation(type);
    }

    @Override
    public  T getByMetaAnnotation(Class type) {
        for (Annotation annotation : annotated.getAnnotations()) {
            if (annotation.annotationType().isAnnotationPresent(type)) {
                return (T) annotation;
            }
        }
        return null;
    }

    @Override
    public Annotation[] getAnnotations() {
        return annotated.getDeclaredAnnotations();
    }

    @Override
    public final boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AbstractAnnotatedElement that = (AbstractAnnotatedElement) o;
        return annotated.equals(that.annotated);
    }

    @Override
    public final int hashCode() {
        return annotated.hashCode();
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + "{" + "annotated=" + annotated + '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy