Skip to content
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

Merged
merged 6 commits into from
Mar 22, 2025
Merged

Conversation

heewonham
Copy link

안녕하세요. get 함수를 줄이려고 해봤는데 생각보다 쉽지 않네요.,,
항상 꼼꼼한 리뷰해주셔서 감사합니다 🙇‍♂️🥹

Copy link

@pci2676 pci2676 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전에 view를 이미 잘 분리해주셔서 5단계에서는 그리 큰 변화가 있진 않았던것 같네요~!

그동안 고생하셨습니다.

merge하겠습니다. 🚀

Comment on lines +6 to +25
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;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Winner가 GameRound를 다루는 static한 함수만 가지고 있을게 아니라

일급컬렉션으로 설계해보면 더 좋을것 같습니다. :)

Comment on lines +17 to +19
for (GameRound round : result) {
for (Car car : round.getRound()) {
System.out.println(car.getName() + " : " + "-".repeat(car.getPosition()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depth가 2인것 같네요~!

@pci2676 pci2676 merged commit c12dc38 into next-step:heewonham Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants