-
Notifications
You must be signed in to change notification settings - Fork 1
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
#344 [fix] 규칙 메인 조회에서 대표 규칙 여부 함께 전달하도록 수정 #346
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.
감사함니다!!
public static RulesResponse of(List<Rule> rules, LocalDateTime now) { | ||
List<RuleInfo> sortedRuleInfo = rules.stream() | ||
.sorted(Rule::compareTo) | ||
.map(rule -> RuleInfo.of(rule, now)).collect(Collectors.toList()); | ||
|
||
Map<Boolean, List<RuleInfo>> ruleInfoMap = sortedRuleInfo.stream() | ||
.collect(Collectors.partitioningBy(RuleInfo::isRepresent)); | ||
|
||
List<RuleInfo> representRuleInfo = ruleInfoMap.get(true); | ||
List<RuleInfo> nonRepresentRuleInfo = ruleInfoMap.get(false); | ||
|
||
return RulesResponse.builder() | ||
.rules(rules.stream() | ||
.sorted(Rule::compareTo) | ||
.map(rule -> RuleInfo.of(rule, now)).collect(Collectors.toList())) | ||
.rules(Stream.concat(representRuleInfo.stream(), nonRepresentRuleInfo.stream()) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} |
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.
오홍.. 처음보는 메서드들이 많네요! 신기합니당..
이 방식도 좋은데 아래와 같이 하면 코드 라인수를 좀 줄일 수 있을 것 같아서 의견 내봅니당!!
public static RulesResponse of(List<Rule> rules, LocalDateTime now) {
return RulesResponse.builder()
.rules(rules.stream()
.sorted(Rule::compareTo)
.map(rule -> RuleInfo.of(rule, now))
.collect(Collectors.toList())
.stream()
.sorted(Comparator.comparing(RuleInfo::isRepresent).reversed())
.collect(Collectors.toList()))
.build();
}
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.
오 stream 을 이을 생각은 못했네요.. 좋습니당
✒️ 관련 이슈번호
🔑 Key Changes
📢 To Reviewers