|
7 | 7 |
|
8 | 8 | public class CharactersCounter {
|
9 | 9 |
|
10 |
| - private final InputStream inputStream; |
11 |
| - private final PrintStream printStream; |
12 |
| - |
13 |
| - public CharactersCounter(InputStream inputStream, PrintStream printStream) { |
14 |
| - Objects.requireNonNull(inputStream, "inputStream must not be null"); |
15 |
| - Objects.requireNonNull(printStream, "printStream must not be null"); |
16 |
| - this.inputStream = inputStream; |
17 |
| - this.printStream = printStream; |
18 |
| - } |
19 |
| - |
20 |
| - public void displayCharactersCount() { |
21 |
| - askForInput(); |
22 |
| - String input = readInput(); |
23 |
| - if (input == null || input.isBlank()) { |
24 |
| - this.printStream.println("Please enter something as input!"); |
25 |
| - return; |
| 10 | + private final InputStream inputStream; |
| 11 | + private final PrintStream printStream; |
| 12 | + |
| 13 | + public CharactersCounter(InputStream inputStream, PrintStream printStream) { |
| 14 | + Objects.requireNonNull(inputStream, "inputStream must not be null"); |
| 15 | + Objects.requireNonNull(printStream, "printStream must not be null"); |
| 16 | + this.inputStream = inputStream; |
| 17 | + this.printStream = printStream; |
26 | 18 | }
|
27 |
| - this.printStream.printf("%s has %d characters.%n", input, input.length()); |
28 |
| - } |
29 | 19 |
|
30 |
| - @SuppressWarnings("PMD.SystemPrintln") |
31 |
| - private void askForInput() { |
32 |
| - System.out.print("What is the input string? "); |
33 |
| - } |
| 20 | + public void displayCharactersCount() { |
| 21 | + askForInput(); |
| 22 | + String input = readInput(); |
| 23 | + if (input == null || input.isBlank()) { |
| 24 | + this.printStream.println("Please enter something as input!"); |
| 25 | + return; |
| 26 | + } |
| 27 | + this.printStream.printf("%s has %d characters.%n", input, input.length()); |
| 28 | + } |
| 29 | + |
| 30 | + @SuppressWarnings("PMD.SystemPrintln") |
| 31 | + private void askForInput() { |
| 32 | + System.out.print("What is the input string? "); |
| 33 | + } |
34 | 34 |
|
35 |
| - private String readInput() { |
36 |
| - try (Scanner scanner = new Scanner(this.inputStream)) { |
37 |
| - return scanner.hasNext() ? scanner.nextLine() : null; |
| 35 | + private String readInput() { |
| 36 | + try (Scanner scanner = new Scanner(this.inputStream)) { |
| 37 | + return scanner.hasNext() ? scanner.nextLine() : null; |
| 38 | + } |
38 | 39 | }
|
39 |
| - } |
40 | 40 |
|
41 | 41 | }
|
0 commit comments