Skip to content

Commit 7941374

Browse files
committed
refactor: 스트링 배열을 불변 컬렉션 리스트 타입으로 반환하도록 수정
1 parent 501aec9 commit 7941374

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/calculator/StringAddCalculator.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package calculator;
22

3+
import java.util.List;
34
import java.util.regex.Matcher;
45
import java.util.regex.Pattern;
56

@@ -15,22 +16,22 @@ public static int splitAndSum(String text) {
1516
return 0;
1617
}
1718

18-
String[] tokens = splitIntoTokens(text);
19+
List<String> tokens = splitIntoTokens(text);
1920
return sumPositiveNumbersOrThrow(tokens);
2021
}
2122

22-
private static String[] splitIntoTokens(String text) {
23+
private static List<String> splitIntoTokens(String text) {
2324
Matcher matcher = CUSTOM_DELIMITER_PARSE_PATTERN.matcher(text);
2425

2526
if (matcher.find()) {
2627
String customDelimiter = Pattern.quote(matcher.group(1));
27-
return matcher.group(2).split(customDelimiter);
28+
return List.of(matcher.group(2).split(customDelimiter));
2829
}
2930

30-
return DEFAULT_DELIMITERS_PATTERN.split(text);
31+
return List.of(DEFAULT_DELIMITERS_PATTERN.split(text));
3132
}
3233

33-
private static int sumPositiveNumbersOrThrow(String[] tokens) {
34+
private static int sumPositiveNumbersOrThrow(List<String> tokens) {
3435
int sum = 0;
3536
for (String token : tokens) {
3637
if (!isValidInteger(token)) {

0 commit comments

Comments
 (0)