From 1656366871750c759f27ea339ec4e220a9a72df3 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 15:58:38 +0900 Subject: [PATCH 01/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=A0=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd90ef0247..166245fc08 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ -# java-calculator-precourse \ No newline at end of file +# java-calculator-precourse + +## 기능 요구사항 +입력한 문자열에서 숫자를 추출하여 더하는 계산기를 구현한다. + +쉼표(,) 또는 콜론(:)을 구분자로 가지는 문자열을 전달하는 경우 구분자를 기준으로 분리한 각 숫자의 합을 반환한다.
+예: "" => 0, "1,2" => 3, "1,2,3" => 6, "1,2:3" => 6
+앞의 기본 구분자(쉼표, 콜론) 외에 커스텀 구분자를 지정할 수 있다.
+커스텀 구분자는 문자열 앞부분의 "//"와 "\n" 사이에 위치하는 문자를 커스텀 구분자로 사용한다.
+ +예를 들어 `"//;\n1;2;3"`과 같이 값을 입력할 경우 커스텀 구분자는 세미콜론(;)이며, 결과 값은 `6`이 반환되어야 한다.
+사용자가 잘못된 값을 입력할 경우 `IllegalArgumentException`을 발생시킨 후 애플리케이션은 종료되어야 한다. + +- 입력 : 구분자와 양수로 구성된 문자열
+- 출력 : 덧셈 결과 + +### 라이브러리
+`camp.nextstep.edu.missionutils`에서 제공하는 Console API를 사용하여 구현해야 한다.
+사용자가 입력하는 값은 `camp.nextstep.edu.missionutils.Console`의 `readLine()`을 활용한다. +## 기능 목록 + +- [ ] 문자열 입력받기 + - [ ] 입력 클래스 분리 + - [ ] 문자열 입력 문구 출력 + - [ ] 라이브러리를 이용한 문자열 입력 +- [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 + - [ ] 문자열 분석 클래스 분리 + - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 + - [ ] 커스텀 구분자 분리 + - [ ] 숫자만 분리된 리스트 반환 +- [ ] 숫자 덧셈 + - [ ] 계산 클래스 분리 + - [ ] 구분자를 비교하여 숫자 덧셈 구현 +- [ ] 예외 처리 + - [ ] 예외 클래스 분리 +- [ ] 결과 반환 \ No newline at end of file From bac710f4108bcf8cb2665545a14e1e3e3b28d2f7 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:18:15 +0900 Subject: [PATCH 02/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 166245fc08..2683db842f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ - [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 - [ ] 문자열 분석 클래스 분리 - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 + - [ ] 구분 인덱스 enum으로 관리 - [ ] 커스텀 구분자 분리 - [ ] 숫자만 분리된 리스트 반환 - [ ] 숫자 덧셈 From 420bc6bbbce1ee3254131dc94f67b5493db9ce86 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:19:50 +0900 Subject: [PATCH 03/35] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/input/InputHandler.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/input/InputHandler.java diff --git a/src/main/java/input/InputHandler.java b/src/main/java/input/InputHandler.java new file mode 100644 index 0000000000..e4809323ed --- /dev/null +++ b/src/main/java/input/InputHandler.java @@ -0,0 +1,4 @@ +package input; + +public class InputHandler { +} From d819ad3d1084d458f5b1ec76a11d0049a31789e6 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:21:25 +0900 Subject: [PATCH 04/35] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EB=B0=9B=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- src/main/java/input/InputHandler.java | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2683db842f..9a8a0d5e52 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,10 @@ 사용자가 입력하는 값은 `camp.nextstep.edu.missionutils.Console`의 `readLine()`을 활용한다. ## 기능 목록 -- [ ] 문자열 입력받기 - - [ ] 입력 클래스 분리 - - [ ] 문자열 입력 문구 출력 - - [ ] 라이브러리를 이용한 문자열 입력 +- [x] 문자열 입력받기 + - [x] 입력 클래스 분리 + - [x] 문자열 입력 문구 출력 + - [x] 라이브러리를 이용한 문자열 입력 - [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 - [ ] 문자열 분석 클래스 분리 - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 diff --git a/src/main/java/input/InputHandler.java b/src/main/java/input/InputHandler.java index e4809323ed..85c6eb012d 100644 --- a/src/main/java/input/InputHandler.java +++ b/src/main/java/input/InputHandler.java @@ -1,4 +1,11 @@ package input; +import camp.nextstep.edu.missionutils.Console; + public class InputHandler { + + public String getInput() { + System.out.println("문자열을 입력해주세요"); + return Console.readLine(); + } } From 0274d6190dc5acb3330d6c113ff5aa4b42b699bc Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:28:02 +0900 Subject: [PATCH 05/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9a8a0d5e52..022b220558 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,12 @@ - [x] 문자열 입력 문구 출력 - [x] 라이브러리를 이용한 문자열 입력 - [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 - - [ ] 문자열 분석 클래스 분리 - - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 + - [ ] 문자열 분석 클래스 분리 + - [ ] 구분자 분리 + - [ ] 커스텀 구분자 분리 + - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 - [ ] 구분 인덱스 enum으로 관리 - - [ ] 커스텀 구분자 분리 - - [ ] 숫자만 분리된 리스트 반환 + - [ ] 커스텀 구분자 구문 삭제 로직 구현 - [ ] 숫자 덧셈 - [ ] 계산 클래스 분리 - [ ] 구분자를 비교하여 숫자 덧셈 구현 From c77d5ad21fcad9ab33cabdea8aa04ef4f3db258e Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:29:49 +0900 Subject: [PATCH 06/35] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EB=B6=84=EC=84=9D=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/parser/Delimiter.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/parser/Delimiter.java diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java new file mode 100644 index 0000000000..fd9d961178 --- /dev/null +++ b/src/main/java/parser/Delimiter.java @@ -0,0 +1,4 @@ +package parser; + +public class Delimiter { +} From 603ec684abfa67fc05e35586f2d9c960d5df7be1 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:30:09 +0900 Subject: [PATCH 07/35] =?UTF-8?q?Revert=20"feat:=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=20=EB=B6=84=EC=84=9D=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c77d5ad21fcad9ab33cabdea8aa04ef4f3db258e. --- src/main/java/parser/Delimiter.java | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/main/java/parser/Delimiter.java diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java deleted file mode 100644 index fd9d961178..0000000000 --- a/src/main/java/parser/Delimiter.java +++ /dev/null @@ -1,4 +0,0 @@ -package parser; - -public class Delimiter { -} From cb34140645e61d4d6efb9fc2d37d2772d425ea32 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:31:21 +0900 Subject: [PATCH 08/35] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EB=B6=84=EC=84=9D=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/parser/Delimiter.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/main/java/parser/Delimiter.java diff --git a/README.md b/README.md index 022b220558..82cf538e93 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ - [x] 문자열 입력 문구 출력 - [x] 라이브러리를 이용한 문자열 입력 - [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 - - [ ] 문자열 분석 클래스 분리 + - [x] 문자열 분석 클래스 분리 - [ ] 구분자 분리 - [ ] 커스텀 구분자 분리 - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java new file mode 100644 index 0000000000..fd9d961178 --- /dev/null +++ b/src/main/java/parser/Delimiter.java @@ -0,0 +1,4 @@ +package parser; + +public class Delimiter { +} From 591d2694dd77634a1454a8bb9e839c53d27fb0b0 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:32:13 +0900 Subject: [PATCH 09/35] =?UTF-8?q?feat:=20=EC=BB=A4=EC=8A=A4=ED=85=80=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84=EC=9E=90=20=EB=B6=84=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/parser/Delimiter.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82cf538e93..3c4e10f782 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ - [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 - [x] 문자열 분석 클래스 분리 - [ ] 구분자 분리 - - [ ] 커스텀 구분자 분리 + - [x] 커스텀 구분자 분리 - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 - [ ] 구분 인덱스 enum으로 관리 - [ ] 커스텀 구분자 구문 삭제 로직 구현 diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index fd9d961178..b75b9d541f 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -1,4 +1,11 @@ package parser; public class Delimiter { + + public String extractDelimiter(String input) { + if (input.startsWith("//") && input.charAt(3) == '\\' && input.charAt(4) == 'n') { + return String.valueOf(input.charAt(2)); + } + return null; + } } From e2c8dba555f8fa7abde3543949c16fd99f7d9eda Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:33:36 +0900 Subject: [PATCH 10/35] =?UTF-8?q?refactor:=20=EC=A1=B0=EA=B1=B4=EB=AC=B8?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/parser/Delimiter.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index b75b9d541f..6ae134bcdf 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -3,9 +3,17 @@ public class Delimiter { public String extractDelimiter(String input) { - if (input.startsWith("//") && input.charAt(3) == '\\' && input.charAt(4) == 'n') { + if (validateStartsWith(input) && validateEndsWith(input)) { return String.valueOf(input.charAt(2)); } return null; } + + private boolean validateStartsWith(String input) { + return input.startsWith("//"); + } + + private boolean validateEndsWith(String input) { + return input.charAt(3) == '\\' && input.charAt(4) == 'n'; + } } From d3156b66a83abf577522f417800ec545b0a5c4aa Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:42:22 +0900 Subject: [PATCH 11/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c4e10f782..2c6058b4f7 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ - [x] 문자열 분석 클래스 분리 - [ ] 구분자 분리 - [x] 커스텀 구분자 분리 - - [ ] 기본 구분자(쉼표 및 세미콜론) 분리 + - [ ] 입력값에서 쉼표 및 세미콜론 또는 커스텀 구분자만 사용되었는지 검증 - [ ] 구분 인덱스 enum으로 관리 - [ ] 커스텀 구분자 구문 삭제 로직 구현 - [ ] 숫자 덧셈 From 3f0334e83b30913ef8750f441766bde0530e50b9 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:44:10 +0900 Subject: [PATCH 12/35] =?UTF-8?q?feat:=20=EC=89=BC=ED=91=9C=20=EB=B0=8F=20?= =?UTF-8?q?=EC=84=B8=EB=AF=B8=EC=BD=9C=EB=A1=A0=20=EB=98=90=EB=8A=94=20?= =?UTF-8?q?=EC=BB=A4=EC=8A=A4=ED=85=80=20=EA=B5=AC=EB=B6=84=EC=9E=90=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/java/parser/Delimiter.java | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c6058b4f7..f491125c77 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ - [x] 라이브러리를 이용한 문자열 입력 - [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 - [x] 문자열 분석 클래스 분리 - - [ ] 구분자 분리 + - [x] 구분자 분리 - [x] 커스텀 구분자 분리 - - [ ] 입력값에서 쉼표 및 세미콜론 또는 커스텀 구분자만 사용되었는지 검증 + - [x] 입력값에서 쉼표 및 세미콜론 또는 커스텀 구분자만 사용되었는지 검증 - [ ] 구분 인덱스 enum으로 관리 - [ ] 커스텀 구분자 구문 삭제 로직 구현 - [ ] 숫자 덧셈 diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index 6ae134bcdf..aaa402bb4d 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -9,6 +9,13 @@ public String extractDelimiter(String input) { return null; } + public boolean validateHasDefaultOrCustomDelimiter(String input, String customDelimiter) { + if (!input.matches("[0-9,:" + customDelimiter + "]*")) { + throw new IllegalArgumentException("허용되지 않는 형식입니다."); + } + return true; + } + private boolean validateStartsWith(String input) { return input.startsWith("//"); } From 025dc537c21c8a6f1b1a169f69a8ea9ea277ad67 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 17:58:33 +0900 Subject: [PATCH 13/35] =?UTF-8?q?refactor:=20=EA=B5=AC=EB=B6=84=EC=9E=90?= =?UTF-8?q?=20=EC=9D=B8=EB=8D=B1=EC=8A=A4=EB=A5=BC=20enum=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B4=80=EB=A6=AC=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/global/DelimiterSyntaxIndex.java | 18 ++++++++++++++++++ src/main/java/parser/Delimiter.java | 7 +++++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/main/java/global/DelimiterSyntaxIndex.java diff --git a/README.md b/README.md index f491125c77..8e0b7dba73 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ - [x] 구분자 분리 - [x] 커스텀 구분자 분리 - [x] 입력값에서 쉼표 및 세미콜론 또는 커스텀 구분자만 사용되었는지 검증 - - [ ] 구분 인덱스 enum으로 관리 + - [x] 구분 인덱스 enum으로 관리 - [ ] 커스텀 구분자 구문 삭제 로직 구현 - [ ] 숫자 덧셈 - [ ] 계산 클래스 분리 diff --git a/src/main/java/global/DelimiterSyntaxIndex.java b/src/main/java/global/DelimiterSyntaxIndex.java new file mode 100644 index 0000000000..6d53a6f4e8 --- /dev/null +++ b/src/main/java/global/DelimiterSyntaxIndex.java @@ -0,0 +1,18 @@ +package global; + +public enum DelimiterSyntaxIndex { + + SPLITTER_INDEX(2), + FIRST_END(3), + SECOND_END(4); + + private final int key; + + DelimiterSyntaxIndex(int i) { + this.key = i; + } + + public int getKey() { + return key; + } +} diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index aaa402bb4d..3032066c65 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -1,10 +1,12 @@ package parser; +import global.DelimiterSyntaxIndex; + public class Delimiter { public String extractDelimiter(String input) { if (validateStartsWith(input) && validateEndsWith(input)) { - return String.valueOf(input.charAt(2)); + return String.valueOf(input.charAt(DelimiterSyntaxIndex.SPLITTER_INDEX.getKey())); } return null; } @@ -21,6 +23,7 @@ private boolean validateStartsWith(String input) { } private boolean validateEndsWith(String input) { - return input.charAt(3) == '\\' && input.charAt(4) == 'n'; + return input.charAt(DelimiterSyntaxIndex.FIRST_END.getKey()) == '\\' + && input.charAt(DelimiterSyntaxIndex.SECOND_END.getKey()) == 'n'; } } From 4fde90b2f765eefe627562e329ada5f45537535b Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:26:05 +0900 Subject: [PATCH 14/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e0b7dba73..d728c57745 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ - [x] 커스텀 구분자 분리 - [x] 입력값에서 쉼표 및 세미콜론 또는 커스텀 구분자만 사용되었는지 검증 - [x] 구분 인덱스 enum으로 관리 - - [ ] 커스텀 구분자 구문 삭제 로직 구현 + - [x] 커스텀 구분자 구문 삭제 로직 구현 + - [ ] 구분자를 이용하여 문자열을 숫자만 있는 배열로 추출 - [ ] 숫자 덧셈 - [ ] 계산 클래스 분리 - [ ] 구분자를 비교하여 숫자 덧셈 구현 From 33f2615bd46e840efb7d5eb5b4db089cd82a268e Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:27:20 +0900 Subject: [PATCH 15/35] =?UTF-8?q?docs:=20=EA=B5=AC=EB=B6=84=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=EC=9D=84=20=EC=88=AB=EC=9E=90=EB=A7=8C=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EB=B0=B0=EC=97=B4=EB=A1=9C=20=EC=B6=94?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +-- src/main/java/global/DefaultDelimiter.java | 17 +++++++++++ .../java/global/DelimiterSyntaxIndex.java | 9 +++--- src/main/java/parser/Delimiter.java | 13 ++++---- src/main/java/parser/InputParser.java | 30 +++++++++++++++++++ 5 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 src/main/java/global/DefaultDelimiter.java create mode 100644 src/main/java/parser/InputParser.java diff --git a/README.md b/README.md index d728c57745..e085f50bbc 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,14 @@ - [x] 입력 클래스 분리 - [x] 문자열 입력 문구 출력 - [x] 라이브러리를 이용한 문자열 입력 -- [ ] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 +- [x] 문자열 쉼표 및 세미콜론, 커스텀 구분자로 나누기 - [x] 문자열 분석 클래스 분리 - [x] 구분자 분리 - [x] 커스텀 구분자 분리 - [x] 입력값에서 쉼표 및 세미콜론 또는 커스텀 구분자만 사용되었는지 검증 - [x] 구분 인덱스 enum으로 관리 - [x] 커스텀 구분자 구문 삭제 로직 구현 - - [ ] 구분자를 이용하여 문자열을 숫자만 있는 배열로 추출 + - [x] 구분자를 이용하여 문자열을 숫자만 있는 배열로 추출 - [ ] 숫자 덧셈 - [ ] 계산 클래스 분리 - [ ] 구분자를 비교하여 숫자 덧셈 구현 diff --git a/src/main/java/global/DefaultDelimiter.java b/src/main/java/global/DefaultDelimiter.java new file mode 100644 index 0000000000..f7a56972b1 --- /dev/null +++ b/src/main/java/global/DefaultDelimiter.java @@ -0,0 +1,17 @@ +package global; + +public enum DefaultDelimiter { + + COMMA(","), + COLON(":"); + + private final String key; + + DefaultDelimiter(String key) { + this.key = key; + } + + public String getKey() { + return key; + } +} diff --git a/src/main/java/global/DelimiterSyntaxIndex.java b/src/main/java/global/DelimiterSyntaxIndex.java index 6d53a6f4e8..15af3cedee 100644 --- a/src/main/java/global/DelimiterSyntaxIndex.java +++ b/src/main/java/global/DelimiterSyntaxIndex.java @@ -2,14 +2,15 @@ public enum DelimiterSyntaxIndex { - SPLITTER_INDEX(2), + DELIMITER_INDEX(2), FIRST_END(3), - SECOND_END(4); + SECOND_END(4), + DELIMITER_AFTER(5); private final int key; - DelimiterSyntaxIndex(int i) { - this.key = i; + DelimiterSyntaxIndex(int key) { + this.key = key; } public int getKey() { diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index 3032066c65..8f7a23c410 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -6,16 +6,17 @@ public class Delimiter { public String extractDelimiter(String input) { if (validateStartsWith(input) && validateEndsWith(input)) { - return String.valueOf(input.charAt(DelimiterSyntaxIndex.SPLITTER_INDEX.getKey())); + return String.valueOf(input.charAt(DelimiterSyntaxIndex.DELIMITER_INDEX.getKey())); } - return null; + return ""; + } + + public String removeDelimiterSyntax(String input) { + return input.substring(DelimiterSyntaxIndex.DELIMITER_AFTER.getKey()); } public boolean validateHasDefaultOrCustomDelimiter(String input, String customDelimiter) { - if (!input.matches("[0-9,:" + customDelimiter + "]*")) { - throw new IllegalArgumentException("허용되지 않는 형식입니다."); - } - return true; + return input.matches("[0-9,:" + customDelimiter + "]*"); } private boolean validateStartsWith(String input) { diff --git a/src/main/java/parser/InputParser.java b/src/main/java/parser/InputParser.java new file mode 100644 index 0000000000..390cd5623c --- /dev/null +++ b/src/main/java/parser/InputParser.java @@ -0,0 +1,30 @@ +package parser; + +import global.DefaultDelimiter; + +public class InputParser { + + private static final InputParser INSTANCE = new InputParser(); + private final Delimiter delimiter = new Delimiter(); + + private InputParser() { + } + + public static InputParser getInstance() { + return INSTANCE; + } + + public String[] parse(String input) { + String customDelimiter = delimiter.extractDelimiter(input); + if (!delimiter.validateHasDefaultOrCustomDelimiter(input, customDelimiter)) { + throw new IllegalArgumentException("허용되지 않는 입력문입니다."); + } + String defaultSyntax = delimiter.removeDelimiterSyntax(input); + return extractNumbersFromDefaultSyntax(defaultSyntax, customDelimiter); + } + + private String[] extractNumbersFromDefaultSyntax(String defaultSyntax, String customDelimiter) { + String delimiters = DefaultDelimiter.COMMA.getKey() + DefaultDelimiter.COLON.getKey() + customDelimiter; + return defaultSyntax.split("[" + delimiters + "]"); + } +} From 3572207ba1659a230333d58d210f491c5fe7ac23 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:37:21 +0900 Subject: [PATCH 16/35] =?UTF-8?q?feat:=20=EA=B3=84=EC=82=B0=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/calculation/Calculation.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/main/java/calculation/Calculation.java diff --git a/README.md b/README.md index e085f50bbc..3b3448b5db 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ - [x] 커스텀 구분자 구문 삭제 로직 구현 - [x] 구분자를 이용하여 문자열을 숫자만 있는 배열로 추출 - [ ] 숫자 덧셈 - - [ ] 계산 클래스 분리 + - [x] 계산 클래스 분리 - [ ] 구분자를 비교하여 숫자 덧셈 구현 - [ ] 예외 처리 - [ ] 예외 클래스 분리 diff --git a/src/main/java/calculation/Calculation.java b/src/main/java/calculation/Calculation.java new file mode 100644 index 0000000000..077bdead43 --- /dev/null +++ b/src/main/java/calculation/Calculation.java @@ -0,0 +1,4 @@ +package calculation; + +public class Calculation { +} From 093c1dfc4e72109920127b11af3c78b416f1b466 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:38:04 +0900 Subject: [PATCH 17/35] =?UTF-8?q?feat:=20=EC=88=AB=EC=9E=90=20=EB=8D=A7?= =?UTF-8?q?=EC=85=88=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/java/calculation/Calculation.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b3448b5db..a5e31fa4cd 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ - [x] 구분 인덱스 enum으로 관리 - [x] 커스텀 구분자 구문 삭제 로직 구현 - [x] 구분자를 이용하여 문자열을 숫자만 있는 배열로 추출 -- [ ] 숫자 덧셈 +- [x] 숫자 덧셈 - [x] 계산 클래스 분리 - - [ ] 구분자를 비교하여 숫자 덧셈 구현 + - [x] 구분자를 비교하여 숫자 덧셈 구현 - [ ] 예외 처리 - [ ] 예외 클래스 분리 - [ ] 결과 반환 \ No newline at end of file diff --git a/src/main/java/calculation/Calculation.java b/src/main/java/calculation/Calculation.java index 077bdead43..0dc8b76351 100644 --- a/src/main/java/calculation/Calculation.java +++ b/src/main/java/calculation/Calculation.java @@ -1,4 +1,21 @@ package calculation; public class Calculation { + + private static final Calculation INSTANCE = new Calculation(); + + private Calculation() { + } + + public static Calculation getInstance() { + return INSTANCE; + } + + public Integer calculate(String[] numbers) { + int sum = 0; + for(String number : numbers) { + sum += Integer.parseInt(number); + } + return sum; + } } From 2c0fd9f25081cf0e9a11ab84bd05d85a84c503f5 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:42:32 +0900 Subject: [PATCH 18/35] =?UTF-8?q?refactor:=20=ED=95=98=EB=93=9C=EC=BD=94?= =?UTF-8?q?=EB=94=A9=20=EB=90=98=EC=96=B4=EC=9E=88=EB=8D=98=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EA=B5=AC=EB=B6=84=EC=9E=90=EB=A5=BC=20enum=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/parser/Delimiter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index 8f7a23c410..481d5e41e0 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -1,5 +1,6 @@ package parser; +import global.DefaultDelimiter; import global.DelimiterSyntaxIndex; public class Delimiter { @@ -16,7 +17,8 @@ public String removeDelimiterSyntax(String input) { } public boolean validateHasDefaultOrCustomDelimiter(String input, String customDelimiter) { - return input.matches("[0-9,:" + customDelimiter + "]*"); + String delimiters = DefaultDelimiter.COLON.getKey() + DefaultDelimiter.COMMA.getKey() + customDelimiter; + return input.matches("[0-9" + delimiters + "]*"); } private boolean validateStartsWith(String input) { From 2e0ee37fb8a96a4b4e99dc909c661285c350308b Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:44:24 +0900 Subject: [PATCH 19/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a5e31fa4cd..8b0b72e73c 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,4 @@ - [x] 숫자 덧셈 - [x] 계산 클래스 분리 - [x] 구분자를 비교하여 숫자 덧셈 구현 -- [ ] 예외 처리 - - [ ] 예외 클래스 분리 - [ ] 결과 반환 \ No newline at end of file From 24ae6ef7430b05e4e6d28e154dcee5ebc0453aca Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:52:10 +0900 Subject: [PATCH 20/35] =?UTF-8?q?refactor:=20=EB=B0=98=ED=99=98=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20primitive=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculation/Calculation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/calculation/Calculation.java b/src/main/java/calculation/Calculation.java index 0dc8b76351..cfd6218f3d 100644 --- a/src/main/java/calculation/Calculation.java +++ b/src/main/java/calculation/Calculation.java @@ -11,7 +11,7 @@ public static Calculation getInstance() { return INSTANCE; } - public Integer calculate(String[] numbers) { + public int calculate(String[] numbers) { int sum = 0; for(String number : numbers) { sum += Integer.parseInt(number); From ff6e4eaddfdcee6a9c47a43d1ebab72b343dc357 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Thu, 17 Oct 2024 20:52:55 +0900 Subject: [PATCH 21/35] =?UTF-8?q?feat:=20=EA=B2=B0=EA=B3=BC=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/calculator/Application.java | 17 ++++++++++++++++- src/main/java/input/InputHandler.java | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b0b72e73c..8ff1da96a9 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,4 @@ - [x] 숫자 덧셈 - [x] 계산 클래스 분리 - [x] 구분자를 비교하여 숫자 덧셈 구현 -- [ ] 결과 반환 \ No newline at end of file +- [x] 결과 반환 \ No newline at end of file diff --git a/src/main/java/calculator/Application.java b/src/main/java/calculator/Application.java index 573580fb40..4883b3e49d 100644 --- a/src/main/java/calculator/Application.java +++ b/src/main/java/calculator/Application.java @@ -1,7 +1,22 @@ package calculator; +import calculation.Calculation; +import input.InputHandler; +import parser.InputParser; + public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + + Calculation calculator = Calculation.getInstance(); + InputParser parser = InputParser.getInstance(); + InputHandler inputHandler = new InputHandler(); + + String input = inputHandler.getInput(); + String[] parseResult = parser.parse(input); + + int result = calculator.calculate(parseResult); + System.out.println(result); + + inputHandler.closeInput(); } } diff --git a/src/main/java/input/InputHandler.java b/src/main/java/input/InputHandler.java index 85c6eb012d..6fa84d3c27 100644 --- a/src/main/java/input/InputHandler.java +++ b/src/main/java/input/InputHandler.java @@ -8,4 +8,8 @@ public String getInput() { System.out.println("문자열을 입력해주세요"); return Console.readLine(); } + + public void closeInput() { + Console.close(); + } } From 76ea3d27e9d5cb1cf3529641cdb38f56a7d5aa8f Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Fri, 18 Oct 2024 12:20:13 +0900 Subject: [PATCH 22/35] =?UTF-8?q?refactor:=20=EA=B5=AC=EB=B6=84=EC=9E=90?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9=EC=8B=9D=EC=9D=84=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=20=ED=9B=84=20=EA=B2=80=EC=A6=9D=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/parser/Delimiter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index 481d5e41e0..e42ecb6f97 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -18,7 +18,8 @@ public String removeDelimiterSyntax(String input) { public boolean validateHasDefaultOrCustomDelimiter(String input, String customDelimiter) { String delimiters = DefaultDelimiter.COLON.getKey() + DefaultDelimiter.COMMA.getKey() + customDelimiter; - return input.matches("[0-9" + delimiters + "]*"); + String defaultSyntax = removeDelimiterSyntax(input); + return defaultSyntax.matches("[0-9" + delimiters + "]*"); } private boolean validateStartsWith(String input) { From 439f1debb74f274920d31cb42060f96567f56e4e Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Fri, 18 Oct 2024 12:21:04 +0900 Subject: [PATCH 23/35] =?UTF-8?q?refactor:=20=EC=BB=A4=EC=8A=A4=ED=85=80?= =?UTF-8?q?=20=EA=B5=AC=EB=B6=84=EC=9E=90=EB=A5=BC=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=EC=97=90=EB=A7=8C=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=EC=9E=90=20=EC=A0=81=EC=9A=A9=EC=8B=9D=EC=9D=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/parser/Delimiter.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/parser/Delimiter.java index e42ecb6f97..d94384458b 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/parser/Delimiter.java @@ -13,7 +13,10 @@ public String extractDelimiter(String input) { } public String removeDelimiterSyntax(String input) { - return input.substring(DelimiterSyntaxIndex.DELIMITER_AFTER.getKey()); + if (validateStartsWith(input) && validateEndsWith(input)) { + return input.substring(DelimiterSyntaxIndex.DELIMITER_AFTER.getKey()); + } + return input; } public boolean validateHasDefaultOrCustomDelimiter(String input, String customDelimiter) { From 7d2b2c8990edb549445d6cda227173514ab2a06e Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sat, 19 Oct 2024 23:13:21 +0900 Subject: [PATCH 24/35] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/Application.java | 6 +++--- src/main/java/{ => calculator}/calculation/Calculation.java | 2 +- src/main/java/{ => calculator}/global/DefaultDelimiter.java | 2 +- .../java/{ => calculator}/global/DelimiterSyntaxIndex.java | 2 +- src/main/java/{ => calculator}/input/InputHandler.java | 2 +- src/main/java/{ => calculator}/parser/Delimiter.java | 6 +++--- src/main/java/{ => calculator}/parser/InputParser.java | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) rename src/main/java/{ => calculator}/calculation/Calculation.java (92%) rename src/main/java/{ => calculator}/global/DefaultDelimiter.java (89%) rename src/main/java/{ => calculator}/global/DelimiterSyntaxIndex.java (90%) rename src/main/java/{ => calculator}/input/InputHandler.java (91%) rename src/main/java/{ => calculator}/parser/Delimiter.java (91%) rename src/main/java/{ => calculator}/parser/InputParser.java (93%) diff --git a/src/main/java/calculator/Application.java b/src/main/java/calculator/Application.java index 4883b3e49d..2ab1ced939 100644 --- a/src/main/java/calculator/Application.java +++ b/src/main/java/calculator/Application.java @@ -1,8 +1,8 @@ package calculator; -import calculation.Calculation; -import input.InputHandler; -import parser.InputParser; +import calculator.calculation.Calculation; +import calculator.input.InputHandler; +import calculator.parser.InputParser; public class Application { public static void main(String[] args) { diff --git a/src/main/java/calculation/Calculation.java b/src/main/java/calculator/calculation/Calculation.java similarity index 92% rename from src/main/java/calculation/Calculation.java rename to src/main/java/calculator/calculation/Calculation.java index cfd6218f3d..307fbcb41d 100644 --- a/src/main/java/calculation/Calculation.java +++ b/src/main/java/calculator/calculation/Calculation.java @@ -1,4 +1,4 @@ -package calculation; +package calculator.calculation; public class Calculation { diff --git a/src/main/java/global/DefaultDelimiter.java b/src/main/java/calculator/global/DefaultDelimiter.java similarity index 89% rename from src/main/java/global/DefaultDelimiter.java rename to src/main/java/calculator/global/DefaultDelimiter.java index f7a56972b1..fcfb1f61ad 100644 --- a/src/main/java/global/DefaultDelimiter.java +++ b/src/main/java/calculator/global/DefaultDelimiter.java @@ -1,4 +1,4 @@ -package global; +package calculator.global; public enum DefaultDelimiter { diff --git a/src/main/java/global/DelimiterSyntaxIndex.java b/src/main/java/calculator/global/DelimiterSyntaxIndex.java similarity index 90% rename from src/main/java/global/DelimiterSyntaxIndex.java rename to src/main/java/calculator/global/DelimiterSyntaxIndex.java index 15af3cedee..e7e1fb436d 100644 --- a/src/main/java/global/DelimiterSyntaxIndex.java +++ b/src/main/java/calculator/global/DelimiterSyntaxIndex.java @@ -1,4 +1,4 @@ -package global; +package calculator.global; public enum DelimiterSyntaxIndex { diff --git a/src/main/java/input/InputHandler.java b/src/main/java/calculator/input/InputHandler.java similarity index 91% rename from src/main/java/input/InputHandler.java rename to src/main/java/calculator/input/InputHandler.java index 6fa84d3c27..2f966d0001 100644 --- a/src/main/java/input/InputHandler.java +++ b/src/main/java/calculator/input/InputHandler.java @@ -1,4 +1,4 @@ -package input; +package calculator.input; import camp.nextstep.edu.missionutils.Console; diff --git a/src/main/java/parser/Delimiter.java b/src/main/java/calculator/parser/Delimiter.java similarity index 91% rename from src/main/java/parser/Delimiter.java rename to src/main/java/calculator/parser/Delimiter.java index d94384458b..e9c80e99c3 100644 --- a/src/main/java/parser/Delimiter.java +++ b/src/main/java/calculator/parser/Delimiter.java @@ -1,7 +1,7 @@ -package parser; +package calculator.parser; -import global.DefaultDelimiter; -import global.DelimiterSyntaxIndex; +import calculator.global.DefaultDelimiter; +import calculator.global.DelimiterSyntaxIndex; public class Delimiter { diff --git a/src/main/java/parser/InputParser.java b/src/main/java/calculator/parser/InputParser.java similarity index 93% rename from src/main/java/parser/InputParser.java rename to src/main/java/calculator/parser/InputParser.java index 390cd5623c..5df09e758f 100644 --- a/src/main/java/parser/InputParser.java +++ b/src/main/java/calculator/parser/InputParser.java @@ -1,6 +1,6 @@ -package parser; +package calculator.parser; -import global.DefaultDelimiter; +import calculator.global.DefaultDelimiter; public class InputParser { From e6f3e1a484cb588073352f376610e60689d61860 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sat, 19 Oct 2024 23:15:44 +0900 Subject: [PATCH 25/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8ff1da96a9..19ee3099a0 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,5 @@ - [x] 숫자 덧셈 - [x] 계산 클래스 분리 - [x] 구분자를 비교하여 숫자 덧셈 구현 +- [ ] runner 구현 - [x] 결과 반환 \ No newline at end of file From 841e57866c9682a3c9afbbe8c3b0866b848e464b Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sat, 19 Oct 2024 23:23:08 +0900 Subject: [PATCH 26/35] =?UTF-8?q?refactor:=20Delimiter=20=EC=8B=B1?= =?UTF-8?q?=EA=B8=80=ED=86=A4=20=ED=8C=A8=ED=84=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/parser/Delimiter.java | 8 ++++++++ src/main/java/calculator/parser/InputParser.java | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/calculator/parser/Delimiter.java b/src/main/java/calculator/parser/Delimiter.java index e9c80e99c3..ded584377d 100644 --- a/src/main/java/calculator/parser/Delimiter.java +++ b/src/main/java/calculator/parser/Delimiter.java @@ -5,6 +5,14 @@ public class Delimiter { + private static final Delimiter INSTANCE = new Delimiter(); + + private Delimiter() {} + + public static Delimiter getInstance() { + return INSTANCE; + } + public String extractDelimiter(String input) { if (validateStartsWith(input) && validateEndsWith(input)) { return String.valueOf(input.charAt(DelimiterSyntaxIndex.DELIMITER_INDEX.getKey())); diff --git a/src/main/java/calculator/parser/InputParser.java b/src/main/java/calculator/parser/InputParser.java index 5df09e758f..4f85338a3b 100644 --- a/src/main/java/calculator/parser/InputParser.java +++ b/src/main/java/calculator/parser/InputParser.java @@ -5,9 +5,10 @@ public class InputParser { private static final InputParser INSTANCE = new InputParser(); - private final Delimiter delimiter = new Delimiter(); + private final Delimiter delimiter; private InputParser() { + this.delimiter = Delimiter.getInstance(); } public static InputParser getInstance() { From 72bd283431bdba6d78329cfec7cb7b263bc86cb9 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sat, 19 Oct 2024 23:23:25 +0900 Subject: [PATCH 27/35] =?UTF-8?q?refactor:=20InputHandler=20=EC=8B=B1?= =?UTF-8?q?=EA=B8=80=ED=86=A4=20=ED=8C=A8=ED=84=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/input/InputHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/calculator/input/InputHandler.java b/src/main/java/calculator/input/InputHandler.java index 2f966d0001..ca13ce7b23 100644 --- a/src/main/java/calculator/input/InputHandler.java +++ b/src/main/java/calculator/input/InputHandler.java @@ -4,6 +4,14 @@ public class InputHandler { + private static final InputHandler INSTANCE = new InputHandler(); + + private InputHandler() {} + + public static InputHandler getInstance() { + return INSTANCE; + } + public String getInput() { System.out.println("문자열을 입력해주세요"); return Console.readLine(); From 2cdc2a01385f7d20e9b3fb71ca7e1b42b93be3d5 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sat, 19 Oct 2024 23:30:02 +0900 Subject: [PATCH 28/35] =?UTF-8?q?refactor:=20Calculation=20=EC=8B=B1?= =?UTF-8?q?=EA=B8=80=ED=86=A4=20=ED=8C=A8=ED=84=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/calculation/Calculation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/calculator/calculation/Calculation.java b/src/main/java/calculator/calculation/Calculation.java index 307fbcb41d..b3eb4e99d1 100644 --- a/src/main/java/calculator/calculation/Calculation.java +++ b/src/main/java/calculator/calculation/Calculation.java @@ -4,8 +4,7 @@ public class Calculation { private static final Calculation INSTANCE = new Calculation(); - private Calculation() { - } + private Calculation() {} public static Calculation getInstance() { return INSTANCE; From 9f42d0cb362bf6712a30cd0bf713c1d1123b2633 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sat, 19 Oct 2024 23:30:28 +0900 Subject: [PATCH 29/35] =?UTF-8?q?refactor:=20main=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EC=97=90=20=EC=A7=91=EC=A4=91=EB=90=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B6=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/Application.java | 16 ++------- .../calculator/runner/CalculateRunner.java | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/main/java/calculator/runner/CalculateRunner.java diff --git a/src/main/java/calculator/Application.java b/src/main/java/calculator/Application.java index 2ab1ced939..fffe8b4b00 100644 --- a/src/main/java/calculator/Application.java +++ b/src/main/java/calculator/Application.java @@ -1,22 +1,12 @@ package calculator; -import calculator.calculation.Calculation; -import calculator.input.InputHandler; -import calculator.parser.InputParser; +import calculator.runner.CalculateRunner; public class Application { public static void main(String[] args) { - Calculation calculator = Calculation.getInstance(); - InputParser parser = InputParser.getInstance(); - InputHandler inputHandler = new InputHandler(); + CalculateRunner runner = CalculateRunner.getInstance(); - String input = inputHandler.getInput(); - String[] parseResult = parser.parse(input); - - int result = calculator.calculate(parseResult); - System.out.println(result); - - inputHandler.closeInput(); + runner.run(); } } diff --git a/src/main/java/calculator/runner/CalculateRunner.java b/src/main/java/calculator/runner/CalculateRunner.java new file mode 100644 index 0000000000..81bf741635 --- /dev/null +++ b/src/main/java/calculator/runner/CalculateRunner.java @@ -0,0 +1,34 @@ +package calculator.runner; + +import calculator.calculation.Calculation; +import calculator.input.InputHandler; +import calculator.parser.InputParser; + +public class CalculateRunner { + + private static final CalculateRunner INSTANCE = new CalculateRunner(); + + public static CalculateRunner getInstance() { + return INSTANCE; + } + + private final Calculation calculator; + private final InputParser parser; + private final InputHandler inputHandler; + + private CalculateRunner() { + this.calculator = Calculation.getInstance(); + this.parser = InputParser.getInstance(); + this.inputHandler = InputHandler.getInstance(); + } + + public void run() { + String input = inputHandler.getInput(); + String[] parseResult = parser.parse(input); + int result = calculator.calculate(parseResult); + + System.out.println("Result: " + result); + + inputHandler.closeInput(); + } +} From 9d98f7f00f7f251e8a47890469a782d5ccdfc1a6 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sat, 19 Oct 2024 23:30:56 +0900 Subject: [PATCH 30/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 19ee3099a0..68b1deab1f 100644 --- a/README.md +++ b/README.md @@ -34,5 +34,5 @@ - [x] 숫자 덧셈 - [x] 계산 클래스 분리 - [x] 구분자를 비교하여 숫자 덧셈 구현 -- [ ] runner 구현 +- [x] runner 구현 - [x] 결과 반환 \ No newline at end of file From 9ba649306848ed17ca9e9f3098b5e83377eb10ce Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sun, 20 Oct 2024 02:09:09 +0900 Subject: [PATCH 31/35] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calculation/CalculationTest.java | 48 +++++++++++++++ .../calculator/delimiter/DelimiterTest.java | 60 +++++++++++++++++++ src/test/java/calculator/input/InputTest.java | 31 ++++++++++ .../java/calculator/parser/ParserTest.java | 48 +++++++++++++++ .../java/calculator/runner/RunnerTest.java | 23 +++++++ 5 files changed, 210 insertions(+) create mode 100644 src/test/java/calculator/calculation/CalculationTest.java create mode 100644 src/test/java/calculator/delimiter/DelimiterTest.java create mode 100644 src/test/java/calculator/input/InputTest.java create mode 100644 src/test/java/calculator/parser/ParserTest.java create mode 100644 src/test/java/calculator/runner/RunnerTest.java diff --git a/src/test/java/calculator/calculation/CalculationTest.java b/src/test/java/calculator/calculation/CalculationTest.java new file mode 100644 index 0000000000..af4b02d1a1 --- /dev/null +++ b/src/test/java/calculator/calculation/CalculationTest.java @@ -0,0 +1,48 @@ +package calculator.calculation; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class CalculationTest { + + private final Calculation calculator = Calculation.getInstance(); + + @Test + @DisplayName("정상적인 숫자 배열로 계산") + void testCalculateWithValidNumbers() { + // Given + String[] numbers = {"1", "2", "3"}; + + // When + int result = calculator.calculate(numbers); + + // Then + assertEquals(6, result); + } + + @Test + @DisplayName("빈 배열 입력 시 0 반환") + void testCalculateWithEmptyArray() { + // Given + String[] numbers = {}; + + // When + int result = calculator.calculate(numbers); + + // Then + assertEquals(0, result); + } + + @Test + @DisplayName("숫자가 아닌 값이 포함되었을 때 예외 발생") + void testCalculateWithInvalidNumber() { + // Given + String[] numbers = {"1", "a", "3"}; + + // When & Then + assertThrows(IllegalArgumentException.class, () -> calculator.calculate(numbers)); + } +} diff --git a/src/test/java/calculator/delimiter/DelimiterTest.java b/src/test/java/calculator/delimiter/DelimiterTest.java new file mode 100644 index 0000000000..86d166b75f --- /dev/null +++ b/src/test/java/calculator/delimiter/DelimiterTest.java @@ -0,0 +1,60 @@ +package calculator.delimiter; + +import calculator.parser.Delimiter; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class DelimiterTest { + + private final Delimiter delimiter = Delimiter.getInstance(); + + @Test + @DisplayName("커스텀 구분자를 올바르게 추출") + void testExtractDelimiterWithCustomSyntax() { + // Given + String input = "//;\\n1;2;3"; + + // When + String result = delimiter.extractDelimiter(input); + + // Then + assertEquals(";", result); + } + + @Test + @DisplayName("구분자 구문 제거 테스트") + void testRemoveDelimiterSyntax() { + // Given + String input = "//;\\n1;2;3"; + + // When + String result = delimiter.removeDelimiterSyntax(input); + + // Then + assertEquals("1;2;3", result); + } + + @Test + @DisplayName("기본 또는 커스텀 구분자 유효성 테스트") + void testValidateHasDefaultOrCustomDelimiter() { + // Given + String input = "//;\\n1;2;3"; + + // When & Then + assertTrue(delimiter.validateHasDefaultOrCustomDelimiter(input, ";")); + } + + @Test + @DisplayName("잘못된 구분자 입력 시 실패") + void testValidateInvalidDelimiter() { + // Given + String input = "//;\\n1,2;3"; + + // When & Then + assertFalse(delimiter.validateHasDefaultOrCustomDelimiter(input, "|")); + } +} diff --git a/src/test/java/calculator/input/InputTest.java b/src/test/java/calculator/input/InputTest.java new file mode 100644 index 0000000000..573e4a6db0 --- /dev/null +++ b/src/test/java/calculator/input/InputTest.java @@ -0,0 +1,31 @@ +package calculator.input; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class InputTest { + + private final InputHandler inputHandler = InputHandler.getInstance(); + + @Test + @DisplayName("사용자 입력을 정상적으로 받는지 테스트") + void testGetInput() { + // Given + String simulatedInput = "1,2,3"; + System.setIn(new ByteArrayInputStream(simulatedInput.getBytes())); + + // When & Then + assertDoesNotThrow(inputHandler::getInput); + } + + @Test + @DisplayName("입력 스트림을 정상적으로 닫는지 테스트") + void testCloseInput() { + // Given & When & Then + assertDoesNotThrow(inputHandler::closeInput); + } +} diff --git a/src/test/java/calculator/parser/ParserTest.java b/src/test/java/calculator/parser/ParserTest.java new file mode 100644 index 0000000000..0d9dc87e22 --- /dev/null +++ b/src/test/java/calculator/parser/ParserTest.java @@ -0,0 +1,48 @@ +package calculator.parser; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ParserTest { + + private final InputParser parser = InputParser.getInstance(); + + @Test + @DisplayName("커스텀 구분자로 입력을 파싱") + void testParseWithCustomDelimiter() { + // Given + String input = "//;\\n1;2;3"; + + // When + String[] result = parser.parse(input); + + // Then + assertArrayEquals(new String[]{"1", "2", "3"}, result); + } + + @Test + @DisplayName("기본 구분자로 입력을 파싱") + void testParseWithDefaultDelimiter() { + // Given + String input = "1,2:3"; + + // When + String[] result = parser.parse(input); + + // Then + assertArrayEquals(new String[]{"1", "2", "3"}, result); + } + + @Test + @DisplayName("잘못된 구분자 구문 입력 시 예외 발생") + void testParseWithInvalidDelimiter() { + // Given + String input = "///;\\n1,2:3"; + + // When & Then + assertThrows(IllegalArgumentException.class, () -> parser.parse(input)); + } +} diff --git a/src/test/java/calculator/runner/RunnerTest.java b/src/test/java/calculator/runner/RunnerTest.java new file mode 100644 index 0000000000..1b459139ea --- /dev/null +++ b/src/test/java/calculator/runner/RunnerTest.java @@ -0,0 +1,23 @@ +package calculator.runner; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class RunnerTest { + + @Test + @DisplayName("CalculateRunner 실행 중 예외 발생 없이 실행") + void testRunnerExecution() { + // Given + CalculateRunner runner = CalculateRunner.getInstance(); + String simulatedInput = "1,2:3"; + System.setIn(new ByteArrayInputStream(simulatedInput.getBytes())); + + // When & Then + assertDoesNotThrow(runner::run); + } +} From 1255875a1a90bee0f64c86711d2c51679242258a Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Sun, 20 Oct 2024 03:06:34 +0900 Subject: [PATCH 32/35] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=96=91=EC=8B=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 68b1deab1f..a897fff0bb 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,14 @@ 입력한 문자열에서 숫자를 추출하여 더하는 계산기를 구현한다. 쉼표(,) 또는 콜론(:)을 구분자로 가지는 문자열을 전달하는 경우 구분자를 기준으로 분리한 각 숫자의 합을 반환한다.
+ 예: "" => 0, "1,2" => 3, "1,2,3" => 6, "1,2:3" => 6
+ 앞의 기본 구분자(쉼표, 콜론) 외에 커스텀 구분자를 지정할 수 있다.
커스텀 구분자는 문자열 앞부분의 "//"와 "\n" 사이에 위치하는 문자를 커스텀 구분자로 사용한다.
예를 들어 `"//;\n1;2;3"`과 같이 값을 입력할 경우 커스텀 구분자는 세미콜론(;)이며, 결과 값은 `6`이 반환되어야 한다.
+ 사용자가 잘못된 값을 입력할 경우 `IllegalArgumentException`을 발생시킨 후 애플리케이션은 종료되어야 한다. - 입력 : 구분자와 양수로 구성된 문자열
From a10af82e7195d1c62b1161b2c757050dd72bd17b Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Mon, 21 Oct 2024 21:19:02 +0900 Subject: [PATCH 33/35] =?UTF-8?q?refactor:=20=EC=9D=B4=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=ED=94=84=20=EB=AC=B8=EC=9E=90=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/parser/Delimiter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/calculator/parser/Delimiter.java b/src/main/java/calculator/parser/Delimiter.java index ded584377d..b1c73b5a33 100644 --- a/src/main/java/calculator/parser/Delimiter.java +++ b/src/main/java/calculator/parser/Delimiter.java @@ -15,7 +15,8 @@ public static Delimiter getInstance() { public String extractDelimiter(String input) { if (validateStartsWith(input) && validateEndsWith(input)) { - return String.valueOf(input.charAt(DelimiterSyntaxIndex.DELIMITER_INDEX.getKey())); + String rawDelimiter = String.valueOf(input.charAt(DelimiterSyntaxIndex.DELIMITER_INDEX.getKey())); + return rawDelimiter.matches("[\\W]") ? "\\" + rawDelimiter : rawDelimiter; } return ""; } From 82a7a7a64bf6a7bf989c9fbae3b4f87a8a23205a Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Mon, 21 Oct 2024 21:40:23 +0900 Subject: [PATCH 34/35] =?UTF-8?q?refactor:=20=EC=9D=B4=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=ED=94=84=20=EB=AC=B8=EC=9E=90=20=EC=9E=AC=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/parser/Delimiter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/calculator/parser/Delimiter.java b/src/main/java/calculator/parser/Delimiter.java index b1c73b5a33..4f036a9560 100644 --- a/src/main/java/calculator/parser/Delimiter.java +++ b/src/main/java/calculator/parser/Delimiter.java @@ -16,7 +16,8 @@ public static Delimiter getInstance() { public String extractDelimiter(String input) { if (validateStartsWith(input) && validateEndsWith(input)) { String rawDelimiter = String.valueOf(input.charAt(DelimiterSyntaxIndex.DELIMITER_INDEX.getKey())); - return rawDelimiter.matches("[\\W]") ? "\\" + rawDelimiter : rawDelimiter; + + return rawDelimiter.matches("[.\\^$|?*+(){}\\[\\]\\\\]") ? "\\" + rawDelimiter : rawDelimiter; } return ""; } From 1f805a34724cbbcaea7b7e07f324a6bf23420742 Mon Sep 17 00:00:00 2001 From: SongJaeHoonn Date: Mon, 21 Oct 2024 21:40:34 +0900 Subject: [PATCH 35/35] =?UTF-8?q?refactor:=20=EB=B9=88=20=EC=88=AB?= =?UTF-8?q?=EC=9E=90=20=EC=9E=85=EB=A0=A5=20=EC=8B=9C=200=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/calculator/parser/InputParser.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/calculator/parser/InputParser.java b/src/main/java/calculator/parser/InputParser.java index 4f85338a3b..b37066f999 100644 --- a/src/main/java/calculator/parser/InputParser.java +++ b/src/main/java/calculator/parser/InputParser.java @@ -2,6 +2,8 @@ import calculator.global.DefaultDelimiter; +import java.util.Arrays; + public class InputParser { private static final InputParser INSTANCE = new InputParser(); @@ -26,6 +28,10 @@ public String[] parse(String input) { private String[] extractNumbersFromDefaultSyntax(String defaultSyntax, String customDelimiter) { String delimiters = DefaultDelimiter.COMMA.getKey() + DefaultDelimiter.COLON.getKey() + customDelimiter; - return defaultSyntax.split("[" + delimiters + "]"); + String[] numbers = defaultSyntax.split("[" + delimiters + "]"); + + return Arrays.stream(numbers) + .filter(num -> !num.isEmpty()) + .toArray(String[]::new); } }