Skip to content

Commit

Permalink
refactor: findUpdateLogic 메서드에서 contains()의 반복된 코드를 없애기 위해 이름에 포함된 it…
Browse files Browse the repository at this point in the history
…em의 종류를 매핑해주는 itemMap과 반복문을 사용하여 변경
  • Loading branch information
hades3 committed Oct 9, 2024
1 parent a242d08 commit b1df8d7
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

public class UpdateLogicFactory {
private final Map<ItemCategory, UpdateLogic> updateLogicMap;
private final Map<String, ItemCategory> itemMap;

public UpdateLogicFactory() {
updateLogicMap = new HashMap<>();
itemMap = Map.ofEntries(Map.entry("Aged Brie", BRIE), Map.entry("Backstage passes", PASS),
Map.entry("Conjured", CONJURED), Map.entry("Sulfuras", SULFURAS));

updateLogicMap.put(BRIE, new BrieUpdateLogic());
updateLogicMap.put(PASS, new PassesUpdateLogic());
Expand All @@ -19,15 +22,11 @@ public UpdateLogicFactory() {
}

public UpdateLogic findUpdateLogic(String name) {
if (name.contains("Aged Brie")) {
return updateLogicMap.get(BRIE);
} else if (name.contains("Backstage passes")) {
return updateLogicMap.get(PASS);
} else if (name.contains("Conjured")) {
return updateLogicMap.get(CONJURED);
} else if (name.contains("Sulfuras")) {
return updateLogicMap.get(SULFURAS);
} else
return updateLogicMap.get(ELSE);
for (String key : itemMap.keySet()) {
if (name.contains(key)) {
return updateLogicMap.get(itemMap.get(key));
}
}
return updateLogicMap.get(ELSE);
}
}

0 comments on commit b1df8d7

Please sign in to comment.