Conversation
| @RequiredArgsConstructor | ||
| public class AllApplicantCnt { | ||
|
|
||
| // private final String generation; | ||
| // | ||
| // private final Integer cnt; | ||
| // | ||
| // public static AllApplicantCnt of(String generation, Integer cnt){ | ||
| // return new AllApplicantCnt(generation, cnt); | ||
| // } | ||
|
|
||
| } |
There was a problem hiding this comment.
주석으로 가득찬 코드? 그냥 지우세요 ㅋㅋ 추상 클래스로 선언해둬도 되구요.
| private final Integer cnt; | ||
|
|
||
| private final Map<String, Integer> hopeFieldCnt; | ||
|
|
||
| private final Map<String, Integer> majorCnt; | ||
|
|
||
| private final Map<String, Integer> pathCnt; | ||
|
|
||
| // 이게 난관이네 | ||
| private final DesiredTimeStatistics desiredTimes; |
There was a problem hiding this comment.
이렇게 선언할 경우 나중에 캐시나 DB에 최신 데이터를 저장하게 될경우
@transient를 사용해서 일부 필드를 제외하거나, JSON String Serialize 를 하게 될 경우 @JsonIgnore를 사용할 수 있습니다. 이 점 인지하고 넘어갑시다.
| List<int[]> desiredTime = times.getDesiredTime(); | ||
| for (int i = 0; i < 3; i++) { | ||
| List<Integer> tmp = new ArrayList<>(); | ||
| int[] targetArr = desiredTime.get(i); | ||
| for (int j = 0; j < desiredTime.size(); i++) { | ||
| if (targetArr[j] == 1) tmp.add(j); | ||
| } | ||
| DesiredTimeStatistics.put(tmp,times.getRegistrationId()); |
There was a problem hiding this comment.
stream 필드 내에서 for문을 쓰는 것은 패러다임의 불일치입니다. 함수형과 절차지향의 짬뽕이랄까요.
최대한 stream을 사용했다면 stream 클래스의 메소드만 사용해서 구성하세요.
There was a problem hiding this comment.
람다의 매개변수로 times를 주셨는데 stream을 사용했을 때 스트림 원소는 List 이아니라 DesiredTime 객체 1개입니다. 따라서 times보다는 time이 의미에 맞을 것 같네요
There was a problem hiding this comment.
그리고 desiredTime이 List<int[]> 이라서 내부에서 for문을 이렇게 사용한 것 같은데 flatMap을 사용해서 List<Integer>로 바꾸고 원하는 작업을 stream으로 하면 더 좋을 것 같네요
| s -> s, // 키는 희망 분야 그대로 | ||
| Collectors.mapping( | ||
| s -> 1, // 희망 분야를 1로 변경 | ||
| Collectors.reducing(0, (i,j)->i+j) // 누적 |
There was a problem hiding this comment.
(i,j) -> i+j 는 Integer::sum 으로 변경할 수 있습니다. 훨씬 의미가 잘 전달되겠죠?
No description provided.