Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Our EVIL code has turned into an angel
* We now have a small and maintanable code
class Angel {
// Get rid of old switch-case/if-else ladder
// Replace it with a sweet map
HashMap<String, CaseConverter> converters =
(HashMap<String, CaseConverter>)
"lower", new LowerConverter(),
"camel", new CamelConverter()
public String changeCase(String caseType, String... words) {
// We support lower and camel cases
// Sanitize the user input
caseType = caseType
// Lookup which converter the user wants
CaseConverter converter = converters.get(caseType);
if (converter!=null)
return converter.convert(words);
return null;
public static void main(String[] args) {
Angel obj = new Angel();
String output = obj.changeCase("camel", "This", "Word");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment