-
Notifications
You must be signed in to change notification settings - Fork 0
Stream API #3
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
base: master
Are you sure you want to change the base?
Stream API #3
Conversation
StreamAPI/src/WordCounter.java
Outdated
|
|
||
| private Map<String, Integer> count() throws IOException { | ||
|
|
||
| return Arrays.stream(Files.readAllLines(file.toPath()).stream() // список строк |
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.
Вот это мне не нравится. Ты, получается, весь файл грузишь в память. А если это дамп википедии? Используй Files.lines и сделай единый стрим, без этого вложенного
StreamAPI/src/WordCounter.java
Outdated
| } else { | ||
| previous.put(next, 1); | ||
| private static Map<String, Integer> MyAccumulator(Map<String, Integer> previous, List<String> next) { | ||
| for (String word : next) { |
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.
Не, так не интересно. Сделай без цикла тут.
StreamAPI/src/WordCounter.java
Outdated
| private static Map<String, Integer> MyAccumulator(Map<String, Integer> previous, List<String> next) { | ||
|
|
||
| return WordCounter.MyCombiner(previous, next.stream().filter((w) -> w.length() > 0) | ||
| .collect(Collectors.groupingBy(String::toLowerCase, Collectors.summingInt((w) -> 1)))); |
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.
Да не должен accumulator выполнять такую сложную работу. Верни фильтрацию и преобразование к нижнему регистру назад в основной стрим.
No description provided.