-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] 코드 레벨에서 ActionHandler을 DrawEventAction enum 타입 기반으로 접근할 수 있도록…
… 설정 작성(#40)
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/hyundai/softeer/orange/event/draw/DrawEventConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package hyundai.softeer.orange.event.draw; | ||
|
||
import hyundai.softeer.orange.event.draw.component.score.actionHandler.ActionHandler; | ||
import hyundai.softeer.orange.event.draw.enums.DrawEventAction; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
@Configuration | ||
public class DrawEventConfig { | ||
private static final String NamePattern = "(.+?)_ActionHandler"; | ||
|
||
// actionHandler을 Action 타입으로 가져올 수 있도록 설정 | ||
@Bean(name = "actionHandlerMap") | ||
public Map<DrawEventAction, ActionHandler> actionHandlerMap(Map<String, ActionHandler> handlers) { | ||
Map<DrawEventAction, ActionHandler> actionHandlerMap = new HashMap<>(); | ||
Pattern pattern = Pattern.compile(NamePattern); | ||
|
||
for(var entry: handlers.entrySet()) { | ||
Matcher matcher = pattern.matcher(entry.getKey()); | ||
if (!matcher.find()) throw new RuntimeException("no matched action"); | ||
|
||
String key = matcher.group(1); | ||
ActionHandler actionHandler = entry.getValue(); | ||
|
||
actionHandlerMap.put(DrawEventAction.valueOf(key), actionHandler); | ||
} | ||
// 런타임에 변경 못하게 제한 | ||
return Collections.unmodifiableMap(actionHandlerMap); | ||
} | ||
} |