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

Add Feature: #293 Add implementation to TextProcessorJDK.topLetters()… #319

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand All @@ -40,13 +41,16 @@ public List<Map.Entry<Character, Long>> topLetters()
// TODO: of Character objects to their counts
// Hint: Look at IntStream's filter, map, mapToObject, collect methods
// Hint: Also loo at Collectors.groupingBy, Collectors.counting
Map<Character, Long> chars = null;
Map<Character, Long> chars = this.getHaikuAsChars().filter(Character::isLetter)
.mapToObj(i -> Character.toLowerCase((char) i)).collect(Collectors.groupingBy(c -> c, Collectors.counting()));

// TODO: Sort the entries in the Map by their values in reverseOrder
// TODO: Take the top three entries and convert them to a List
// Hint: Look at entrySet, stream, sorted, Map.Entry.comparingByValue, Comparator.reverseOrder()
// Hint: On Stream look at limit and toList.
return null;


return chars.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).limit(3).collect(Collectors.toList());
prathasirisha marked this conversation as resolved.
Show resolved Hide resolved
}

public String distinctLetters()
Expand Down