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

com.cmeza.spring.ioc.handler.metadata.impl.AbstractMetadata Maven / Gradle / Ivy

The newest version!
package com.cmeza.spring.ioc.handler.metadata.impl;

import com.cmeza.spring.ioc.handler.metadata.AnnotationMetadata;
import com.cmeza.spring.ioc.handler.metadata.Metadata;
import lombok.Data;

import java.lang.annotation.Annotation;
import java.util.*;

@Data
@SuppressWarnings("unchecked")
public class AbstractMetadata implements Metadata {

    private final Map attributes = new LinkedHashMap<>();
    private final List> annotations = new LinkedList<>();
    private final Map, Annotation> processorsResult = new LinkedHashMap<>();
    private String name;

    @Override
    public  T getAttribute(String key, Class clazz) {
        return (T)attributes.get(key);
    }

    @Override
    public  T getAttribute(String key, Class clazz, T defaultValue) {
        T result = getAttribute(key, clazz);
        return Objects.isNull(result) ? defaultValue : result;
    }

    @Override
    public boolean hasAttribute(String key) {
        return Objects.nonNull(attributes.get(key));
    }

    @Override
    public  AnnotationMetadata getAnnotation(Class clazz) {
        return (AnnotationMetadata) annotations.stream().filter(ann -> ann.getAnnotation().annotationType().isAssignableFrom(clazz)).findAny().orElse(null);
    }


    @Override
    public  T getProcessorResult(Class annotationClass) {
        return (T) processorsResult.get(annotationClass);
    }

    @Override
    public Metadata addAttribute(String key, Object value) {
        attributes.put(key, value);
        return this;
    }

    public  Metadata addAnnotation(AnnotationMetadata annotationMetadata) {
        annotations.add(annotationMetadata);
        return this;
    }

    public Metadata addProcessorResult(Class annotationType, Annotation process) {
        this.processorsResult.put(annotationType, process);
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy