-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Step2] 문자열 덧셈 계산기 #1578
Merged
Merged
[Step2] 문자열 덧셈 계산기 #1578
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9b31a09
docs: 문자열 덧셈 계산기 기능요구사항 정의
LenKIM 58b1533
feat: 컴마(,)구분자로 입력한 경우의 테스트 코드 추가
LenKIM ac8b3f6
refactor(Main): 불필요한 사용자 UI 제거
LenKIM b924d06
refactor: 클래스 이름변경(CalculatorModel > AddCalculatorModel)
LenKIM c4424e9
refactor: 메소드(calculate) 추출
LenKIM 9c1ac70
feat: “//”와 “\n” 문자 사이에 커스텀 구분자 관련 테스트 코드 추가
LenKIM d2f3cbe
refactor: 메소드 시그니쳐 변수명 변경
LenKIM 172a6b4
refactor: polishing inline variable
LenKIM fb6735a
refactor: 테스트 코드 간결하게 수정
LenKIM 841340f
style: 불필요한 개행 문자 제거
LenKIM 7091907
refactor:코드 피드백 반영
LenKIM File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package calculator; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public final class CustomDelimiterMatcher { | ||
|
||
private final Matcher matcher; | ||
private final static Pattern CUSTOM_DELIMITER_PATTERN = Pattern.compile("//(.)\n(.*)"); | ||
|
||
private CustomDelimiterMatcher(Matcher matcher) { | ||
requireNonNull(matcher); | ||
this.matcher = matcher; | ||
} | ||
|
||
public static String[] getSplitTokens(String userInput) { | ||
Matcher matcher = new CustomDelimiterMatcher(CUSTOM_DELIMITER_PATTERN.matcher(userInput)).matcher; | ||
if (matcher.find() == false) { | ||
throw new RuntimeException("커스텀 구분자를 찾을 수 없습니다"); | ||
} | ||
String delimiter = matcher.group(1); | ||
String group = matcher.group(2); | ||
return group.split(delimiter); | ||
} | ||
|
||
public static boolean hasDelimiter(String userInput) { | ||
return CUSTOM_DELIMITER_PATTERN.asPredicate().test(userInput); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,14 @@ | ||
package calculator; | ||
|
||
public final class NumberUtils { | ||
import java.util.regex.Pattern; | ||
|
||
public static String[] requireNumber(String[] strings) { | ||
for (String s : strings) { | ||
requireNumber(s); | ||
} | ||
return strings; | ||
} | ||
public final class NumberUtils { | ||
|
||
public static String requireNumber(String string) { | ||
for (char aChar : string.toCharArray()) { | ||
requireNumber(aChar); | ||
} | ||
return string; | ||
} | ||
private static final Pattern numberPattern = Pattern.compile("[0-9]*"); | ||
|
||
public static void requireNumber(char aChar) { | ||
if (aChar == '-' || Character.isAlphabetic(aChar)) { | ||
throw new RuntimeException(); | ||
public static void validateString(String string) { | ||
if (numberPattern.matcher(string).matches() == false) { | ||
throw new IllegalArgumentException("유효하지 않은 숫자가 사용되었습니다."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package calculator; | ||
|
||
import static calculator.NumberUtils.*; | ||
import static java.util.Objects.*; | ||
|
||
public final class StringUtils { | ||
|
||
public static String[] getSplit(String s, String regex) { | ||
return s.split(regex); | ||
} | ||
|
||
public static boolean isBlank(String s) { | ||
return isNull(s) || s.equals(""); | ||
} | ||
|
||
static Long[] convertStringToLong(String[] strings) { | ||
Long[] result = new Long[strings.length]; | ||
for (int i = 0; i < strings.length; i++) { | ||
String value = strings[i]; | ||
validateString(value); | ||
result[i] = Long.parseLong(value); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금과 같은 복잡도에서는 크게 상관은 없겠지만
List
등을 활용하면 어떨까요?List
에서 제공하는 내장 함수나 Stream을 활용하면 좋을 것 같네요.다음 단계부터는 배열의 사용을 지양하고
List
를 사용해보시면 좋을 것 같습니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 👍 피드백 감사합니다.