Skip to content

Commit

Permalink
Extracted condtion to method
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Dziemidowicz committed Nov 24, 2011
1 parent 9e9ef1c commit 355aad8
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 @@ -3,7 +3,7 @@ public int add(String s) {
if (s.isEmpty()) {
return 0;
}
if (s.startsWith("//")) {
if (hasCustomSeparator(s)) {
int returnValue = 0;
for (String n : s.substring(4).split("[\n"+ s.charAt(2) +"]")) {
returnValue += Integer.parseInt(n);
Expand All @@ -17,4 +17,8 @@ public int add(String s) {
return r;
}
}

private boolean hasCustomSeparator(String s) {
return s.startsWith("//");
}
}

0 comments on commit 355aad8

Please sign in to comment.