org.khasanof.collector.DefaultSimpleMethodContext Maven / Gradle / Ivy
Show all versions of spring-boot-starter-fluent Show documentation
package org.khasanof.collector;
import lombok.extern.slf4j.Slf4j;
import org.khasanof.collector.context.SimpleMethodContext;
import org.khasanof.collector.loader.HandlerLoader;
import org.khasanof.collector.method.checker.HandleMethodCheckerMediator;
import org.khasanof.constants.FluentConstants;
import org.khasanof.event.methodContext.MethodCollectedEvent;
import org.khasanof.factories.invoker.method.InvokerMethodFactory;
import org.khasanof.feature.annotation.AnnotationHandler;
import org.khasanof.models.invoker.InvokerParam;
import org.khasanof.models.invoker.SimpleInvoker;
import org.khasanof.service.annotation.handler.AnnotationHandlerService;
import org.springframework.context.ApplicationEventPublisher;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
/**
* The {@link DefaultSimpleMethodContext} class collects the methods from the classes corresponding
* to the {@link org.khasanof.enums.ClassLevelTypes} enum.
*
*
* Author: Nurislom
*
* Date: 18.06.2023
*
* Time: 11:28
*
* Package: org.khasanof.core.collector
*/
@Slf4j
public class DefaultSimpleMethodContext implements SimpleMethodContext {
public static final String NAME = "defaultSimpleMethodContext";
private static final Set IGNORE_METHOD_NAMES = FluentConstants.IGNORE_METHOD_NAMES;
private final HandlerLoader resourceLoader;
private final ApplicationEventPublisher eventPublisher;
private final InvokerMethodFactory invokerMethodFactory;
private final HandleMethodCheckerMediator checkerMediator;
private final AnnotationHandlerService annotationHandlerService;
private final Map> beanMap = new HashMap<>();
public DefaultSimpleMethodContext(HandlerLoader resourceLoader,
HandleMethodCheckerMediator checkerAdapter,
ApplicationEventPublisher eventPublisher,
InvokerMethodFactory invokerMethodFactory,
AnnotationHandlerService annotationHandlerService) {
this.resourceLoader = resourceLoader;
this.checkerMediator = checkerAdapter;
this.eventPublisher = eventPublisher;
this.invokerMethodFactory = invokerMethodFactory;
this.annotationHandlerService = annotationHandlerService;
}
/**
*
* @return
*/
@Override
public Map> findAll() {
return beanMap;
}
/**
*
* @param classes
* @return
*/
@Override
public Optional> find(AnnotationHandler classes) {
return Optional.of(beanMap.getOrDefault(classes, Collections.emptyList()));
}
/**
*
* @param key
* @return
*/
@Override
public boolean contains(AnnotationHandler key) {
return beanMap.containsKey(key);
}
/**
*
*/
@Override
public void assemble() {
log.info("Default Method Context Start");
assembleMethodsInternal();
}
private void assembleMethodsInternal() {
Collection