Skip to content

Commit

Permalink
Merge pull request eclipse#319 from sakshi35/master
Browse files Browse the repository at this point in the history
Add Feature: eclipse#293 Add implementation to TextProcessorJDK.topLetters()…
  • Loading branch information
prathasirisha committed Sep 22, 2023
2 parents dddecf5 + 21fe330 commit 0152f62
Showing 1 changed file with 6 additions and 2 deletions.
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());
}

public String distinctLetters()
Expand Down

0 comments on commit 0152f62

Please sign in to comment.