Skip to content

Commit

Permalink
extract method to make intent clear
Browse files Browse the repository at this point in the history
  • Loading branch information
mklose committed Nov 25, 2011
1 parent bf440cf commit c76bc43
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion java/string_calculator/src/main/java/StringCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ public int add(String s) {

private String[] extractNumbers(String s) {
if (hasCustomSeparator(s))
return split(removeSeparatorDefinition(s),"\n" + s.charAt(2));
return split(removeSeparatorDefinition(s),extractCustomSeparator(s));
return split(s, DEFAULT_SEPARATORS);
}

private String extractCustomSeparator(String s) {
return "\n" + s.charAt(2);
}

private String removeSeparatorDefinition(String s) {
return s.substring(4);
}
Expand Down

0 comments on commit c76bc43

Please sign in to comment.