-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5단계 - 자동차 경주(리팩토링) #6079
5단계 - 자동차 경주(리팩토링) #6079
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전에 view를 이미 잘 분리해주셔서 5단계에서는 그리 큰 변화가 있진 않았던것 같네요~!
그동안 고생하셨습니다.
merge하겠습니다. 🚀
public class Winners { | ||
public static List<String> findWinners(List<GameRound> cars) { | ||
List<Car> finalRound = cars.get(cars.size() - 1).getRound(); | ||
return filterWinners(finalRound, findMaxPosition(finalRound)); | ||
} | ||
|
||
private static List<String> filterWinners(List<Car> cars, int maxPosition) { | ||
return cars.stream() | ||
.filter(car -> car.isSamePosition(maxPosition)) | ||
.map(Car::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static int findMaxPosition(List<Car> cars) { | ||
int maxPosition = 0; | ||
for (Car car : cars) { | ||
maxPosition = car.max(maxPosition); | ||
} | ||
return maxPosition; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Winner가 GameRound를 다루는 static한 함수만 가지고 있을게 아니라
일급컬렉션으로 설계해보면 더 좋을것 같습니다. :)
for (GameRound round : result) { | ||
for (Car car : round.getRound()) { | ||
System.out.println(car.getName() + " : " + "-".repeat(car.getPosition())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depth가 2인것 같네요~!
안녕하세요. get 함수를 줄이려고 해봤는데 생각보다 쉽지 않네요.,,
항상 꼼꼼한 리뷰해주셔서 감사합니다 🙇♂️🥹