Skip to content

Conversation

@nrsxx
Copy link
Owner

@nrsxx nrsxx commented Apr 27, 2017

No description provided.


private Map<String, Integer> count() throws IOException {

return Arrays.stream(Files.readAllLines(file.toPath()).stream() // список строк

Choose a reason for hiding this comment

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

Вот это мне не нравится. Ты, получается, весь файл грузишь в память. А если это дамп википедии? Используй Files.lines и сделай единый стрим, без этого вложенного

} else {
previous.put(next, 1);
private static Map<String, Integer> MyAccumulator(Map<String, Integer> previous, List<String> next) {
for (String word : next) {
Copy link

@DanAnastasyev DanAnastasyev Apr 27, 2017

Choose a reason for hiding this comment

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

Не, так не интересно. Сделай без цикла тут.

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))));

Choose a reason for hiding this comment

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

Да не должен accumulator выполнять такую сложную работу. Верни фильтрацию и преобразование к нижнему регистру назад в основной стрим.

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.

3 participants