From 93a3693299a9211cd1ef33d6099b51e99c5d6bdc Mon Sep 17 00:00:00 2001 From: kevstevie Date: Mon, 25 Sep 2023 15:09:09 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20forEach=20=EA=B5=AC=EB=AC=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../servlet/mvc/tobe/AnnotationHandlerMapping.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMapping.java b/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMapping.java index 6858f3100a..e86afe42aa 100644 --- a/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMapping.java +++ b/mvc/src/main/java/webmvc/org/springframework/web/servlet/mvc/tobe/AnnotationHandlerMapping.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.reflections.Reflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,11 +30,14 @@ public AnnotationHandlerMapping(final Object... basePackage) { public void initialize() { Reflections reflections = new Reflections(basePackage); Set> controllers = reflections.getTypesAnnotatedWith(Controller.class); - for (Class controller : controllers) { - Method[] methods = controller.getMethods(); - Arrays.stream(methods) - .filter(method -> method.isAnnotationPresent(RequestMapping.class)) - .forEach(this::putHandlers); + Set methods = controllers.stream() + .map(Class::getMethods) + .flatMap(Arrays::stream) + .filter(method -> method.isAnnotationPresent(RequestMapping.class)) + .collect(Collectors.toSet()); + + for (Method method : methods) { + putHandlers(method); } log.info("Initialized AnnotationHandlerMapping!"); log.info("handler size: {}", handlerExecutions.size());