Skip to content

Instantly share code, notes, and snippets.

@chbaranowski
Created October 24, 2010 13:07
Show Gist options
  • Save chbaranowski/643523 to your computer and use it in GitHub Desktop.
Save chbaranowski/643523 to your computer and use it in GitHub Desktop.
TextParser Implementierung - TDD Demo
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