#JC-1605 Added tests and javadocs. Multiple if-else replaced by switch.