Created
February 29, 2020 09:08
-
-
Save BartoszDabek/6e3994e8c4358e608c3f891aaeffaa8f to your computer and use it in GitHub Desktop.
TDD - recruitment task implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FrequencyImpl implements Frequency { | |
@Override | |
public Map<Character, Double> analyze(String text) { | |
if (text == null) { | |
throw new IllegalArgumentException(); | |
} | |
text = text.toLowerCase(); | |
Map<Character, Double> characterFrequency = new HashMap<>(); | |
long distintChars = text.chars().distinct().count(); | |
for (Character character: text.toCharArray()) { | |
characterFrequency.putIfAbsent(character, 1.0 / distintChars); | |
} | |
return characterFrequency; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment