Created
October 24, 2010 13:07
-
-
Save chbaranowski/643523 to your computer and use it in GitHub Desktop.
TextParser Implementierung - TDD Demo
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
import java.util.HashMap; | |
import java.util.Map; | |
public class TextParser { | |
public Map<String, Integer> parseTextWordCount(String text) { | |
HashMap<String, Integer> result = new HashMap<String, Integer>(); | |
if(text != null) | |
{ | |
if(!text.trim().isEmpty()) | |
{ | |
String[] words = text.split(" "); | |
for (String word : words) { | |
word = word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase(); | |
if(result.containsKey(word)) | |
result.put(word, result.get(word)+1); | |
else | |
result.put(word, 1); | |
} | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment